Our environment is RHEL 5.7. I would like to know if one of the crontab entry in the crontab failes to execute ( even though the entry available in the crontab ), is it getting logged. If so where and which log file. I have gone through the /var/log/cron logfile. But it just show only the execution of the crontab entries,crontab edit start,stop etc such as
Feb 11 16:03:01 BGRIPD01 crond[3665]: (oracle) CMD (sh
/home/oracle/cronlogtest.sh > /home/oracle/cronlogtest.log 2>&1)
Feb 11 16:02:04 BGRIPD01 crontab[32690]: (oracle) REPLACE (oracle)
Feb 11 16:02:04 BGRIPD01 crontab[32690]: (oracle) END EDIT (oracle)
Feb 11 16:02:09 BGRIPD01 crontab[1033]: (oracle) LIST (oracle)
Feb 11 16:03:01 BGRIPD01 crond[7883]: (oracle) RELOAD (cron/oracle)
Is there any other option to get the failure results and reasons.
I knew that one of the other way is to append the crontab entry activity to a logfile like below
10 14 * * * sh /home/oracle/cronlogtest.sh > /home/oracle/cronlogtest.log 2>&1
But in my scenario I want a single logfile where only the crontab entry failures get logged. Is there any other logfile or other option to log the failures. Kindly help me in this.
Thanks
I believe you are asking too much from CRON.
I have each cron job writing to a log file. It writes begin/end and debug info. They could all write to the same file or not. In my case they write to their own file in a directory for cron logs. I also have some cron jobs which also write their status to a database table.
Once I had trouble understanding why a cron job failed to execute. Our sysadmin said CRON was calling it each day as I had asked. But it wasn't doing what it was supposed to do. After a bit of badgering the sysadmin worked with me on the problem. I had uploaded the cron job in dos format. CRON did what is was supposed to do. I needed to convert the cron job to unix format. I did and everything worked.
Related
I got some errors in my cron job and I don't know why. In my cron job is this:
and I got those errors when my cron job is trying to start my script but I don't understand Error: bad username error because mc is a valid user in my system and got the rights for the folder.
Errors:
Apr 2 21:34:55 Debian-78-wheezy-64-minimal /usr/sbin/cron[27104]: (CRON) INFO (pidfile fd = 3)
Apr 2 21:34:55 Debian-78-wheezy-64-minimal /usr/sbin/cron[27105]: (CRON) STARTUP (fork ok)
Apr 2 21:34:55 Debian-78-wheezy-64-minimal cron[27105]: Error: bad username; while reading /etc/crontab
Apr 2 21:34:55 Debian-78-wheezy-64-minimal /usr/sbin/cron[27105]: (*system*) ERROR (Syntax error, this crontab file will be ignored)
Apr 2 21:34:55 Debian-78-wheezy-64-minimal /usr/sbin/cron[27105]: (CRON) INFO (Skipping #reboot jobs -- not system startup)
You have probably corrupted your crontab file. Edit it with crontab -e and try to add an empty new line at the end.
I think the bad username it's complaining about is cd in the #reboot line.
A system crontab is like a user crontab except that you need to provide a username after the time and date fields and before the commands.
Normally there are 5 time and date fields, but they can be replaced by a single field #reboot (or #daily, #weekly, and several other options). You still need the username field.
Add a user name after #reboot (I don't know whether you want root, mc, or something else
(I'm not 100% sure of my interpretation; I haven't tried using # fields in a system crontab.)
Aside from that, it's generally a good idea to use your personal crontab, not /etc/crontab, for commands you want to run under your own account. Assuming your username is mc, you can create a file like this:
1 * * * * some_command
and then feed that file to the crontab command.
By putting personal commands in /etc/crontab, you risk messing up the rest of the file and possibly damaging the system as a whole. And you have to be root to edit /etc/crontab; don't use the root account for anything that doesn't require it.
I have a very simple script in my crontab that I want to run every day. It is located in /home:
-rwxr-xr-x 1 root root 40 Apr 15 08:01 kill_slony_stop_sql.sh
It has execute permission and here is the content:
#!/bin/bash
slon_kill;rcpostgresql stop
and here is the cron line for it to run daily:
56 12 * * * /home/kill_slony_stop_sql.sh
But it is not working for some reason. When I type /home/kill_slony_stop_sql.sh in the command line, it works good but it is not working in the crontab.
Any thoughts?
It is most likely a PATH issue. Have a look at Why is my crontab not running and be sure to set a PATH so that it can call your slon_kill command.
Also, add some debug to your cron
56 12 * * * /home/kill_slony_stop_sql.sh &>/tmp/errorcron.log
And also look at the logs; cron logs its actions via syslog, which (depending on your setup) often go to /var/log/cron or /var/log/syslog.
I had the same problem with a daily cron job, I used the #daily but this will run at 00:00 every day.
#daily /usr/local/bin/msa70_check.sh
was the cron tab line i added, below is the script i run.
#!/bin/bash
# msa70 disk check
/sbin/mdadm --detail /dev/md0 /dev/md1|
/bin/mailx -s"Disk check on server123 please check" person#domain.com
I also had to edit my script and add /sbin/ and /bin in front of mdadm and mailx for the cron job to run
My date command -
May 19 20:28:00
Crontab file -
ubuntu#ip:/etc/cron.daily$ crontab -l
24 20 19 5 1 /opt/sw/p3/scratch/test.py > /opt/sw/p3/scratch/test1.txt
Based on the above command and date, My job should have run at 20:24 on May 19 but I dont see any output in my test1.txt
test.py just prints a statement -
print "I will be run soon"
Why my crontab job did not run at that time?
If you are running this cron job on a remote server, please verify whether the server's timezone is same as your's. If not you can change the server default timezone and try setting the cron job again to a different date/time.
I am having problems getting the 'at' command to run a script file:
This one works fine:
[myid#els-e37620 init.d]$ at now + 2 min
at> echo "this is my test" | write myid >/dev/null 2>&1
at> <EOT>
job 20 at Thu Jan 30 17:26:00 2014
But nothing happens when I try to run my script with 'at':
[myid#els-e37620 init.d]$ at now + 2 min
at> ./users/myid/bashtest.sh
at> <EOT>
job 21 at Thu Jan 30 17:31:00 2014
As far as I have seen the job is added to the 'at' queue and removed after the designated time but nothing happens! Is it executed somewhere else?
Thanks very much
The at command is usually disabled due to possible security issues. In the old days, it was possible to set an at job, then go into the queue and change the script including the environment before the job started.
One of the things you need to look at are the at.allow and at.deny files. These are sometimes kept under the /etc directory, sometimes under /var and sometimes under /usr/lib/cron. You'll need to look in your at manpage to find the actual location. If there's an empty at.allow file, then you cannot run any at jobs.
Another thing you should look at the manpage of your atrun command. The atrun command is what executes the at jobs. On some systems, the atrun command must be setup in the root's crontab file. On Macs, it's run by the launchd daemon, and you must run the launchctl command to start the atrun process.
I have created scripts and now I want them to run automatically at specified time, how can I do that?
I am using Ubuntu and JAVA to write my scripts.
You can use crontab to do this in a specific time continuously.
To edit a crontab entries, Login as root user (su – root) and do crontab -e as shown below. By default this will edit the current logged-in users crontab.
root#dev-db# crontab -e
Scheduling a Job For a Specific Time
The basic usage of cron is to execute a job in a specific time as
shown below. This will execute the Full backup shell script
(full-backup) on 10th June 08:30 AM.
Please note that the time field uses 24 hours format. So, for 8 AM use 8, and for 8 PM use 20.
30 08 10 06 * /home/ramesh/full-backup
More example here, and the crontab utils can be found here