Find the answer to your Linux question:
Results 1 to 7 of 7
Red Hat 9 I have a process that frequently defuncts. I would like to write a script to stop it and start it at a set time everyday. To stop ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2004
    Posts
    4

    Simple scripting question from newbie


    Red Hat 9

    I have a process that frequently defuncts. I would like to write a script to stop it and start it at a set time everyday. To stop and start the process I used the following lines from the command line.
    /etc/rc.d/init.d/agent.init stop
    /etc/rc.d/init.d/agent.init start

    when I try to create a script that I could run from cron I get the following error.
    Usage: agent.be { start | stop }

    I have also tried the follwoing commands without success.
    killall agent.be
    ./etc/bkupexec/agent.be

    Here is a copy of the agent.init script
    Code:
    #!/bin/sh
    
    DESTDIR=/etc/bkupexec
    
    if [ ! -d $DESTDIR ]
    then			# Backup Exec Agent not installed
    	exit
    fi
    
    CMD="$1"
    
    case "$CMD" in
    'start')
    	if [ -x $DESTDIR/agent.be ]
    	then
    		$DESTDIR/agent.be -c $DESTDIR/agent.cfg 2>$DESTDIR/agent.log &
    	fi
    	;;
    'stop')
    	# stop the Agent daemons
            if [ -f /bin/grep ]
            then
    	   pid=`/bin/ps -e | /bin/grep agent.be | /bin/sed -e 's/^  *//' -e 's/ .*//'`
            else
    	   pid=`/usr/bin/ps -e | /usr/bin/grep agent.be | /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
            fi
    	if [ "${pid}" != "" ]
    	then
               if [ -f /bin/kill ]
               then
    		/bin/kill ${pid}
               else 
                    /usr/bin/kill ${pid}
               fi
    	fi
    	;;
    *)
    	echo "Usage: agent.be { start | stop }"
    	;;
    esac
    Thankyou for your help

    ***Mod Edit: Put code into code brackets. Please use BBCode to format your posts in the future.***

  2. #2
    Just Joined!
    Join Date
    Dec 2004
    Posts
    12
    Hi

    From my command line your script works well. Could you post the lines from your crontab which invoke the script ? It seems that your arguments may not be reaching the script.

    Spook

  3. #3
    Just Joined!
    Join Date
    Dec 2004
    Posts
    4
    OK, the crontab entry is

    0 16 * * * /etc/dansguardian/bkupexec_agent_restart

    this is just a file I created with the two lines

    /etc/rc.d/init.d/agent.init stop
    /etc/rc.d/init.d/agent.init start

    in it.

  4. #4
    Just Joined!
    Join Date
    Dec 2004
    Posts
    12
    Hmm, OK I had asumed that the code you posted was agent.be

    It seems like the agent.be script which you call in the start method of the case statement requires a start or stop parameter which you are not supplying:

    Code:
    $DESTDIR/agent.be -c $DESTDIR/agent.cfg 2>$DESTDIR/agent.log &
    I would also change the line
    Code:
    echo "Usage: agent.be { start | stop }"
    to read
    Code:
    echo "Usage: agent.init { start | stop }"
    so you can actually tell if the error is coming from agent.be or your script.

    Cheers

    Spook

  5. #5
    Just Joined!
    Join Date
    Dec 2004
    Posts
    4
    Alright, that worked. The script is successfully stopping and starting the process. Thank You very much!

  6. #6
    Just Joined!
    Join Date
    Dec 2004
    Posts
    4
    OK, I am a goober. Obviously the echoi would'nt have made a difference, un less it means something different than a windows/dos environment. For what ever reason this script is now working. I have changed nothing on the system since I first wrote in asking for help but it seems to really be working now. Thank you for all your help!!

  7. #7
    Just Joined!
    Join Date
    Dec 2004
    Posts
    12
    Hi

    You're welcome!

    I suggested changing the echo just so it was clear where the actual error message came from (the error generated by agent.init would have said agent.be)

    I'm glad you got things working. Isn't it a bummer when it just suddenly works and you cant see why it didn't in the first place

    Cheers
    Spook

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •