duficy
asked on
scripts runs correctly on command line but not as cronjob
The following script will run completely from a command prompt. However, I have a problem when running it as a cronjob. The job is executed, since I get the email however, "/etc/init.d/radiator restart > /dev/null 2>&1" is not run. I'm using debian 2.2, I tried adding -u root without success.
>>>>>>>>>>>>>>>>>>>>>>>>>> .
#!/bin/sh
HOSTNAME=`hostname`
ADMIN="emergency@cshore.co m"
/bin/ps axwwww | grep radiusd | grep -v "grep" > /dev/null 2>&1
if [ $? -eq 0 ]; then
:
else
/etc/init.d/radiator restart > /dev/null 2>&1
echo "Radius restarted on Mozart" | Mail -s "Radius for ${HOSTNAME} rest
arted!" ${ADMIN}
fi
>>>>>>>>>>>>>>>>>>>>>>>>>>
#!/bin/sh
HOSTNAME=`hostname`
ADMIN="emergency@cshore.co
/bin/ps axwwww | grep radiusd | grep -v "grep" > /dev/null 2>&1
if [ $? -eq 0 ]; then
:
else
/etc/init.d/radiator restart > /dev/null 2>&1
echo "Radius restarted on Mozart" | Mail -s "Radius for ${HOSTNAME} rest
arted!" ${ADMIN}
fi
Did you try 'start'? If it's not running, then 'restart' may not apply.
ASKER
>>Did you try 'start'? If it's not running, hen 'restart' may not apply.
Yes. I have doubled points to 200.
Yes. I have doubled points to 200.
Then the only thing I can think of is that there's something missing from the PATH or some other environment problem when it runs from cron.
ASKER
I have specified the path
"/etc/init.d/radiator restart > /dev/null 2>&1"
"/etc/init.d/radiator restart > /dev/null 2>&1"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
would it be possible if you could post the whole script? Also under which account have you installed the cronjob and which account did you test it?
first, take out the > /dev/null 2>&1 so that you can see the errors that are actually occuring... then try changing Mail to mail (or better yet, /bin/mail).
Hi.
Since I don't use debian I'm not sure about this, but the line "/bin/ps axwwww | grep radiusd | grep -v "grep" > /dev/null 2>&1"
Shouldn't it be "/bin/ps -axwwww | grep radiusd | grep -v "grep" > /dev/null 2>&1".
It looks like bsd-ps and I don't believe that the third "w" does anything.
Hope this helps.
Since I don't use debian I'm not sure about this, but the line "/bin/ps axwwww | grep radiusd | grep -v "grep" > /dev/null 2>&1"
Shouldn't it be "/bin/ps -axwwww | grep radiusd | grep -v "grep" > /dev/null 2>&1".
It looks like bsd-ps and I don't believe that the third "w" does anything.
Hope this helps.
does /etc/profile or $HOME/.profile of the user running this script contain any tty-related commands, like stty?
Also check /etc/init.d/radiator or such bogus commands.
If the cron fails to execute a command, it sends mail too root, what does this mail tell you?
Also check /etc/init.d/radiator or such bogus commands.
If the cron fails to execute a command, it sends mail too root, what does this mail tell you?
Make sure that:
1. If you point the cronttab file to the right script.
2. Any file been used in your script should not be a symbol link. If so, find the origin file and use that name.
3. Is your crond daemon program worked well? :)
Good Luck:)
1. If you point the cronttab file to the right script.
2. Any file been used in your script should not be a symbol link. If so, find the origin file and use that name.
3. Is your crond daemon program worked well? :)
Good Luck:)
> Any file been used in your script should not be a symbol link.
Why that?
Why that?
In Redhat, you can put the script in directory:/etc/cron.daily( hourly | weekly) then, the daemon program will run it after very xxxx times, in these directorys if you creat a script by command "ln -s" it will not be run at all.
.. that's not a cron behaviour, but one of the script called by cron (or at) calling etc/cron.{daily,hourly,wee kly}
Not sure if you have the "service" command on debian, but if so, you could try "service radiator restart" instead.
Not sure if you have done this but specify the full path to all the commands;
eg/
/bin/ps axwwww | /bin/grep radiusd | /bin/grep -v "grep" > /dev/null 2>&1
You will have to find the correct paths for your system and may have to include the paths for the mail proggy as well.
jools
eg/
/bin/ps axwwww | /bin/grep radiusd | /bin/grep -v "grep" > /dev/null 2>&1
You will have to find the correct paths for your system and may have to include the paths for the mail proggy as well.
jools
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area to:
Accept chris_calabrese's answer
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
majorwoo
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area to:
Accept chris_calabrese's answer
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
majorwoo
EE Cleanup Volunteer
per recommendation
SpideyMod
Community Support Moderator @Experts Exchange
SpideyMod
Community Support Moderator @Experts Exchange