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.

2 Answers 2

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
2
  • 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 Nov 28, 2019 at 12:03
  • Of course, sorry. 0 1 * * 1-3 sudo <your comand> . Now it's executed once at 01:00 AM from Monday to Wednesday.
    – ginerama
    Nov 28, 2019 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

1
  • This one i checked this one will run At 00:00 on every 3rd day-of-month Nov 28, 2019 at 12:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .