sh

not exit a bash script when one of the sub-script fails

拟墨画扇 提交于 2020-06-16 17:29:29
问题 I am new to shell script. I have a script that runs several test scripts using different input files. Currently it exits if any one of the input test fails. I want the test to complete running the loop and exits with all errors accumulated at last. main.sh set -e ; set -x ; for f in $files;do ./scripts/test_script.sh $f done ====================== test_script.sh : runs few stuff and exits like this. : : : exit $? ================ 回答1: set -e is what causes your script to exit immediately

entering password into openssl command from shell script

不羁岁月 提交于 2020-06-12 08:28:50
问题 I am trying to convert a p12 to a pem from a shell script without any user input. I can have the password as a variable within the script. so when I call: openssl pkcs12 -in *.p12 -out cert.pem -nodes The terminal prints "Enter Import Password:" and waits for input. I tried to pipe the password in with: echo $PASS | openssl pkcs12 -in *.p12 -out cert.pem -nodes as well as trying to use a flag with the openssl command but can't figure out how to do this. 回答1: This one liner worked for me-

Treat first column with spaces as one column using awk

∥☆過路亽.° 提交于 2020-06-02 09:33:26
问题 I have this data that wanted to extract. However, im having trouble with the first column since some data has space in it making it hard for me to parse it using awk 6_MB06 SA003 1550 None uats admin 1270 1478640 1211360 none 2957656064 no 0 no 60021AA29H38028200000000000521D3 no no 0 no yes no no supported no no 18 2.60 193 no 0 Active optimized 0000 Not Available 6_VLS01 G 516 None uats admin 0 492880 176 none 1008291840 no 0 no 60021AA29H38028200000000000521D4 no no 0 no yes no no

Treat first column with spaces as one column using awk

▼魔方 西西 提交于 2020-06-02 09:33:11
问题 I have this data that wanted to extract. However, im having trouble with the first column since some data has space in it making it hard for me to parse it using awk 6_MB06 SA003 1550 None uats admin 1270 1478640 1211360 none 2957656064 no 0 no 60021AA29H38028200000000000521D3 no no 0 no yes no no supported no no 18 2.60 193 no 0 Active optimized 0000 Not Available 6_VLS01 G 516 None uats admin 0 492880 176 none 1008291840 no 0 no 60021AA29H38028200000000000521D4 no no 0 no yes no no

Send E-Mail on File Change in monitored directory

对着背影说爱祢 提交于 2020-05-15 18:36:27
问题 I want to send an e-mail notification to guys in our company if a file changed in their staff folder on the server. I have a script that works fine on sending an e-mail on every file change using inotifywait. What I would like to do is on multiple file uploads (lets say 10 jpg's are being uploaded to somebody's staff folder) to only send out one email. This script sends an email on every file change: inotifywait --recursive --exclude '.DS_Store' -e create -e moved_to -m /media/server/Staff

Bash script - Auto fill answer

爷,独闯天下 提交于 2020-05-13 05:14:12
问题 I have a bash script that has several questions, is it possible to automatically fill the answers ? ./script.sh install answers in order y 2 1 n n How can I do that in bash ? edit: is it possible to only pass the first answer ? echo "y" | install and let the choice to the user to answer the next questions ? 回答1: I would pass a here document to stdin: ./script.sh install <<EOF y 2 1 n n EOF If you want it on one line, you can also use echo : echo -e "y\n2\n1\nn\nn" | ./script.sh install

Bash script - Auto fill answer

余生长醉 提交于 2020-05-13 05:14:07
问题 I have a bash script that has several questions, is it possible to automatically fill the answers ? ./script.sh install answers in order y 2 1 n n How can I do that in bash ? edit: is it possible to only pass the first answer ? echo "y" | install and let the choice to the user to answer the next questions ? 回答1: I would pass a here document to stdin: ./script.sh install <<EOF y 2 1 n n EOF If you want it on one line, you can also use echo : echo -e "y\n2\n1\nn\nn" | ./script.sh install

Write current date/time to a file using shell script

情到浓时终转凉″ 提交于 2020-05-12 04:42:42
问题 I am trying to use a shell script to write the current date and time to a file. Here is what I have so far echo "$(date)" >> //home/user/Desktop/Scripts/Date Logs/datelog.txt It will say it completed but nothing is printed to the file after it is run. 回答1: Use date >> //home/user/Desktop/Scripts/Date Logs/datelog.txt . Like i tried in my system :- date > /tmp/date.txt . And file contains Wed Apr 5 09:27:37 IST 2017 . [Edit] There are difference between >>(appending to the file) and >(Create

Inline if shell script

纵然是瞬间 提交于 2020-05-09 20:08:59
问题 Is it possible to execute shell script in command line like this : counter=`ps -ef | grep -c "myApplication"`; if [ $counter -eq 1 ] then; echo "true"; > Above example is not working I get only > character not the result I'm trying to get, that is "true" When I execute ps -ef | grep -c "myApplication I get 1 output. Is it possible to create result from single line in a script ? thank you 回答1: It doesn't work because you missed out fi to end your if statement. counter=`ps -ef | grep -c

Inline if shell script

社会主义新天地 提交于 2020-05-09 20:08:38
问题 Is it possible to execute shell script in command line like this : counter=`ps -ef | grep -c "myApplication"`; if [ $counter -eq 1 ] then; echo "true"; > Above example is not working I get only > character not the result I'm trying to get, that is "true" When I execute ps -ef | grep -c "myApplication I get 1 output. Is it possible to create result from single line in a script ? thank you 回答1: It doesn't work because you missed out fi to end your if statement. counter=`ps -ef | grep -c