Edit: I managed to solve this myself, I actually deleted my original question as I was over complicating the process slightly, but have since answered it in case others find it useful. RegExp is not required in this case, as its dealing with mainly numeric based results.
I have a
write_cronjob() function that checks if the passed job already exists or writes to crontab if the grep condition doesn't find anything matching already.
Due to certain network restrictions cronjobs should only be scheduled in a certain window. As the schedule can be set by the user freely the script needs to detect any jobs that attempted to be scheduled outside the defined window, simply because they won't run.
The function takes two parameters:
$1- contains just cron schedule e.g.
0 19 * * 3
$2- contains the job/command to run
They are then merged just before the write operation if required.
Cron schedule rules must be within following criteria:
- Monday - Friday (Weekdays)
- 7 AM (07:00 AM) - 10 PM (22:00 PM)
I was thinking of doing range check on the day part which is simple enough, but the hour part is a bit harder, with the use of 24hr time i.e. 22 = 10 PM.
What I require is:
- Ability to split
$1to pick out the hour and day parts of the cronjob for conditional checks.
- RegExp pattern/range check on the split parts to detect if they are outside the criteria, and
My shell is ash (BusyBox), I can't use an array.