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?