cron job

chsoh
chsoh used Ask the Experts™
on
I have a reschedule daily cron job process to purge some database record at the end of the day. The process worked fine with more than 6 month.

Recently, the cron job event has been missing and never reschedule. why ?

For more information, the owner of the job has a right access mode & has a never expired password.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Is the job still define in the crontab ?

Do you have a log file for the job?

Have a look at your crontab and log file, and try to run the script in command line see what happen.
Top Expert 2007

Commented:
Have a look in /var/cron/log to see the status of the job.

Author

Commented:
Need to know if the following line mean the server is restarted ?

I have a cron job at 3am but server restarted at 3.01am




> userXXX 2993 a Tue Nov 12 03:00:00 2002
! SIGTERM Tue Nov 12 03:01:39 2002
! ******* CRON ABORTED ******** Tue Nov 12 03:01:39 2002
! *** cron started ***   pid = 182 Tue Nov 12 03:03:43 2002
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Author

Commented:
Need to know if the following line mean the server is restarted ?

I have a cron job at 3am but server restarted at 3.01am




> userXXX 2993 a Tue Nov 12 03:00:00 2002
! SIGTERM Tue Nov 12 03:01:39 2002
! ******* CRON ABORTED ******** Tue Nov 12 03:01:39 2002
! *** cron started ***   pid = 182 Tue Nov 12 03:03:43 2002
Have you/or someone installed any new software or patches on the systems in the last few months ? (I mean from the time the cron job stop working).

Have you try to run the script in the command line to verify if it still work ?

Try to change the starting time to 3.05am to see what happen.
Top Expert 2007

Commented:
Doing a 'who -b' or uptime will tell you when the server was last rebooted.

Do you have some other cronjob that runs around that time and does a reboot?
I just wonder why do you guys want to reboot a UNIX box every day.

I keep all my boxes running unless there is a power outage, or OS update required a reboot.
can you do an crontab -l and paste it also let us see your /var/cron/log file, also check to see if there is any mail for the user who runs the cron job, and also paste that here, the more information we have the better.
Anything new ?

Author

Commented:
The news : Find out the missing job is handle by <at> command.

if the job takes minimum 20 minutes to complete, what happen if we restart the server.

will <at> command re-schedule it ?

Anyone please simulate for me because I am not allow to restart the server.

1) <at> schedule a daily job and will take apprx 20 minutes to complete
2) When the job start, shutdown system immediately
3) bootup system
4) check the <atq>

When the system shultdown, the "at" or "cron" job will get killed, after the system is reboot, the job miss out the starting time, it will not run it for the same day, eg if you schedule a job at 3.00am, and your system reboot at 3.05, how can you get the time back to 3.00am for the same day. My advise is that avoid to run any cron job when the system is about to shultdown. Schedule the job start at a different time.



Author

Commented:
ok, nevermind if I miss out today 3am job.
but what happen to the next day process ? will system trigger my process again at 3am tomorrow?

actually my 3am daily job is to purge the old records from database. eg
DELETE from tableXYZ
where date < today.

I dont have a problem if the system trigger my program again for tomorrow 3am. The main problem now is the job missing FOREVER and never reshedule again.

why.

X-file.

I don't know if your system is rebooting at 3.00am everyday? If not to can put the job in your crontab. Let's say to want to run the job as user fred, put the following in the crontab (root)

0 3 * * * su - fred -c "/path-to/yourscript"  >/dev/null 2>&1

it will run, for 3.00am everyday if the system is not rebooting !

If you know your system is always reboot at 3.05, start at 3.30am:

30 3 * * * su - fred -c "/path-to/yourscript"  >/dev/null 2>&1

If your script has args, just put them inside the ""

eg:

0 3 * * * su - fred -c "/path-to/yourscript arg1 arg2 "  >/dev/null 2>&1



Author

Commented:
ok, nevermind if I miss out today 3am job.
but what happen to the next day process ? will system trigger my process again at 3am tomorrow?

actually my 3am daily job is to purge the old records from database. eg
DELETE from tableXYZ
where date < today.

I dont have a problem if the system trigger my program again for tomorrow 3am. The main problem now is the job missing FOREVER and never reshedule again.

why.

X-file.

Author

Commented:
my system will reboot 5am everyday.

I not sure what is the cause to manually reboot the system for that day. What I wonder now is why the system reboot before my program finished and cause my batch never exist in the batch.
(my tomorrow's job never exist in <atq> anymore)

I have to run <at> command to add in the daily process again.


Ask you sys adm why he want to reboot the system every day?

If you don't want to run "at" dailly, ask your sys adm to put it in the crontab to make it automatically doing the job for you. change the starting time to 5.30am if the system reboot at 5.00am.

Good luck

Author

Commented:
hi yuzh,

This is not an operational error.

Anyway, You know what is the differences between <crontab -e> and <at> command to queue the job ?

Top Expert 2007

Commented:
Scheduling jobs via 'at' differs from cronjobs as it will use your current environment.

I a cronjob, you must make sure you set all the additional paths, environment variables explicity.
Hi Tintin,

   Did you read my previous comments( and example)

 eg:

0 3 * * * su - fred -c "/path-to/yourscript arg1 arg2 "  >/dev/null 2>&1


   su - fred -c "command"
   means what? run the "command" use user "fred"'s Environment settings !




Top Expert 2007

Commented:
Hi yuzh.

Yes I did read your previous comments.  I was responding to chsoh's questions about the difference between 'at' and cronjobs.

Author

Commented:
can we schedule the job like
Run script <abc.sh> Daily 1pm, from month January to June only ??
Yes, you can put the following in your crontab:

0 13 * 1,2,3,4,5,6 * /path-to/abc.sh >/dev/null 2>&1

if you want to use user "fred" Env, it should looks like:

0 13 * 1,2,3,4,5,6 * su - fred -c /path-to/abc.sh >/dev/null 2>&1

Author

Commented:
how about <at> command ?
Top Expert 2007

Commented:
If you want to do the equivalent as an 'at' job, then you are going to have to schedule 180 separate 'at' jobs.  I know which one I'd rather type in.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial