#!/bin/ksh
file=`uname -n`
> /sunmast/projects/oasis/COREDEV/Dss$file.log
> /tmp/output_sss
today=`date`
varb=`ps -ef | grep java | grep sss | grep -v grep | wc -l`
if [ "$varb" -ne 1 ]
then
echo "FAILED : SSS processes down, Recycling SSS " >> /sunmast/projects/oasis/COREDEV/Dss$file.log
sudo /etc/init.d/init.sss start >> /tmp/output_sss
else
echo "SSS process is running successfully on `uname -n` on $today " >> /sunmast/projects/oasis/COREDEV/Dss$file.log
fi
MEMSIZE=`ps -e -o vsz,args | grep /amex/dss/sss/java | grep -v grep | cut -d' ' -f1`
echo " Memory usage by dss java client in kilobytes is $MEMSIZE on $today " >> /sunmast/projects/oasis/COREDEV/Dss$file.log
when i am manully running this script sudo command inside the script is working,But when the cron is executing the sudo command is not working inside the script.
Could anyone let me know what could be the possible reason.
I have checked that the cron is executing as other command are running except the sudo command.
It's probably got something to do with the way you have sudo setup to handle passwords. There are a variety of options:
sudo will always ask for a password.
sudo will only ask the first time it's run
sudo will require no password
I'm willing to bet that your script works in your shell because sudo is set to only prompt for a password the first time. When cron calls the script, it is probably hanging waiting on a password to be entered.
I'd look at your /etc/sudoers file to see how you're setup.
Or, you could just put this job into the root crontab and not worry about sudo at all.
Well, if you have access to sudo as root, you can modify the sudoers file:
sudo visudo
Or, like I said, you can just modify the root crontab:
sudo crontab -e
If you don't have access to the root account and sudo is not working for you, then you will not be able to run root commands until someone with proper privileges gives you access.