2

In linux ec2 instance i want to run a cron job 3 Days once to automate a process once in three days as a sudo user in my linux ec2 instance.

Can anyone help me out with the cron.

Manikandan Ram
  • 399
  • 2
  • 15

2 Answers2

0

You can create a cron that executes 3 days of the week and once you finish these three days delete it it.

$ crontab -e

And add the following line:

* * * * 1-3 sudo <your comand>

These is an explanation of the cron syntax:

 ┌────────── minute (0 - 59)
 │ ┌──────── hour (0 - 23)
 │ │ ┌────── day of month (1 - 31)
 │ │ │ ┌──── month (1 - 12)
 │ │ │ │ ┌── day of week (0 - 6 => Sunday - Saturday, or
 │ │ │ │ │                1 - 7 => Monday - Sunday)
 ↓ ↓ ↓ ↓ ↓
 * * * * * command to be executed

And you can use the number of the days or the short name of the days:

0 - Sun      Sunday
1 - Mon      Monday
2 - Tue      Tuesday
3 - Wed      Wednesday
4 - Thu      Thursday
5 - Fri      Friday
6 - Sat      Saturday
7 - Sun      Sunday
ginerama
  • 216
  • 1
  • 7
  • Ginerama, But this cron i checked this one, It has the capability to At every minute on every day-of-week from Monday through Wednesday – Manikandan Ram Nov 28 '19 at 12:03
  • Of course, sorry. `0 1 * * 1-3 sudo ` . Now it's executed once at 01:00 AM from Monday to Wednesday. – ginerama Nov 28 '19 at 15:07
0

This should do the job:

0 0 */3 * * sudo ...
\_/ \_/ | |
 |   |  | Every week 
 |   |  |
 |   |  Every month
 |   |
 |   Every third day
 |
 Midnight 

http://man7.org/linux/man-pages/man5/crontab.5.html

Phill W.
  • 1,479
  • 7
  • 7