Hi, On Mon, Feb 21, 2000 at 15:05 -0600, Jon Pennington wrote:
On Mon, 21 Feb 2000, Stefan Troeger wrote:
dothis && dothat && anddothattoo && echo "done" |mail jpennington -s "done" || echo "failed" |mail jpennington -s "failed"
Okay, I've cleaned up my script quite a bit since this posting. The part that still eludes me is the usage of the || operator. Remember, I've never written a script in my life ;) [...] If a backup or a fake backup file exists (/tmp/irm-$IRM_DATE.dump.gz), gz asks if I want to overwrite it. Since this script is meant to be non-interactive, what would you do if you wanted to overwrite the file automatically? I still don't know how an error could be trapped and an alternate message sent; would you mind elaborating on that concept a bit?
Regarding gzip, you should use the -f option so it will automatically owerwrite files. Error trapping works because every program returns an exit code when it exits. If that exit code is 0 everything went fine, if it's >0 an error occured. If you connect several programs with the && operator like this program1 && program2 && program3 program2 will only be executed if program1 exited Ok (i.e. with exit code 0) and program3 will only be started if program1 and program2 exited Ok. || works similar, but in program1 || program2 program2 will only be executed if program1 failed (exit code >0). If you use this in your script a `done'-mail is only sent if every program exited Ok. If an error occured somewhere you'll receive the `failed' message. Try this (true returns 0, false 1): [sttr]/home/sttr/1> true && true && true && echo Ok || echo Oops Ok [sttr]/home/sttr/1> false && true && true && echo Ok || echo Oops Oops Btw. `man bash' is a good reading ;-) Ciao, Stefan -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/