Tag Info

New answers tagged

1

I want my script to tell the user if the string isn’t found ….    I have tried ... to use an else statement but it didn't work. What did you try? if grep -q "$STRING" "$FILE" then echo "string found" else echo "string not found" fi works. P.S. I advise you to quote all references to shell variables (e.g., "$INPUT_STRING2", ...


3

You did two syntax errors (in after the variable and esac as end of the case statement): echo "Do you wish to search again? [y/n]" read INPUT_STRING2 case $INPUT_STRING2 in "y") echo "Searching again" ;; *) exit ;; esac


3

There seems to be an 'in' missing in the line with the case statement as well as a closing esac: echo "Do you wish to search again? [y/n]" read INPUT_STRING2 case $INPUT_STRING2 in y) ;; *) exit ;; esac


2

Different emulators have different capabilities and protocols for the hold open feature. Some simply will not/can not do this. Others require the script to specify that the emulator remain open. I ran into this when writing a simple script for a program called HDSentinel. Here are the various solutions I can up with: KDE (Konsole emulator) konsole -hold -e ...


0

I do have the exact same problem than you for years as well. For simple non-interactive uses, I like to use the binary block editor BBE. BBE is to binary as SED is to text, including its archaic syntax and simplicity, however, it has a lot of features missing from what I often need, so I have to combine it with other tools. So, BBE is only a partial ...


1

It looks like the causing problem is being caused during looping of while cat /test/emailbody.txt; Remove the "," while printing in file and push @dzones, "No files have more than 20% deletions.\n\nPlease see attached for the deletions in different zones.\n\nThanks, Vishal\n\n";


3

Does the order of fileA matter? Can you have multiple lines in fileB with that pattern? This will for example parse fileA and search for each pattern in fileB: while read i; do grep "$i" fileB; done < fileA But you need to define the problem better to get a solution with more performance. For example it is sufficient to get the whole line, you don't ...


11

You can just use grep: grep -Fwf fileA fileB From man grep: -F, --fixed-strings Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. (-F is specified by POSIX.) -f FILE, --file=FILE Obtain patterns from FILE, one per line. The empty file ...


3

You missed a fi for inner if: if [ "$mes" -lt 12 -a "$mes" -gt 0 ]; then echo "muy bien, sigamos." else if [ "$mes" -gt 12 -a "$mes" -lt 0 ]; then echo "Creo que eso ya no es un mes!"; # Missed fi here fi exit fi


0

If your script file is invoked by cron and it contains a shell in the first line like #!/bin/bash you need to find the parent-parent name for your purpose. 1) cron is invoked at the given time in your crontab, executing a shell 2) shell executes your script 3) your script is running The parent PID is available in bash as variable $PPID. The ps command to ...


3

An alternative solution using xargs: echo -n {c..k} | xargs -d' ' -I{} echo mount /dev/sd{}2 /{}2


10

