How to detect and fix why crontab job is not executed?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to detect and fix why crontab job is not executed?
# 8  
Old 03-06-2019
I know it is unlikely, but has anyone checked whether or not the server is running at 6am on the day(s) when the cron job doesn't run? If there is some kind of daily maintenance operation that takes the server out of normal multi-user mode during that timeframe, cron jobs that were missed while not in multi-user mode will not be started if the system comes back up to normal multi-user mode after the job's scheduled start time.
This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 03-06-2019
Quote:
Originally Posted by Don Cragun
I know it is unlikely, but has anyone checked whether or not the server is running at 6am on the day(s) when the cron job doesn't run? If there is some kind of daily maintenance operation that takes the server out of normal multi-user mode during that timeframe, cron jobs that were missed while not in multi-user mode will not be started if the system comes back up to normal multi-user mode after the job's scheduled start time.
Hi Don,

Thanks for your answer.

For now with the help of bukuni and RudiC I've set the cron in this way

Code:
  # crontab -l
0 6 * * * /path/to/scripts/script1.sh > /root/CronLog/cronlog.log 2> /root/CronLog/cronlog.err

The issue is that the cron job has failed every day of the week.

Do you know how to check if the source server was running a maintenance operation or something else when the cron job failed?

The source server model/version is

SunOS Generic_118833-22 sun4u sparc SUNW,Sun-Fire-V245

Thanks
# 10  
Old 03-06-2019
Did you add the set -vx to the script so it prints useful info?
For the server maintenance, you check the server system logs. You could also search for the relevant cron entries there.
# 11  
Old 03-06-2019
You have got Solaris. (BTW a very old Solaris 10, certainly never updated.)
Solaris /usr/bin/date has no -d option. The trailing -d is ignored! (An initial -d would give an error).
Either you have got GNU date installed, then please add the path to it, usually /usr/local/bin/date or /usr/sfw/bin/date or /opt/csw/bin/date
Or install GNU date.
Or try the TZ trick:
Code:
dyear=`TZ=$TZ+24 /usr/bin/date +'%Y'`
dmonth=`TZ=$TZ+24 /usr/bin/date +'%b'`
ddate=`TZ=$TZ+24 /usr/bin/date +%Y-%m-%d`

# 12  
Old 03-06-2019
Quote:
Originally Posted by RudiC
Did you add the set -vx to the script so it prints useful info?
For the server maintenance, you check the server system logs. You could also search for the relevant cron entries there.
Hi RudyC. Yes, I've added set -vx. So I'll need to check by tommorow what appears in those logs. Thanks for the help.

--- Post updated at 02:41 PM ---

Quote:
Originally Posted by MadeInGermany
You have got Solaris. (BTW a very old Solaris 10, certainly never updated.)
Solaris /usr/bin/date has no -d option. The trailing -d is ignored! (An initial -d would give an error).
Either you have got GNU date installed, then please add the path to it, usually /usr/local/bin/date or /usr/sfw/bin/date or /opt/csw/bin/date
Or install GNU date.
Or try the TZ trick:
Code:
dyear=`TZ=$TZ+24 /usr/bin/date +'%Y'`
dmonth=`TZ=$TZ+24 /usr/bin/date +'%b'`
ddate=`TZ=$TZ+24 /usr/bin/date +%Y-%m-%d`

Thanks for your suggestions, but since I get the date, year, month in destination server (CentOS) where the cron job is defined, then I don't have issues with date command.

The question about SunOS was more oriented how to know, if possible, if it runs some maintenance operation in a timeframe that includes the hour when the cron is configured on CentOS server (04:00 or 06:00 am).

If not I'll wait tommorow if something appears in log.

Thanks again.
# 13  
Old 03-06-2019
I don't remember the name of the log file that would contain the information about when the system changes states, but there has to be one. And, as has already been stated, look for cron's log file as well.

A quick and simple check would be to see what output you get from the command:
Code:
uptime

when run on that server. If it says the system has been up longer than when your last 6am cron job was skipped, that isn't your problem.
# 14  
Old 03-06-2019
Quote:
Originally Posted by Don Cragun
I don't remember the name of the log file that would contain the information about when the system changes states, but there has to be one. And, as has already been stated, look for cron's log file as well.

