2

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

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.

| improve this answer | |
  • i think it will work, ill find out tomorrow. – Tymur Valiiev Apr 10 '18 at 19:33
  • @ТимурВалиев, it works in the command line. If there is an issue try to add sleep 15 && in front of the command - 15 seconds should be enough for the graphical environment to be completely loaded. – pa4080 Apr 10 '18 at 19:41
  • Its not working for me. Tried few days, no luck. It works in commandline, but not via "Startup Applications" – Tymur Valiiev Apr 16 '18 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.