Globbing (which is what you're doing with your wildcard matching) will expand the current command line. For example: ls [abc]1 gets expanded to: ls a1 b1 c1 Globbing only works where the command allows multiple arguments. While umount /dev/sdc2 /dev/sdd2 Works, there's no way to express the same thing for mount. So you have to loop it: for m in ...


3

There are many ways of doing this. The approach you tried would have worked perfectly if each sudo did not require you to enter a password. Since it does, the commands would hang since the 2nd would ask for a password and you weren't there to give it. Therefore, you need a way of running everything with a single sudo call. Here are a few ways of doing this. ...


8

Note the usage for rsync is rsync [OPTION]... SRC [SRC]... DEST which means this can be more simply written as rsync -r -t -h /src1dir /src2 /src3 /destdir which isn't subject to sudo session timeouts. You didn't ask, but the option -a is far more comprehensive than -r -t.


12

For repeatability I suggest to put the lines into a small script, but without the keyword sudo: #!/bin/bash rsync -v -v -r -h -t --progress /Volumes/My\ Book/Backups.backupdb/MbpScs-van-iSCS/2014-01-02-233653/SSDaeffer /Volumes/BackupMyBook/ViaMacbookMove/DitIsDeMap rsync -v -v -r -h -t --progress /Volumes/My\ ...


1

Using awk: awk ' NR==1 { for (i=1; i<=NF; i++) header[i] = $i } NR==FNR { for (i=1; i<=NF; i++) { A[i,NR] = $i } next } { for (i=1; i<=NF; i++) if (A[i,FNR] != $i) print "ID#-" $1 ": " header[i] "- " ARGV[1] " value= ", A[i,FNR]" / " ARGV[2] " value= "$i }' file1.txt file2.txt Output: ID#-ee: Time- file1.txt value= ...


1

Here's a script that I think does the job: #! /bin/bash FILE1=$1 FILE2=$2 [[ -z $FILE1 || -z $FILE2 ]] && echo "USAGE: $0 FILE1 FILE2" && exit 1 join -j 1 $FILE1 $FILE2 | awk ' NR == 1 { for (i = 1; i <= NF; i++) { header[i] = $i; }; NCOLS = (NF - 1)/2; } NR > 1 { for (i = 2; i <= NCOLS + 1; i++) { if ($i != $(i+NCOLS)) {print ...


3

No, not every GUI application interprets the commandline arguments/options, and many only have options for configuration or debug issues that are best set in the process of starting the application. However there are several GUI test/automation tools (look at the automation column and Linux compatibility), that can drive your application. For simple ...


4

If you want to redirect the output of the echo command, the redirection operator > needs to be outside of any quotes. The character > between double quotes stands for itself. By default, in bash, echo doesn't expand backslash sequences. You need to pass the -e option to echo, set the xpg_echo shell option with shopt, or use printf instead of echo. ...


0

If you're only running on Unix, use fifos. You can write work records to the fifo and have processes read from this file and your readers will block on the fifos. Lock files are ok, but for what you describe I would go with fifos


0

I was having the exact same question a year ago, and after asking some people I started with Fabric. It was recommended to me over Puppet and Chef for it's simplicity. You can easily mix local commands and remote commands in the same function. Also, being able to use Python instead of Bash is a notable upgrade that will help if you need to do lots of helper ...


0

If I understand the purpose of your code correctly, then, in your example case: $6$hcwp49Lr$BjcJYc/nwaufmsOIw4Tw/POaXO4j.0HDLU0 should be replaced with: XXXXX If this is true, you don't need to involve the shell at all: sed '/^user:/s/:[^:]*/:XXXXX/ ' <<\DATA # junk here user:$6$hcwp49Lr$BjcJYc/nwaufmsOIw4Tw/POaXO4j.0HDLU0:16310:0:99999:7::: ...


1

If you want $arr to be substituted, you need to put it outside single quotes. For instance: sed -i "s|$arr|XXXXX|g" /tmp/shadowtest


4

docx2txt works on the information in the docx file which is a zipped set of XML files. With regards to line wrapping the .docx XML data only includes information about paragraphs and hard-breaks, not about soft-breaks. Soft-breaks are a result of rendering the text in a specific font, font-size and page width. docx2txt normally just tries to fit text in 80 ...


4

sed: Call the sed command -i: Pass sed the -i option: Modify the file in-place 's|\(LAYOUT PATH \).*|\1 "../GDS/'$1'.gds"|g': The '...'$1'..' are used to make this whole part one single argument to the sed command s|\(LAYOUT PATH \).*|\1 "../GDS/'$1'.gds"|g: s|pattern|replacement|options: s is the substitute (or search and replace) command, the | ...


1

I can comment on Gnome's "Application is not responding" dialog, but not directly answer your question. It seems that both Metacity and Mutter use meta_display_ping_window() function to determine the status of a window (read the doc comment in display.c). The default timeout PING_TIMEOUT_DELAY is 5 s. Ping-timeout and response are handled internally by ...


0

You can give nmap a range: $ nmap -sn 138.0.0.0/24 $ nmap -sn 138.0.0.0-255 The -sn flag means to just ping the host and return (i.e. no port scan like nmap usually does). Edit: After reading the comments I see that bahamat mentions arp. In fact, arp with no arguments runs faster than nmap for me, and finds everything connected to my LAN: $ time arp ...


4

eval does a printf of its arguments and then runs it as a command. So you can take your printf argument list, insert set $MyVar = at the beginning, and eval it. (gdb) eval "set $MyVar = \"Hello %d\"", 7 (gdb) print $MyVar $2 = "Hello 7"


2

Are you okay with typing the password when you run it? You can read it in a bash script without making it visible in the terminal, saving to history, etc: #!/bin/bash if ! IFS= read -rs -p "Enter password: " password < /dev/tty 2> /dev/tty then echo "Password entry failed" exit 1 fi somecommand -user me -password $password Looking at the other ...


3

It will not only show up on your screen, but also in ps output, in your ~/.bash_history (though that one should only be readable to you and the admins) and possibly in some audit or performance logs. You should not pass passwords as arguments to commands. Arguments to commands should be considered public knowledge. For mysql, use ~/.my.cnf as Michael has ...


5

A better option than providing the password on the command line at all is to make a ~/.my.cnf file with the credentials in it: [client] password=something That way they are also protected against someone looking at the ps output, or your shell history. That said, you can turn off the watch title entirely with the -t or --no-title option, which will: ...


3

use readlink to get the target of a symlink: TARGET=$(readlink $1) then use the power of shell, to remove everything before the last /; ID=${TARGET##*/} or remove everything after the last /: BASE=${TARGET%/*} then use the power of shell to do simple arithmetic NEWID=$((ID+1)) finally glue them together: NEWTARGET=${BASE}/${NEWID} or, in one ...



Top 50 recent answers are included