LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   cron job <defunct> error? (https://www.linuxquestions.org/questions/slackware-14/cron-job-defunct-error-137158/)

existo 01-21-2004 01:33 PM

cron job <defunct> error?
 
Fairly new to using cron to automate tasks and have come across an error <defunct> as job is run... Some details:

Cron job line

*/2 * * * 1-5 sh /path/to/script.sh >> /tmp/dhcp_log 2>&1

Contents of script.sh

today="date +%m.%d.%Y"
if HOME=/path/to
then
if test -f /path/to/restart
then
if test -f /path/to/dhcpd.conf
then
$today
echo "----------------------------------------------------------------"
echo "File was found. Attempting to restart the DHCP Service."
echo "Please wait..."
if killall -HUP dhcpd
then
echo "DHCP Service has been stopped."
/usr/sbin/dhcpd -cf /path/to/dhcpd.conf
echo "DHCP Service was started successfully."
echo "/path/to/dhcpd.conf"
rm /path/to/restart
if test -f /path/to/restart
then
rm -dfr /path/to/restart
echo "Removed temporary file used to flag mandatory restart"
else
echo "No file found to flag mandatory restart"
fi
else
echo "DHCP Service was started"
/usr/sbin/dhcpd -cf /path/to/dhcpd.conf
rm /path/to/restart
echo "----------------------------------------------------------------"
fi
else
echo "File was not found"
fi
else
exit 0
fi
else
exit 0
fi

If I run the script alone it works fine... however if I run it through cron this is the error I recieve using ps xaf

root 711 0.0 0.0 1484 324 ? S 2003 0:00 /usr/sbin/crond -l10
root 19825 0.0 0.0 1480 608 ? S 10:41 0:00 /usr/sbin/crond -L /tmp/crond
root 20127 0.0 0.0 0 0 ? Z 11:14 0:00 [crond] <defunct>
root 20128 0.0 0.0 0 0 ? Z 11:14 0:00 [crond] <defunct>

Now the contents of the error log I am running crond with...

unable to exec /usr/sbin/sendmail -t, user -oem, output to sink nullUSER root pid 20207 cmd sh /us\
r/local/www/dhcp/bin/dhcp.sh >> /tmp/dhcp_log 2>&1^M
unable to exec /usr/sbin/sendmail -t, user -oem, output to sink null

Permissions on shell script are here...

-rwxr-xr-t 1 root root 1340 Jan 21 11:13 dhcp.sh

If anyone knows why this is occuring please let me know... as you can see I am in no way trying to output the results of by script to an email... I need it logged to a file so I may view it later.

Thanks in advance.

jhorvath 01-21-2004 01:45 PM

according to the crond manpage , crond attempts to mail the results of the jobs using sendmail. so probably you need sendmail installed, unless you can turn that option off (try a google, there's no such option listed in manpage..)

--jeremy

existo 01-21-2004 01:49 PM

Re: <defunct>
 
Actually everything I have found says to use
command >> /tmp/filename 2>&1
which outputs to a file instead of an email message. I have a couple of cron jobs running this exact method and they all work, as a matter of fact if I run this command from a shell prompt it works...

sh /path/to/shell.sh >> /tmp/error 2>&1

weird huh? if cron runs it i get this error

unable to exec /usr/sbin/sendmail -t, user -oem, output to sink nullUSER root pid 20207 cmd sh /usr/local/www/dhcp/bin/dhcp.sh >> /tmp/dhcp_log 2>&1^M
unable to exec /usr/sbin/sendmail -t, user -oem, output to sink null

jhorvath 01-21-2004 01:56 PM

hmm...now i'm reading that if you redirect the output (which you have), it shouldn't be mailed.. (i'm not really big on cron jobs ;))

this line ::

*/2 * * * 1-5 sh /path/to/script.sh >> /tmp/dhcp_log 2>&1

should it not be 'without' the boldened text? i believe just the /path/to/script.sh is needed because it calls a shell to execute it on its own?

existo 01-21-2004 03:22 PM

Let me give that idea a try... I will be back in a minute

jhorvath 01-21-2004 03:24 PM

dont worry about it...has nothing to do with it..been trying everything to make this thing fail :) ,...and cannot seem to manage it ;)

these lines ...
root 711 0.0 0.0 1484 324 ? S 2003 0:00 /usr/sbin/crond -l10
root 19825 0.0 0.0 1480 608 ? S 10:41 0:00 /usr/sbin/crond -L /tmp/crond

...this has nothing to do with this problem , but you may not want two cron daemons running during go time..

try making some simple script that just echos HELLOOO or somethin...and run it 'exactly' the same way your trying to run the dhcp script..same permissions and file name (back the other one up),...just like it was the dhcp.sh file and see if you get the same results...

i even set up a cron job to run a simple script without redirecting output...it still didn't cry about sendmail...<?>

existo 01-21-2004 03:36 PM

Well I killed the cron daemon and restarted it then I modified the cron syntax to read as follows...

*/1 * * * * /path/to/script.sh &> /tmp/errors

Seems to be working fine now...

jhorvath 01-21-2004 03:39 PM

WIERD !!

mine was set as

*/1 * * * * sh /path/shit.sh >> /tmp/shit.txt 2>&1

and was working fine?? doesn't make sense to me, but, whatever works i guess ;)


All times are GMT -5. The time now is 12:59 AM.