A quick and simple check would be to see what output you get from the command:
Code:
uptime

when run on that server. If it says the system has been up longer than when your last 6am cron job was skipped, that isn't your problem.
Thanks for your answer Don.

On SunOS server where I copy the files from the uptime command gives this output.

Code:
# uptime
  4:28pm  up 839 day(s),  5:42,  1 user,  load average: 0.08, 0.07, 0.07

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Detect changes to crontab

Dear All, My server is running crontabs of 4 different users. I want to develop a script that whenever a particular change occurs in a crontab , it is detected and the particular change is noted into a file. Kindly let me know of suggestions on how it can be achieved. My algo would be: ... (1 Reply)
Discussion started by: Junaid Subhani
1 Replies

2. UNIX for Dummies Questions & Answers

Cron job executed at wrong time

Dear *nix users. I'm on Mac OS 10.6 / Terminal and try to use crontab to schedule two scripts every 30 minutes and every 41 minutes. I followed the man instructions and created / installed a crontab file for the current user:crontab -e with the following content */30 * * * *... (4 Replies)
Discussion started by: moxnos
4 Replies

3. Shell Programming and Scripting

crontab job not executed with variables

Hi, I am trying to execute a script (for once) during the booting time in Ubuntu system. However, the result is only showing the strings without without the variables. Here is the script: MgrIp=$(ec2-describe-instances --filter tag:Name=Mgr --filter instance-state-name=running | egrep... (4 Replies)
Discussion started by: turki_00
4 Replies

4. Shell Programming and Scripting

Users who desire to have their .profile executed must explicitly do so in the crontab entry. Why?

The .profile file should be read when the user logs in. So, there should be no need to execute .profile file again in a cron job (since the cron job is run after the user logs in). Doesn't the cron require login from the user. Then, from where does the cron execute? Please help!! (1 Reply)
Discussion started by: thulasidharan2k
1 Replies

5. UNIX and Linux Applications

Log files to view job executed in Autosys -- Help ASAP

Hi all, I really need your help ASAP on this. Below is the description of my problem and a sketch of Autosys Job Activity Console ++++++++++++++++++++++++++++++++ File View Options +++++++++++++++++++++++++++++++ Job Name Description Status Command Machine... (1 Reply)
Discussion started by: sakal_woman
1 Replies

6. Shell Programming and Scripting

Script errors out only when its executed via job

I wrote a script to shutdown the oracle database. The script works fine when I manually run the script. However, when i schedule a job, i get the following error. Shutting Down cmismart .................... ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist SVR4... (6 Replies)
Discussion started by: mrx1350
6 Replies

7. Shell Programming and Scripting

Routine doesn't give output when executed in crontab

I have a script running in the crontab that gets data from a database every hour. Now I would like to execute a fortran routine to process the data in some way, after getting it and saving it locally. I have added the following commands to my script: set convert =... (1 Reply)
Discussion started by: SharkM
1 Replies

8. Shell Programming and Scripting

bash scripting cannot executed in crontab

hi guys, i have a problem. a week ago i made a successful crontab that execute bash scripting daily, it worked well but now, it doesn't work at all, in the mail i have: " /home/jimmy/cha/scripts/cekpderr produced the following output: lagi jalan /home/jimmy/cha/scripts/cekpderr:... (6 Replies)
Discussion started by: jimmbp
6 Replies

9. Shell Programming and Scripting

Shell script doesn't get executed using crontab

I have the following crontab entry to run a shell script for every 30 minutes of every day: 30 * * * * $HOME/main.sh > $HOME/main.log 2>$HOME/error.log after I created the crontab file I have also done: $crontab my_crontab I also check to make sure it exists, by using the following... (11 Replies)
Discussion started by: radhika
11 Replies

10. Shell Programming and Scripting

ant not being executed as cron job

i have a script that uses an ant build.xml and its targets to pull a project from a cvs server, attempt to build the project, and then email me the results. When I run the script (either @ CLI or as a cron job) while I am logged in, everything works fine. However, if the script is set up to run... (5 Replies)
Discussion started by: kingfinny
5 Replies
Login or Register to Ask a Question