Add crontab job after at job is executed - linux

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.

Related

I want the cron job to run the script weekly basis

I am trying to setup a cron job on a Ubuntu server. I want the cron job to run the script on weekly basis. Problem is - It should be a working day, If im mentioning it with time interval, it fails during weekoffs - Need an Schedular Exp which has to work weekly only on working days at office hours.(9am to 9pm)max.
Want to Execute the script every week #6 pm during the weekdays. It Can be Mon to Fri.
Step1
sudo apt-get install cron
systemctl status cron
Step2
Configure the cron job:
crontab -e
Select an editor of your choice
0 0 * * 0 /path/to/command
Syntax: minute hour day-of-month month day-of-week command.
Day-of-week goes from 0-6 where 0 is Sunday.
Save it.

Wait 60 Seconds to Run Cron Job After Reboot Then Run Job Every 10 Minutes

I have a script that I would like to run 60 seconds after initial system reboot and then every 10 minutes after that. I currently need two cron job listings to achieve this:
*/10 * * * * php myscript.php
#reboot /bin/sleep 60; php myscript.php
The first listing will run my cron job immediately after system boot and so I need to have the second listing to account for the on start wait time.
Is there anyway to combine the above two cron listings into one?

Cron job not running at specified time

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.

Is there a way to source cron jobs from a file

One of our servers has around 20-25 different cron jobs scheduled on it.
Usually, we periodically check-in the cron jobs to a file in the repo using crontab -l > cron.jobs
While bringing up a new server, which is a replica of the previous server (in terms of OS and deployed code base), is it possible to source the cron jobs for the new server from a file containing valid cron jobs?
If a file name is given as the sole argument to the crontab command, it is used to replace the current crontab:
crontab -l > cron.jobs
crontab cron.jobs
Alternately, feed the file through stdin:
crontab < cron.jobs
Try,
crontab < cron.jobs
on new server. The jobs in cron.jobs becomes new jobs replacing the installed jobs. So better take a back-up of existing cron jobs before replacing,
crontab -l > cron.jobs.bkp

Details of last ran cron job in Unix-like systems?

I want to get the details of the last run cron job. If the job is interrupted due to some internal problems, I want to re-run the cron job.
Note: I don't have superuser privilege.
You can see the date, time, user and command of previously executed cron jobs using:
grep CRON /var/log/syslog
This will show all cron jobs. If you only wanted to see jobs run by a certain user, you would use something like this:
grep CRON.*\(root\) /var/log/syslog
Note that cron logs at the start of a job so you may want to have lengthy jobs keep their own completion logs; if the system went down halfway through a job, it would still be in the log!
Edit: If you don't have root access, you will have to keep your own job logs. This can be done simply by tacking the following onto the end of your job command:
&& date > /home/user/last_completed
The file /home/user/last_completed would always contain the last date and time the job completed. You would use >> instead of > if you wanted to append completion dates to the file.
You could also achieve the same by putting your command in a small bash or sh script and have cron execute that file.
#!/bin/bash
[command]
date > /home/user/last_completed
The crontab for this would be:
* * * * * bash /path/to/script.bash
/var/log/cron contains cron job logs. But you need a root privilege to see.
CentOs,
sudo grep CRON /var/log/cron

Resources