LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-13-2005, 07:06 PM   #1
Kristijan
Member
 
Registered: Sep 2003
Location: Melbourne, Australia
Distribution: NetBSD 3.0.1, Slackware 10.1
Posts: 394

Rep: Reputation: 30
Simple Shell Script Help


Hi,

First time shell scripting, so I'm just trying to get by with man pages and the sticky in this forum.

This is the output of the following command:


Code:
VIC_DAS36 (root): /home/tsioper/status 2>/dev/null | grep CAL-SERVER2 | awk '{ print $5 }'
Serving
and this is the script I'm trying to create:


Code:
CAL-2=`/home/tsioper/status 2>/dev/null | grep CAL-SERVER2 | awk '{ print $5 }'` 
CAL-4=`/home/tsioper/status 2>/dev/null | grep CAL-SERVER4 | awk '{ print $5 }'`  
if [ '$CAL-2' = 'Stopped' ]
         then
                 echo CAL Server 2 has gone down and/or stopped serving! | mail -s "WARNING: CAL Server" fake@email.com
elif
if [ '$CAL-4' = 'Stopped' ]
         then
                 echo CAL Server 4 has gone down and/or stopped serving! | mail -s "WARNING: CAL Server" fake@email.com 
fi
Now what I want the script to do is e-mail me when the output of the command is 'Stopped'.

This is what I get when I try running it:


Code:
VIC_DAS36 (root): ./CAL-test ./CAL-test[7]: CAL-2=Serving:  not found. 
./CAL-test[8]: CAL-4=Serving:  not found. 
./CAL-test[10]: 0403-057 Syntax error at line 13 : `if' is not matched.
Any input is accreciated

-Kristijan

Last edited by Kristijan; 06-13-2005 at 07:07 PM.
 
Old 06-13-2005, 07:13 PM   #2
Kristijan
Member
 
Registered: Sep 2003
Location: Melbourne, Australia
Distribution: NetBSD 3.0.1, Slackware 10.1
Posts: 394

Original Poster
Rep: Reputation: 30
I've made a slight change to the script to use 2 if condition statements, then the single one.

It now reads like this:

Code:
CAL-2=`/home/tsioper/status 2>/dev/null | grep CAL-SERVER2 | awk '{ print $5 }'`
CAL-4=`/home/tsioper/status 2>/dev/null | grep CAL-SERVER4 | awk '{ print $5 }'`

if [ $CAL-2 = 'Stopped' ];
        then
                echo CAL Server 2 has gone down and/or stopped serving! | mail -s "WARNING: CAL Server" fake@email.com
fi
if [ $CAL-4 = 'Stopped' ];
        then
                echo CAL Server 4 has gone down and/or stopped serving! | mail -s "WARNING: CAL Server" fake@email.com
fi
When I run it, I now get the following error:

Code:
VIC_DAS36 (root): ./CAL-test
./CAL-test[7]: CAL-2=Serving:  not found.
./CAL-test[8]: CAL-4=Serving:  not found.
-Kristijan

Last edited by Kristijan; 06-13-2005 at 07:17 PM.
 
Old 06-13-2005, 08:52 PM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
I don't believe you can have a '-' in a variable name.

Try CAL_2 and CAL_4.
 
Old 06-13-2005, 09:13 PM   #4
Kristijan
Member
 
Registered: Sep 2003
Location: Melbourne, Australia
Distribution: NetBSD 3.0.1, Slackware 10.1
Posts: 394

Original Poster
Rep: Reputation: 30
Dark_Helmet,

The name of the variable seemed to be the problem. It seems that I can't have a - in the variable name. I have replaced it with an _ and it all works fine now.

Thanks for your help.

Cheers,
-Kristijan
 
  


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
simple shell script sharpie Programming 9 06-02-2004 11:47 PM
simple shell script Greg_courageous Programming 2 05-12-2004 04:34 PM
a simple shell script Warchief Programming 1 07-31-2003 05:01 AM
Very Simple Shell Script cli_man Linux - Software 5 04-24-2003 10:14 AM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM


All times are GMT -5. The time now is 04:00 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration