Tag Info

New answers tagged

0

To get the Window ID in my program, I have the program set the title to something unique, then have the program start wmctrl and parse its output (and not the shell script that started the program), and then report on the Window ID (most often via a file). Since the program doesn't continue until the windows are open, you will never have to wait to long. ...


1

You don't need to install Expect on the server. Write an Expect script instead of running expect from a shell script. Have the Expect script itself spawn the SSH client, connect to the server and then loop through the numbers. To save yourself some effort you can record a session where you log in to the server and try some number with autoexpect. Save the ...


0

I don't think diff (even in combination with cut) will be flexible enough to handle this. And it seems as though what you really want is keys in file1 that are not in file2 and vice versa - not strictly a line-by-line diff. If the input files are big, I would go with perl, but for small files this awk script works for the input provided: %cat a.awk BEGIN ...


3

awk is a better tool for comparing columns of files. See, for example, the answer to: compare two columns of different files and print if it matches -- there are similar answers out there for printing lines for matching columns. Since you want to print lines that don't match, we can create an awk command that prints the lines in file2 for which column 2 has ...


1

You inner shell is not interactive; remove the -i flag and it should stop freaking out. See What should interactive shells do in orphaned process groups? for an explanation of what is going on under the cover.


1

It can be done using, awk: awk -F: -v OFS=: '{split ($NF, groups, " "); $NF=""; for (i in groups) {printf "%s%s\n", $0, groups[i]}}' Assigning to a field (like in $NF="") causes $0 to have instances of FS replaced with the OFS, so we have to assign : to OFS. Don't expect any order in the output - the group field will be randomly output. Use a sort later ...


0

If I remember correctly from the top of my head, the following too are identical: $ ./script and $ source script So using the ./ "command" will in fact invoke source under the hood, which on its part is a bash builtin command. Or, in another interpretation they might be called aliases of each other. I think that will answer your question as well in ...


1

Use file matching operator in your for loop. for f in *_*.png will match all the png file names as you specified and assign each name to variable f. Then inside the loop use the ${f%_*} bash operation to extract only the number of the file. FOLDER="$HOME/Images/Shutter" cd "$FOLDER" for f in *_*.png do num=${f%_*} shutter -f -e -n -o ...


0

http://www.linuxquestions.org/questions/linux-newbie-8/bash-script-to-copy-files-to-samba-share-653093/ Use smbclient (apt-get install smbclient). #! /bin/bash # Scipt to upload /tmp/file to Windows share cd /tmp smbclient -U username%windowspassword //server/share << MARK cd Directory/in/share put file MARK


1

I wound up up creating a variant on swalog's answer. With his you had to wait X seconds for the first iteration, I'm also running my in the foreground so.. ./foo.sh;while sleep 1; do (./foo.sh) ; done


9

Another solution: echo There are $(who | wc -l) people online at the moment


18

You want the output of who | wc -l assigned to w, not that string, which is what you get because of the quotes around it. You should use command substitution $(...): w=$(who | wc -l) echo "There are $w people online at the moment" (you can also use the backquotes, but you cannot easily nest those).


4

you should use backtick to execute command w=`who | wc -l` echo "There are $w people online at the moment"


1

This will help you ip r l && ip addr show {interface name} | grep ether Ex. ip r l && ip addr show eth0 | grep ether Sample output ip r l && ip addr show wlan0 | grep ether default via 192.168.1.254 dev wlan0 proto static 192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.42 link/ether e4:d5:3d:ef:90:a9 brd ...


1

You are better off using ip a, but with your current output, you could use awk: awk ' BEGIN { RS="\n\n"} /eth0/ && /UP/ {ifc=$1; ip=$6; subn=$8; gway=$10; mac=$12} END {print "Interface: "ifc "\nIP: "ip "\nSubnet: "subn "\nGateway: "gway "\nMac: "mac} ' <(ifconfig -a) Interface: eth0: IP: 192.168.0.154 Subnet: 255.255.255.0 Gateway: ...


1

Have you looked into PDF Content Comparer? There are command line options which should let you automate the process. You could run some sort of logic on the difference log it creates to see how similar they are. Failing that you might try splitting the PDF's into multiple files temporarily and comparing them that way. You'd probably still have duplicates ...


-1

There is an Linux application, called recoll. It can perform the task, but only for pdfs with text layer.


0

You can also open up two separate screen sessions to run both scripts. For example: screen -S sampleOne ./runScript.sh At that point you would hold CTRL+A&D, which will exit the screen without terminating and then type: screen -S sampleTwo ./runScript2.sh One other way would be to use tmux to do this as well: tmux new-window -a -n SampleWindows ...


1

You could run the first script in background like this: skript1 & skript2 Each script will run as a separate process. You cannot change variables in the other script.


1

You problem is here: $ attachmenttype='file $attachment | cut -d\ -f2' $ echo $attachmenttype file $attachment | cut -d\ -f2 In this command you just store string file $attachment | cut -d\ -f2 in attachmenttype and when you check in if statement you get invalid result. You need to use bash Command Substitution $(...) to avoiding wrong result. And one ...


2

grep -E 'fatal|error|critical|failure|warning|' *.log


2

Instead of attachmenttype='file $attachment | cut -d\ -f2' you should write : attachmenttype=$(file "$attachment" | cut -d' ' -f2) See http://wiki.bash-hackers.org/syntax/expansion/cmdsubst or to get mime-type : $ file -i "$attachmenttype" | cut -d' ' -f2 text/plain; and decide what you want to do with the file depends of the type.


0

Here's a portable means of getting a sorted list of all currently defined varnames: v(){ set "${IFS+IFS=\$2}" "$IFS"; unset IFS set $(set|sed -n '/^[_[:alpha:]][[:alnum:]]*=/s/=.*//p'|sort -u) "$@" while [ "$#" -gt 2 ] do eval '[ "${'$1'+1}" = 1 ]' && echo "$1"; shift done; eval "$1" } That list is echoed to ...


1

You can store the list of variables at the beginning of the script and compare it with the value somewhere during the script. Beware that the output of commands like set isn't built to be unambiguous: something like set | sed 's/=.*//' doesn't work with variables whose values contain newlines. (In bash, it actually does for string variables, but not for ...


1

You can use: tr -dc '\-0-9\n' | sort -u -t- -nk1,1 | grep -c . ...which is, admittedly, more than a little inspired by muru's answer here. Differently, though, I use grep to count the lines rather than wc in case there are blank lines in input. His answer doesn't have a blank line problem as grep -o will only print lines with their match (as grep -c only ...


1

There is a (common) syntax error in this line (OK, not only one...): [$year>1] [ is not a special character but an ordinary command. Thus the rest of the line is parameters and those must be separated by whitespace: [ "$year" > 1 ] The next problem is that > is not an ordinary parameter but the redirection character (a metacharacter). Thus the ...


0

Would something like this work? if [ "$#" -ne 5 ]; then echo "Illegal number of parameters"; exit; fi #Usage: # ./script-name PORT REM_USER REM_HOST REM_PATH LOCAL_PATH PORT=$1; S_USER=$2; S_HOST=$3; S_PATH=$4; D_PATH=$5; # $S's stand for source # $D stands for destination sftp -r -P $PORT $S_USER@$S_HOST:$S_PATH $D_PATH;


0

An awk solution awk -F'-' '{sub(/[^[:digit:]]+/, "", $1); a[$1]} END{for (k in a) ++i; print i}' file 8


1

Use extended grep to and look for four digits, telling grep to only list the matches (as opposed to the whole line, which is the default): grep -Eo '[0-9]+' <filename> Sort this list of numbers and only output unique ones: sort -u Count the number of lines: wc -l Put it all together: $ grep -Eo '[0-9]+' filename | sort -u | wc -l 8


4

With grep, filter out just the numbers: grep -Eo '[0-9]+-' file | sort -u | wc -l [0-9] Matches any character between 0 and 9 (any digit). + in extended regular expressions stands for at least one character (that's why the -E option is used with grep). So [0-9]+- matches one or more digits, followed by -. -o only prints the part that matched your ...


0

With perl, without any shell pipes (quicker) : $ perl -lne '/\d+-/ and $h{$&}++;END{print scalar keys %h}' file


0

The script provided by LG works fine when you change the grep in the for-loop to: grep "$i " /proc/mounts. In that case it won't return false positives.


0

A solution using comm based on storing all the variables before and after: #!/bin/bash # Storing variables before: set -o posix set > $TMP/VariablesBefore.txt sort $TMP/VariablesBefore.txt -o $TMP/VariablesBeforeSorted.txt a=3 b=7 # Storing variables after: set > $TMP/VariablesNow.txt sort $TMP/VariablesNow.txt -o $TMP/VariablesNowSorted.txt # ...


0

#!/bin/bash DIR="/mnt/filer01/round2/twitter" for file in tweets*.tar do NEWDIR=`echo $file | tr -d [a-zA-Z.]` mkdir $DIR/$NEWDIR tar -xvf $file -C $DIR/$NEWDIR done


2

The [ command should be closed using a ] with a leading space: if [ $string == tweets10_*.tar* ]; then Also, please don't do for x in `ls` Instead, use: for x in * Or, better: for x in tweets10_*.tar and skip the check altogether. You can also extract out the 10_x part more easily: $ a=tweets10_8.tar; echo ${a//[a-z.]/} 10_8 Here, I'm ...


1

Assuming the domain is the most recent before the matching VDISK line, I'd use awk: awk -F '[=|]' -v dev="/dev/dev/my_dev2" ' $1 == "vol" && $5 == dev {vol = $2} $1 == "DOMAIN" {domain = $3} $1 == "VDISK" && $3 == vol {print vol, domain; exit} ' file This outputs disk02 domain01 To capture those in shell variables use read ...


-1

For the moment I'm using this solution, but I would like something cleaner. volname=`grep $dsk ldm_ls-o_disk.out|uniq|cut -d\| -f2|cut -d= -f2` linenr=`grep -n $volname ldm_ls-o_disk.out |grep VDISK|cut -d\: -f1` retval=1 while [ $retval -eq 1 ] do line=`sed -n "${linenr}p" ldm_ls-o_disk.out|grep DOMAIN` if [ $? -eq 0 ]; then ...


1

In order to simulate user input you can use xdottool which is mentioned in comments to your question. Besides, there is xaut (formerly xautomation) python lib. You cas simulate mouse movement and mouse clicks, keystrokes, and manipulate windows from Python. Moreover, there's X11:GUITest perl package. This can be used to interact (SendKeys, ...


1

The Hypertable project has recently added a multi-host ssh tool. This tool is built with libssh and establishes connections and issues commands asynchronously and in parallel for maximum parallelism. See Multi-Host SSH Tool for complete documentation. To run a command on a set of hosts, you would run it as follows: $ ht ssh 1.1.1.1,2.2.2.2,3.3.3.3 uptime ...


2

You could use something like this: find . -name "*.log" | xargs grep -E 'fatal|error|critical|failure|warning|' This will find every file with .log as extension and apply the grep command.


1

Something along the lines of: name_of_process=$1 ps aux\ | grep $name_of_process\ | grep -v "grep"\ | awk '{print \"{\ \"pid\" : $2,\ \"status\" : $8,\ \"usageCPU\" : $10,\ \"usageMemoire\" : $4,\ \"numFD\" : $some_field_num,\ \"commandline\" : split($NF)[0]\ \":[{ \"pid\" : $2},{\"pid\" : $some_field_num_too }]}' So ...


0

You can try elinks with Javascript support. Once it is build just type: elinks --dump 1 http://www.example.com/my-js-page.html and that should do it. Their documentation says that the Javascript support isn't great but this is another way of doing it.


0

I'm not sure which distribution you're using, but very often cron scripts will run with a minimal shell with less "fanciness" than an interactive shell. Is this your entire script? If so, you should add a shebang to load some proper context. Also, it helps to use the fully-qualified path for things other than builtin shell commands. For example, find may be ...


6

Found this method on AskUbuntu that shows using a crontab entry along with amixer to mute/unmute the sound. It's titled: How do I automatically mute/unmute sound during a certain time period (e.g. night)?. General steps Create a crontab entry $ crontab -e Add entries to crontab 59 21 * * * amixer set Master mute 00 08 * * * amixer set Master unmute ...


1

I'm assuming that you are asking this because you want it to be done automatically rather than having somebody tell you "Just turn the volume down when you go to bed". Go to a shell prompt and use "crontab -e" and add two events along this lines of this: 0 21 * * * /usr/sbin/amixer -D pulse sset Master,0 0% 0 8 * * * /usr/sbin/amixer -D pulse sset ...


1

You should pipe the output of date to awk: $ date | awk '{print $2, $3, $6}' 1 Dec 2014 or get date to format it for you: $ date +'%d %b %Y' 01 Dec 2014


8

Why use awk at all? date +"%b %d %Y" gives you the values without the hassle.


5

Try piping the output from the date command instead, like so: $ date | awk '{print $2, $3, $6}' Dec 1 2014 If you truly want to take the output from date using a command similar to yours then you'll need to redirect it using a HERESTRING, aka. (<<<) (assuming a zsh shell or a fairly recent version of ksh93 or bash). $ awk '{print $2, $3, $6}' ...


0

Have a look in your cron Configuration file. Maybe your cron-job is run as an specific user which does not have access to everything. Also its a clever idea to write log-files so you can see what exactly your script does when run by cron.


0

Just to note that that above accepted answer is not complete. To do an actual array assignment you are missing parenthesis around your original array otherwise you will still get a new array of size 1 What i mean is that the following: eval varAlias=\${"myvar"$varname[@]} should be changed to: eval varAlias=(\${"myvar"$varname[@]}) You can validate ...



Top 50 recent answers are included