LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 07-10-2009, 09:12 AM   #1
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,272

Rep: Reputation: 148Reputation: 148
looping startup script


This is my sample startup script for Apache, why this looping when i am starting this script
#/etc/init.d/app start

whats wrong on this script?
pleas help me to avoid looping

Code:
#!/bin/bash
#
APP=/etc/rc.d/init.d/httpd.system

start(){
#
if [ `ps ax | egrep -c "ctdaemon"` -le 1 ]
then 
 echo "Starting ctdaemon"
 ctdaemon
 while [ `ps ax | egrep -c "ctdaemon"` -le 1 ]
  do 
   #
   sleep 1
  done
else
  echo "ctdeamon already running"
fi
echo "Finish"

#
#Starting Appache
if [ `ps -ef|egrep -i "http|apache"|wc -l` -le 1 ]
then
  $APP start
  echo "Starting Appache Server"
  while [ `ps -ef|egrep -i "http|apache"|wc -l` -le 1 ]
   do
    #    
	  sleep 1
   done  
else
  echo "Apache is Already Running"         
fi
echo "Finished"
return 0
}
#


stop(){
    #killall -9 heart
    $APP  stop
    ERROR=2
}
status(){
    $ISUP  status
   
ERROR=$?
}

ARGV="$@"

case $ARGV in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    #$LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } '
    stop
    /opt/nms/bin/oamsys
    start
    ;;
softrestart)
    #$LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } '
    stop
    start
    ;;
status)
    status
    ;;
*)
    echo "Usage: start|stop|restart|status|restart|softrestart"
    ERROR=$?
esac

exit $ERROR


Thanks
 
Old 07-10-2009, 12:51 PM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
Which part is looping?

If it's trying to start over and over, try replacing return 0 with exit 0

If it get's stuck in the:
Code:
while [ `ps ax | egrep -c "ctdaemon"` -le 1 ]
do 
   #
   sleep 1
done
section, then try printing out the output of ps ax|egrep "ctdaemon" to see if it is returning what you are expecting.

Remeber -le is less than or equal to
 
Old 07-10-2009, 02:23 PM   #3
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,272

Original Poster
Rep: Reputation: 148Reputation: 148
Sorry, I would like to make my question more clear. By using this script i am starting two services ctdaemon and httpd if these two services started and running already, when i am executing this script (/etc/init.d/app start) again it should print

Code:
ctdaemon already running
finished
apache already running 
finished
and then this script should terminate but it wont happen like that its continuing infinity time and print this messages again and again(it means looping)
 
Old 07-10-2009, 03:25 PM   #4
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
Out of curiousity, please modify one section of your code:

Code:
if [ `ps -ef|egrep -i "http|apache"|wc -l` -le 1 ]
then
  echo "about to run: $APP start"
  exit 1
  $APP start
  echo "Starting Appache Server"
  while [ `ps -ef|egrep -i "http|apache"|wc -l` -le 1 ]
   do
    #    
	  sleep 1
   done  
else
  echo "Apache is Already Running"         
fi

Last edited by Disillusionist; 07-10-2009 at 03:29 PM.
 
  


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
Problem with shell script looping... ech310n Programming 1 10-19-2008 04:06 PM
Looping in script help needed ZAMO Linux - General 5 08-18-2008 06:17 AM
Looping a script Keentolearn Linux - Newbie 4 01-30-2007 04:54 PM
Looping a bash script SoulGrind Linux - Newbie 5 09-22-2006 07:03 PM
shell script looping ust Linux - General 2 01-19-2005 05:05 AM


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