4

I would like to start on boot Slack only when I'm at work (basically, its 10:00 am till 18:00 pm on working days). I do not really want to write custom scripts, I would like to check this in more good way, for example:

here

But how? My first approach is to use cron's @reboot with date - not looks like its possible. Secondly, I've tried to search for tool, which you pass test string in crontab format and getting error code 1 or 0 back - no luck here.

Could you please point me in right direction?

1 Answers1

4

The command date +%u will output the day of the week as number. The command date +%k will output the current hour in 24h format. We can use command substitution $() and bash double brackets test [[ to create an appropriate condition:

bash -c '[[ $(date +%u) == [1-5] && $(date +%k) == 1[0-7] ]] && /path/executable'
  • [1-5] - is a regular expression that describes the working days of the week.
  • 1[0-7] - is a regexp that describes the working hours, it will cover from 10:00 to 17:59.

  • /path/executable is a synopsis for the command/application that you want to run.

  • Within the expression [[ <condition-1> && <condition-2> ]], the logical and && means that both conditions must be fulfilled.

According to the question, you can use the above command within crontab, or with Startup Applications. For couple of reasons I would prefer to use Startup Applications.

pa4080
  • 30,621