Error stop when scripting
I have written a script that backups my files over the network.
My problem is that i wan't an error log to be written if somthing goes wrong in my script. Eg. First of all i run this line mount -t smbfs -r -o password= //viljamusikxp/bilder /mnt/bilder But if by some reason this computer is of I don't wan't the rest of the script to be run. Instead i wan't an error log to be written. How can I do this? |
I would pipe the output of the command into a grep for the error you get if it fails then if the grep returns with a match then you stop proccessing the script.
|
can you give an exampel? Not so god at scripting!
Thx for the help anyway.. |
I would pipe the output of the command into a grep for the error you get if it fails then if the grep returns with a match then you stop proccessing the script.
If any app handles it's exit status "$?" well, then inserting a Code:
case "$?" in 0) ;; *) logger "got exit status ($?)"; exit 1;; esac |
thx..but one more qustion.
the line case "$?" in 0) ;; *) logger "got exit status ($?)"; exit 1;; esac can you explain a bit more. Where do I tell this line that if moutn fails it should logg this. And where do it logg to. |
it worked. But where dose it log it. I wan't it to be logged in
/var/log/test.log How do I do this? |
Quote:
|
case "$?" in
0) ;; *) echo "wrong on mounting windows disc" >> test.log # logger "got exit status ($?)"; exit 1;; esac This worked...is it okej...what did the logger thing do? |
From "man logger"
Code:
NAME |
Yes - sorry(..) check the output for strings.
Np man, you noticed I started with "if"? :-] About strings I agree, tho I usually try to avoid it if I can... |
A..ok thx..now my program workes great.
|
All times are GMT -5. The time now is 07:34 PM. |