1

The user gives the value of the time interval (minutes), let's call it X. I need to write a program which creates a file and writes a cron job in it to run every X minutes, and then install it as crontab for the user.

Since I need to programmatically create a file containing a list of user's cron jobs. And then I'll install it as the user's crontab (programmatically).

For that, I need a way in my program (algorithm) to translate the value of X into the cron expression.

For example, say the value of X (time interval) is 1 minute, meaning that we need the cron job to run the cron job every 1 minute, so I need to figure out a way to translate that 1 to the cron expression * * * * *, so that a cron job is written to the file like:

* * * * * script/to/execute 2>&1

The value of X can be anything, starting from 1.

So, in a nutshell, the question is that how to translate an integer value of minutes X into a cron expression, such that the cron job runs every X minutes?

Shy
  • 542
  • 8
  • 20
  • use the */x devider, have a look at https://stackoverflow.com/questions/12786410/run-cron-job-every-n-minutes-plus-offset – FatFreddy Oct 16 '18 at 11:12
  • 1
    Run a "scheduler" script that runs every minute and checks what other tasks to run. – brombeer Oct 16 '18 at 11:12

0 Answers0