Tag Info

New answers tagged

0

#! /bin/bash echo "Script is starting......." FILE="/Users/shubhamsinha/Desktop/new_test.log" STRING="MYNAME" while true; do tail bar | grep "MYNAME" && echo "FOUND" && break sleep 5 done Example FILE="/home/user1/tmp/bar" Script name is foo % ./foo & [1] 12586 Script is starting....... ...


0

I'm assuming by parent folder you just mean the folder with filename.txt. You can get find to print this folder name with -printf '%h\n' instead of the -exec. You can pipe this into a shell loop or xargs for example: find /path/ -name "filename.txt" -type f -mtime -2 -printf '%h\n' | xargs -i rsync ... {} /destination \; I think you need to add -R to ...


0

I've solved it. Thanks everyone for your input: Your asking for more information led me to finding out that the program had to be started AFTER LXDE was ready for a desktop session. And as such I googled and found out that /etc/xdg/lxsession/LXDE/autostart contains a list of applications that will be starting after the desktop session is started. I added ...


4

Okay, let's break this down. A subshell executes its contents in a chain (i.e., it groups them). This actually makes intuitive sense as a subshell is created simply by surrounding the chain of commands with (). But, aside from the contents of the subshell being grouped together in execution, you can still use a subshell as if it were a single command. That ...


1

subshell (command) will execute command in subshell, this is usefull, if you have more then one command. (ls) | wc will pipe ls to wc, obviously you can write ls | wc (ls ; date) | wc will pipe the result of both ls and date to wc. using ls ; date | wc will result in only date being piped to wc. substitution $(command) will execute command and ...


1

