Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

command/script execution from script 2

Status
Not open for further replies.

dwcasey

MIS
Oct 31, 2002
179
US
Running a do:while loop to montior for a process in memory and within
that loop, I do a condition check for a process...if it comes back
missing, if PROC = "" then echo to log file that it's down and execute
a restart.

For my restart, I've tried to actually start it as root with su -c
"/home/user/run.sh" and I've tried to embed the su -c command execution
within a script and call that script.

Problem is, when I kill the process to be monitored, it is able to see
that it's down and it will run the startMileage script, but it never
restarts my process and I just see sh /root/old/startMileage stuck
running when I do a ps for it. So, it starts, but it never finishes??

Anyway, if I run the startMileage script manually, it works fine.

What is best way to execute a script/command from within that if:then
loop?

##############################################################################
LOGDIR="/usr/local/logs"
LOGFILE="$LOGDIR/CheckMileage.log"

MILE_DOWN="The Mileage process is not active on `hostname` : `date`"
echo "`date` : CheckMileage started..." >> $LOGFILE
while :
do
sleep 120
echo "******************************************" >>
$LOGFILE
echo "\t\t`date`" >>
$LOGFILE
echo "\nMileage status--" >>
$LOGFILE
ps -ef | grep "MileageCalculator" | grep -v grep >>
$LOGFILE
MILEAPP=`ps -ef | grep "MileageCalculator" | grep -v grep`
if [ "$MILEAPP" = "" ]
then
echo $MILE_DOWN >>
$LOGFILE
echo `date` >>
$LOGFILE
echo "Restarting Mileage and Notifying System
Administration....." >> $LOGFILE
echo "Sleeping 10 before attempt to restart
MileageCalculator" >> $LOGFILE
echo "Running: /root/old/startMileage" >> $LOGFILE
sh /root/old/startMileage

fi
done
return 1
 
The problem is more likely to be within the startMileage script, can you post that?

Annihilannic.
 
Sure thing...only I though might be wrong is there is no #!/bin/ksh magic at the top.

##############################################################################
LOGDIR="/usr/local/logs"
LOGFILE="$LOGDIR/startMileage.log"

su - pacemile "-c /home/pacemile/run" >> $LOGFILE
exit
 
The quotes need to be around the command only, i.e. not including the "-c". You may also need to add a "&" to make it run in the background, otherwise the calling script will wait for it to complete (it's possible that this is in the 'run' file already, if that is a script).

[tt]su - pacemile "-c /home/pacemile/run" >> $LOGFILE &[/tt]

Annihilannic.
 
Oops! Copied it but didn't correct....

[tt]su - pacemile -c "/home/pacemile/run" >> $LOGFILE &[/tt]

Annihilannic.
 
I am running this script as root, so no pass required. But yes, sudo would be a good use in that case.
 
By the way, the lack of #!/bin/ksh magic is irrelevant because you are running it using sh scriptname, which means you are forcing it to be interpreted using sh.

Annihilannic.
 
ok, that seems to have fixed it. But funny thing now. Here is the "run" script that is being called in that su -pacemile -c statement:

mv nohup.out nohup.out.`date +%m%d%I%M`
nohup java -Druntime.environment=TEST com.mileage.MileageCalculator &

But, since this is being called from the root script in /home/old, it's placing the nohup.out file there and not in /home/pacemile.

Any thoughts on how to get the nohup.out file back in /home/pacemile?

 
Any thoughts on how to get the nohup.out file back in /home/pacemile?

Has the filename to be nohup.out? You are renaming it anyways.

What about output redirection, something like this:
nohup java -Druntime.environment=TEST com.mileage.MileageCalculator > /path/to/a/filename/of/your/choice 2>&1 &
(You may see 2 lines here, but it should be on 1 line)

hope this helps
 
Hoinz, done deal. thanks for the tip, I should have know to do that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top