LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-12-2003, 02:23 PM   #1
eXor
Member
 
Registered: Mar 2002
Location: Sweden
Distribution: Slackware 10.1
Posts: 103

Rep: Reputation: 15
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?
 
Old 06-12-2003, 02:32 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
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.
 
Old 06-12-2003, 02:35 PM   #3
eXor
Member
 
Registered: Mar 2002
Location: Sweden
Distribution: Slackware 10.1
Posts: 103

Original Poster
Rep: Reputation: 15
can you give an exampel? Not so god at scripting!

Thx for the help anyway..
 
Old 06-12-2003, 02:40 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
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
should do, shouldn't it? Zero does nothing, so the script should run along, 1, 127 or whatever $? throws at you will exit it.
 
Old 06-12-2003, 02:44 PM   #5
eXor
Member
 
Registered: Mar 2002
Location: Sweden
Distribution: Slackware 10.1
Posts: 103

Original Poster
Rep: Reputation: 15
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.
 
Old 06-12-2003, 02:49 PM   #6
eXor
Member
 
Registered: Mar 2002
Location: Sweden
Distribution: Slackware 10.1
Posts: 103

Original Poster
Rep: Reputation: 15
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?
 
Old 06-12-2003, 02:49 PM   #7
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
Quote:
Originally posted by unSpawn
should do, shouldn't it?
Yes - sorry, I was thinking that he wanted to capture the output from his script and I since not everyone will output the exit codes properly I quite often check the output for strings.
 
Old 06-12-2003, 03:01 PM   #8
eXor
Member
 
Registered: Mar 2002
Location: Sweden
Distribution: Slackware 10.1
Posts: 103

Original Poster
Rep: Reputation: 15
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?
 
Old 06-12-2003, 03:04 PM   #9
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
From "man logger"
Code:
NAME
     logger - a shell command interface to the syslog(3) system log module

SYNOPSIS
     logger [-isd] [-f file] [-p pri] [-t tag] [-u socket] [message ...]

DESCRIPTION
     Logger makes entries in the system log.  It provides a shell command
     interface to the syslog(3) system log module.
 
Old 06-12-2003, 03:06 PM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
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...
 
Old 06-12-2003, 03:06 PM   #11
eXor
Member
 
Registered: Mar 2002
Location: Sweden
Distribution: Slackware 10.1
Posts: 103

Original Poster
Rep: Reputation: 15
A..ok thx..now my program workes great.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH scripting I/O redirection error blinux1 Programming 13 03-18-2008 09:21 PM
shell scripting error shouup Programming 8 09-08-2005 01:38 PM
BASH scripting error Darklight451 Linux - General 4 11-22-2004 04:59 PM
Shell scripting error bindweb Programming 4 09-30-2004 11:50 AM
Newbie : expr scripting error hrg Linux - General 3 08-13-2004 11:24 AM


All times are GMT -5. The time now is 07:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration