LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-10-2004, 04:08 AM   #1
akilles
Member
 
Registered: Sep 2004
Location: Vestfold, Norway
Distribution: Slackware
Posts: 139

Rep: Reputation: 15
BASH Scripting


Hi all.
I have been trying to write my very own monitor script a couple of days, and it's almost working... But no quite..
Here a cut-out from the script:
#!/bin/bash

DNS_STATUS=`ps aux |pgrep named`

if test $DNS_STATUS != ""
then
echo "DNS Service (named) running. OK"
elif test $DNS_STATUS = ""
then
echo "DNS Service (named) not running. Restarting"
named
fi

Anyone see anything wrong with this?
I'm not around my server now, so I can't post the error msgs, cause I can't remember then either.
Is this a good way to check if a service is running, or would you write it differently?

Hope someone can help me with this.

Best regards
Geir Andersen
 
Old 11-10-2004, 04:25 AM   #2
predator.hawk
Member
 
Registered: Aug 2004
Location: USA
Distribution: FreeBSD-5.4-STABLE
Posts: 252

Rep: Reputation: 30
Try this script instead, its a cleaned up version of that using /bin/sh (generic shell script).

#!/bin/sh
DNS_STATUS=`ps aux | pgrep named`
if [ "$DNS_STATUS" != ""]; then
echo "DNS Service (named) running. OK"
else
echo "DNS Service (named) not running. Restarting"
named
fi

(proper shell script format, vary portable). If that syntax is bash valid, they need to clean that syntax up (thank god i use zsh).

Last edited by predator.hawk; 11-10-2004 at 04:28 AM.
 
Old 11-10-2004, 04:51 AM   #3
akilles
Member
 
Registered: Sep 2004
Location: Vestfold, Norway
Distribution: Slackware
Posts: 139

Original Poster
Rep: Reputation: 15
Thanks for the reply.
I modified the reply to look like this:
#!/bin/sh
DNS_STATUS=`ps aux | pgrep bash`
if [ "$DNS_STATUS" != ""]; then
echo "BASH running. OK"
else
echo "BASH Not running."
fi

On the server I tested here, with the username I'm logged in as, bash is the only process I can test with. Running this script gives out:
./test.sh: [: 6448: unary operator expected

I'm at a loss.

-Geir
 
Old 11-10-2004, 05:07 AM   #4
akilles
Member
 
Registered: Sep 2004
Location: Vestfold, Norway
Distribution: Slackware
Posts: 139

Original Poster
Rep: Reputation: 15
SUCCESS:
This script works. (For testing purposes anyway)
#!/bin/bash

BASH_STATUS=`ps aux | pgrep bash`

if [[ "$BASH_STATUS" = "" ]]
then
echo "BASH Not Running"
else
echo "BASH Running Fine"
fi

Now all I have to do, is test the whole thing when I get home to my server.

-Geir
 
Old 11-10-2004, 05:10 AM   #5
akilles
Member
 
Registered: Sep 2004
Location: Vestfold, Norway
Distribution: Slackware
Posts: 139

Original Poster
Rep: Reputation: 15
Looks like something happened with that last post.
 
Old 11-10-2004, 07:26 PM   #6
predator.hawk
Member
 
Registered: Aug 2004
Location: USA
Distribution: FreeBSD-5.4-STABLE
Posts: 252

Rep: Reputation: 30
Bash Syntax Gives me gas <_<. Anyway, glad you got it working.
 
  


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 help (su ...) shwong Linux - General 1 11-02-2005 12:26 PM
Bash scripting pete1234 Programming 1 09-27-2005 01:48 AM
bash scripting vadon Linux - Newbie 6 05-10-2005 04:07 AM
need help with bash scripting rich2oo1 Programming 2 12-17-2003 12:50 PM
HELP with BASH scripting atwah Linux - Newbie 6 09-09-2003 01:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:22 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