Cron job not running at specified time - cron

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.

Related

Add crontab job after at job is executed

I am pretty new to the VPS running on Linux 19.04.
I have already had a at job which will be executed on January 27 13:00:00 2020.
I am just wondering if there is any possible way to add a new crontab job after the at job is executed?
Let say I want to add a crontab job 0 0 * * * /usr/bin/pm2 restart Bot, which will restart the Bot running with pm2 at 00:00 every day.
If I want to manually add the crontab job is no problem, I just crontab -e and edit it in nano. But I want it to automatically add the crontab job after the at job is executed, or after 1 minute of at job is executed.

running a script in crontab

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

Cron Job not working in Linux environment

I've been running a shell script every minute between Monday and Friday between business hours, and thought it was running fine, as I can see it when I use the "crontab -l" command. The script calls a piece of Java code which checks certain conditions in a postgresql table, and if those conditions are met, it writes out to another table. The script is in the following directory on our Linux server.
/var/lib/tomcat7/webapps/sh
So lets say it is called "test.sh", should my cronjob look like this this:
* 08-18 * * 1-5 /var/lib/tomcat7/webapps/sh/test.sh
ie, it should run every minute of every day from Monday to Friday between 8 am and 18:59 pm. I just tried testing it by adding dummy data to the postgresql table so that the other table should have been written to and nothing happened. However when i ran ./test.sh manually from the command line it worked fine. The issue seems to be with my cron. If I type:
grep CRON /var/log/syslog
I can see that it has run every minute today. The output looks like this
Nov 25 12:38:01 webserver CRON[11868]: (ubuntu) CMD (/var/lib/tomcat7/webapps/sh/test.sh)
Nov 25 12:39:01 webserver CRON[11888]: (ubuntu) CMD (/var/lib/tomcat7/webapps/sh/test.sh)
Nov 25 12:40:01 webserver CRON[11953]: (ubuntu) CMD (/var/lib/tomcat7/webapps/sh/test.sh)
Nov 25 12:41:01 webserver CRON[11953]: (ubuntu) CMD (/var/lib/tomcat7/webapps/sh/test.sh)
Nov 25 12:42:01 webserver CRON[11985]: (ubuntu) CMD (/var/lib/tomcat7/webapps/sh/test.sh)
etc.. However after I altered the data in the postgresql table this did not seem to have any effect. It's as if the script isn't actually running. Although it runs perfectly when I run it manually from the command line.
Has anyone ever experienced this sort of thing with cron jobs, or have any advice as to why this might be happening? Any assistance would be appreciated. Thanks in advance!
Your working directory is not /var/lib/tomcat7/webapps/sh but / when you launch your script with /var/lib/tomcat7/webapps/sh/test.sh
You can get the current working directory with pwd command or get the script location (see this post and then :
cd $SCRIPTPATH
cd ../java/JProject/sr
OR
change relative path ../java/JProject/src with the absolute path

Can't get 'at' to run a script under linux

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.

Run a script at specified time in linux

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

Resources