Script works perfectly fine when run manually from terminal. It's just not executing by cron.
Also I had to create/edit the entry in
~> ls /var/spool/cron/crontabs/bender
-rw-r--r-- 1 root root 121 Oct 28 00:16 /var/spool/cron/crontabs/bender
because when i do a crontab -e
it seems to act wierd. When I do crontab -e
it automatically enters a # on a new line, then if i try to add a new line it gives me a ? and doesnt seem to do anything or recognize any commands.
that's 'ed' you are running there. If you don't much like it (can't say I blame you), try setting the EDITOR environment variable to your favourite editor.
In my case, that would be:
EDITOR=vi
export EDITOR
crontab -e
---------- Post updated at 08:11 PM ---------- Previous update was at 08:09 PM ----------
Oh and btw, to quit out of ed, the command is 'q' (no ':' symbol in front)
Hmm, editing then saving should have activated to correctly... I'll read a little more then...
---------- Post updated at 08:19 PM ---------- Previous update was at 08:16 PM ----------
Is there any error in your cron log file? Does it show it executing?
Generally a cron job problem is caused by the environment being wrong in the script - things like your path etc are not set by cron, so something that works from your commandline might not from cron.
Have you checked the user's email? Cron sends an email containing stdout and stderr if the script produces any output.
---------- Post updated at 02:24 AM ---------- Previous update was at 02:21 AM ----------
Ok, it is working now.
After changing the editor to vi like you said, then I edited the crontab, saved, edited it back to normal and saved it again. Now it is working.
But to your other question, I do not have a cron log (would like to turn it on) and when it started working, it sent me an email to my user, however when it was not working, it sent nothing.
The cron log will be in there.
(from memory) try the following file: /var/cron/log
It shows start and finish of each cron job and indicates if any fatal errors occurred.
Before you used crontab to edit it, cron didn't know to reread your /var/spool/cron/crontabs/bender file again - a restart of cron (or a reboot) probably would have done the trick too, or it could have happily replaced your crontab with what it had in memory - YMMV
Cron isnt at fault here, the script is. Have you remembered that cron does not read profiles and does not have any user environmental settings ?? Any script that runs should assume this and define any variabvles, home directories. Ive just had a similar problem with a DBA who wrote a few scripts and nothing worked. "Cron is broken" was his loud cry accross the room.
Well, turns out his script didnt set any variables or paths so commands werent found and the script never ran.
What I suggest you do is have a play, run the script in verbose mode :-
#!/bin/ksh -v or -x
,
Then re-direct the output of the file, within the script, to a file