1
30 */2 * * * *

this expression runs every 2 minutes starting form 30 seconds. Say for example I'm starting cron job at 5 Pm. cron job start executing at 5:00:30, 5:02:30, 5:04:30 in (HH:MM:Sec). But I need the solution to execute every 2 minutes 30 seconds. like 5:02:30, 5:05:00, 5:07:30 this.

Barmar
  • 741,623
  • 53
  • 500
  • 612
Sudhakar T
  • 11
  • 1
  • 3
  • You may need to write a C program doing that. Read [syscalls(2)](https://man7.org/linux/man-pages/man2/syscalls.2.html). You can also observe that your delay is 150 seconds. You should also read [crontab(5)](https://man7.org/linux/man-pages/man5/crontab.5.html) – Basile Starynkevitch Mar 20 '21 at 06:29
  • 1
    `cron` is not a high-resolution scheduler. A crontab specification is "minutes hours day month dayofweek". You cannot specify seconds. At least not according to the default [`crontab(5)`](https://man7.org/linux/man-pages/man5/crontab.5.html) that ships with Ubuntu – knittl Mar 20 '21 at 06:47
  • Voting as off-topic. This question is not programming related and a better fit for – knittl Mar 20 '21 at 06:54
  • 1
    What are you doing that requires running the jobs at such a specific schedule? – Barmar Mar 20 '21 at 06:58

1 Answers1

2

cron only provides the ability to start jobs in minute intervals. However, you can call the sleep program to create a seconds-based offset. NOTE that this is not a high precision scheduling framework; depending on your system load some tasks might be delayed.

# run at minute 2, 7, 12, 17, … then offset by 30 seconds
2-57/5 * * * * sleep 30; your_command
# run at minute 0, 5, 10, 15, … without offset
*/5 * * * * your_command

Find a similar answer here, although the question is phrased a bit differently (execute every 30 seconds)

knittl
  • 246,190
  • 53
  • 318
  • 364