You really don't want to store this in a temporary file. There isn't any need, either, but it requires a bit of creative shuffling: data=$(dialog --passwordbox "Enter your password" 10 30 3>&1- 1>&2- 2>&3-) What that does is swap fd 1 and 2 around (the "X>&Y-" construct means, "move fd Y so it becomes fd X instead". Yes, that's ...


0

I'm not sure if this is exact answer, but at http://linuxcommand.org/lc3_adv_tput.php I found several functions testing tput for colorizing BASH. I hope it helps. #!/bin/bash echo "tput colors test" echo "================" echo echo "tput setaf/setab [0-9] ... tput sgr0" echo for fg_color in {0..7}; do set_foreground=$(tput setaf $fg_color) for ...


2

So you do not have tempfile (resulting in: command not found). Therefore your variable data is set to an empty string. When you try to redirect dialog ... 2> $data it tries to redirect stderr to a not existing value. And that is ambiguous. Your options are to change data=$(tempfile 2>/dev/null) to data="/tmp/mytmpfile" or to install tempfile by ...


1

The following shell script, when given an argument of the form file1.x, generates a series of diffs. It increments the last series of digits in the file name (so you can start at file0.x or file42.x) and goes on until it finds a missing number. #!/bin/sh current=$1 suffix=${1##*[0-9]}; digits=${1%"$suffix"} digits=${digits##*[!0-9]}; ...


0

While it's not that hard to replicate, your screenshot likely came from tldp.org; the bottom of that page contains a script that outputs the table you see: To help myself remember what colours are available, I wrote a script that output all the colours to the screen. Daniel Crisman has supplied a much nicer version which I include below: #!/bin/bash # # ...


2

The following script takes an argument like "file*.x" and applies it to find | sort to get a list of files to process. With thousands of files, you may get "too many arguments" by echo file*.x. #!/bin/bash prev= find . -maxdepth 1 -type f -name "$1" | sort -V | while read -r file; do file=${file#*/} # Remove leading ./ if test -n ...


1

There's something odd going on with the command line - whether it is a file-system problem or something more elementary (like unprintable characters in a directory name). The error message "Unable to find a suitable output format for pipe:1" is due to the previous "-f flac" being ignored. I have tried renaming an mp3 to your stated problem filename, and ...


0

Execute echo $0 to know what shell you're using when you run ./extract.sh $ echo $0 /bin/bash Put the shebang at the very first line #!/bin/bash mboxutil -l > n.txt sed 's/^.*user//' n.txt > n1.txt cat n1.txt | sed 's/^.//' > n2.txt sed 's/\/.*//' n2.txt > dss_list.txt rm -f n.txt rm -f n1.txt rm -f n2.txt sed -e '/^$/d' -e '1d' dss_list.txt ...


2

Check for the existence of a PID from the same script. Supposing your script is called my_script.sh add this at the beginning of the script: #!/bin/bash for pid in $(pidof -x my_script.sh); do if [ $pid != $$ ]; then kill -9 $pid fi done


1

I did this a long time back in one of my shell scripts. Here is how I did it: ps aux | \ grep -P ${BASH_SOURCE[0]} | \ grep -v $$ | \ grep -P "bash" | \ grep -oP "^[[:alnum:]]+\s+\d+\s" | \ grep -oP "\d+" | \ xargs kill -9 The beauty of this method is that it will NOT kill the current running script itself, only the previous instances of it. A sample ...


0

Try this: #!/bin/sh if [ -f /var/run/sh.pid ]; then echo "Process already running." kill -9 `cat /var/run/sh.pid` rm -f /var/run/sh.pid fi echo `pidof $$` > /var/run/sh.pid # From here, your normal shell script can resume


0

For a more general approach to killing processes... This command should show the process pgrep -f runcommand.sh Then either cut and paste the process ID kill PROCESSID or, if you're a little braver using pipes pgrep -f runcommand.sh | xargs -I{} kill {} If you don't have pgrep (for some reason), then you can replace the pgrep command with this ...


0

Give a try to killall runcommand.sh EDIT: |─lightdm─┬─Xorg───2*[{Xorg}] │ ├─lightdm─┬─init─┬─at-spi-bus-laun─┬─dbus-daemon │ │ │ │ └─3*[{at-spi-bus-laun}] │ │ │ ├─at-spi2-registr───{at-spi2-registr} │ │ │ ├─bamfdaemon───3*[{bamfdaemon}] │ │ │ ...


0

Try sudo killall --process-group emulationstation


2

The answer is: You can not! Linux is no real time system. The idea of UNIX and therefore Linux, too, is to provide minimum answer times, while the system is shared between multiple users and system processes. Depending on when you start the command, you might have to wait for a important system process to give you your share of processor time. Further the ...


0

The default route is just another route. If you remove it, the kernel has no way of retaining it. It's just runtime configuration that can change. If you have configured your interface somewhere, you can try restarting the interface (as you mention in your own answer). If you haven't done that, however, you'll need another solution. I can see two options: ...


0

Duh. Not sure why in all my scripting I never thought of this before, but one easy way to do it is to reset the interface: ip link set eth0 down ip link set eth0 up


1

So I took your hex string and printed it out to bytes, but I swapped the NULs for <spaces> (mostly because I can't figure on how to get a NUL in a grep pattern): time \ ( set x58 x5e x20 x20 xfe x5a x1e xda \ x48 x20 x20 x20 x0d x20 x03 x20 \ x07 x20 x20 x20 xcd x01 x20 x20 export ...


2

The standard way of doing this in Debian is with debconf (not to be confused with the Debian conference!). This allows packages to ask questions and act on the user's answers. The wiki linked above has details, including a link to a tutorial (using debconf is too involved to explain here).


4

The GNU implementation of grep (also found in most modern BSDs though the latest versions are a complete (mostly compatible) rewrite) supports a -o option to output all the matched portions. LC_ALL=C grep -ao CDA | wc -l would then count all the occurrences. LC_ALL=C grep -abo CDA to locate them with their byte offset. LC_ALL=C makes sure grep doesn't ...


0

#!/bin/bash turns=(R Ri L Li U Ui D Di F Fi B Bi R2 L2 U2 D2 F2 B2) declare -A possible for i in ${turns[@]}; do possible[$i]=$(printf "%s\n" "${turns[@]}" | grep -v ${i:0:1}) done next=${turns[*]} for ((i=0; i<$1; i++)); do j=$(shuf -n 1 -e $next) turnArray[$i]=$j next=${possible[$j]} done echo ${turnArray[*]} ...


0

You were correct, exp_internal -f passcheck-debug.log 1 pointed me to the problem of not having enough ptys. I added: close -i $spawn_id wait -nowait and it continued beyond that point. I had to add -nowait because if it doesn't have a spawn_id it will wait forever.


1

Test on $0 if you have a script: #!/bin/bash echo $0 and make it executable (chmod 755 test.sh) and do: source test.sh you get bash (or something else depending on how you are logged in and what your shell is). If you do ./test.sh you get ./test.sh, so assuming that the script knows how it is saved on the disc you should do: if [ $(basename "$0") ...


1

Use this dd=$(date -d"$mm" +%Y%m%d) That's all. Example % mm="27 Jun 2011" % dd=$(date -d"$mm" +%Y%m%d) % echo $dd 20110627 to compare with your version % dd=$(date -d"27 Jun 2011" +%Y%m%d) % echo $dd 20110627 % dd=$(date -d'27 Jun 2011' +%Y%m%d) % echo $dd 20110627


1

That's not how you do shell scripting. You're running several commands in sequence for each line of the files! Here you want something like: awk -F, '/040302010/ {actual_cost += $7} ENDFILE {print FILENAME ":", +actual_cost; actual_cost=0} ' data*.CSV (assuming GNU awk). That's one command in total for all your files.


1

You need to use full paths to the output files and probably to the executables as well. When run in cron, there is no pre-existing environment for it to know things like a working directory or a path.


1

#!/usr/bin/env bash # Above, get the path to BASH from the envvironment. # Below, you could just set the total mileage here. total_mileage=0 # Below, start from zero and count up for the three loops. for ((i=0; i<3; i++)); do # Below, use `-n` to prevent the new line. # It's ok to use descriptive variable names. # echo -n "Enter gallons ...


4

The following command yields the requested output: cut -d ' ' -f 1,3-10 file1


0

It might be handy to introduce another command substitution, with the core loop logic defined in a function: sum_cost() { sum=0 while read -r line ; do IFS=',' read -a array <<< "$line" sum=$(echo "$sum + ${array[7]}" | bc) done echo $sum } for filename in data*.CSV; do echo $filename ACTUAL_COST=$(grep '040302010' ...


0

Is c your accumulator ? set it to zero to start with, then you will not get syntax error in line 10 you get an integer result because there is no operation in line 9, Merge lines 8 and 9 to then milage will have a decimal result. mileage=`echo "scale=4; $mil / $gal" |bc` You do not do anything useful with $c and fail to print it after the loop.


0

To avoid the subshell you can use the following: while read -r line do your_stuff done < <(grep '040302010' $filename') That way you are able to fill in the result(s) into the variable.


5

To be on the safe side, include the slash. This can lead to multiple slashes when concatenating the paths, but at least you avoid problems. A few examples: rsync treats paths differently if the trailing slash is included (it synchronizes that directory instead of making another subdirectory). Symbolic links to directories sometimes behave in an unexpected ...


5

According to POSIX: Definition of a pathname: A string that is used to identify a file. It has optional beginning < slash > characters, followed by zero or more filenames separated by < slash > characters. A pathname can optionally contain one or more trailing < slash > characters. Multiple successive < slash > characters are considered ...


3

No, you should not. It adds an extra unnecessary slash (/). example say you want to export java's bin directory to your PATH variable , export PATH=$PATH:/opt/jre1.7.0_45/bin/ now check it, user@host:~$ which java /opt/jre1.7.0_45/bin//java notice the extra slash (/) before java, but fortunately it just works in such case.


-3

You can do it with: sed -e's/ testhost / testhost testhost1 testhost2 testhost3 /; s/ testhost$/ testhost testhost1 testhost2 testhost3/' /etc/hosts


2

The correct and complete answer is: To modify access time only with the "touch" command, you must use "-a" parameter, otherwise the command will modify the modification time too. For example, to add 3 hours: touch -a -r test_file -d '+3 hour' test_file From man touch: Update the access and modification times of each FILE to the current time. -a ...


1

To check for the existence of files matching a pattern, you can do something like if [ "$(shopt -s nullglob; printf "%s" "$WORK"/*"$PRCSID".unl)" != "" ] then tar -cvzf "$WORK/INET_$PRCSID.unl.gz" "$WORK"/*"$PRCSID".unl fi (I’m assuming that you didn’t intend to look in one place for .unl files and then archive files from another place.) shopt -s ...


3

Of the two shell functions below, the actual math is just done here: while set "${1#0?}" "${1#?}" shift "$((!${#1}))" [ "${1:-0}" -gt 0 ] do case $1 in ([3-9]?|2[5-9]) set "$(($1%25))" "$((q+=$1/25))";; (??) set "$(($1%10))" "$((d=$1/10))" ;; (?) set "" "$((p=$1-(5*(n=$1>=5))))";; ...


2

Another answer has addressed your specific issue. I baulked after a while of trying to sort it out. So, here is another approach for you to consider - with one while and one until and one for loop. Arrays help to simplify the code. echo "Enter amount of money: $.c or just $" read amount echo a=(${amount/./ }) # change '.' to ' ' and make an array: ...


6

Your code's most obvious issue is that all of your while loops check a variable (e.g. $quarter) that is never changed inside the loop, so the loop condition can never become false and the loop repeats endlessly. Let's look at one of the loops: while [ $quarter -ge 0 ] do qNum=$(( qNum+1 )) amount=$(( $amount-25 )) done If $quarter > 0, the control flow ...


2

Shortened awk script which expects an input formatted exactly as your example (it [merely] compares the number contained in the 9th field of the first line against the total number of lines minus two): < in awk 'NR==1 {c=$9} END {if (c==FNR-2) print "ok"; else print "ko"}'


0

I ended up just running the commands in a single crontab line with && and inside of a bash -l -c statement, it is working now!


4

Using awk awk '! /^detail/ && /.+/ {max=$9} /^detail record/ {count++} END {if (max == count) { print "ok, "max" = "count} else { print "not ok, "max" != "count }}' foo Or as bash script #!/bin/bash retValue=$(awk '! /^detail/ && /.+/ {max=$9} /^detail record/ {count++} END {if (max != count) { print "1" }}' "$1") if [[ "$retValue" -eq 1 ...


1

Just put the value in a variable compiler_options_for_debug_version="" if something; then compiler_options_for_debug_version="-g -O0" fi Then make sure you quote the variable when you use it: this is just as important. CFLAGS="$compiler_options_for_debug_version" ./configure ...


0

As it seems that the limitation is more on the user experience side (don't have to enter password again and again), the best choice here would be to enter your public key (the .pub file in your ~/.ssh folder) in the destinations ~/.ssh/authorized_keys file. Here the ~ folder stands for the home of the users that are involved on the source and destination ...



Top 50 recent answers are included