The code I used to set up the at command can be found here

at -f noti.sh -t ${sleepTimes[$i]}

The times work correctly as I can see the jobs listed successfully with atq.

The file noti.sh is in the same directory where the at command is being used and it contains:

if [[ "$OSTYPE" == "linux-gnu" ]]; then
    notify-send "Insomnia" "Time to take a rest"  -u critical -t 7000 -i sleep.ico
elif [[ "$OSTYPE" == "darwin"* ]]; then
    terminal-notifier -title "Insomnia" -message "Time to take a rest"  -sound "default"  -group rest -timeout 7 -appIcon sleep.png

Both terminal-notifier and notify-send are installed on both respective platforms I've been testing this on. Why will the function not execute the way it should (show a notification bubble)?

  • I tried providing the full path and i also tried utilizing /.noti.sh – A. Epstein May 8 '17 at 3:28
  • 2
    Are these GUI applications (notify-send and terminal-notifier)? If so, you may need to set some environment variables (DISPLAY=:0.0, XAUTHORITY=/home/your-username/.Xauthority (or wherever it is), etc.) – Fox May 8 '17 at 3:30
  • I guess they are as it does show a notification bubble that isn't a native one so its invoking its own gui for the bubble. How do i set up those enviornment variables – A. Epstein May 8 '17 at 3:32
  • I did copied the output of the command at the top of my script calling the at command and that didnt work should i have put it it at the top of the noti.sh? The output was DISPLAY=/private/tmp/com.apple.launchd.5jte4rZAmH/org.macosforge.xquartz:0 im assuming by placing that at the top of the code it set a variable inside of my script called display – A. Epstein May 8 '17 at 4:01
  • putting that at the top of the noti.sh did not work – A. Epstein May 8 '17 at 4:05

Your problem might be this (from man at):


at and batch read commands from standard input or a specified file which are to be executed at a later time, using /bin/sh.

Also, if you run for example at -f noti.sh -t 2... it should output a warning like this:

warning: commands will be executed using /bin/sh
job 4 at Mon May  8 13:51:00 2017

/bin/sh on Debian is a symlink to /bin/dash. I guess you tested your script with bash, which has some features not defined by POSIX, i.e. they won't work in dash or, in general, with /bin/sh.

In your specific case, the problems are [[ ]] and OSTYPE, which are not supported by dash. Try to run

$ sh noti.sh 

It will return the following error

noti.sh: 2: noti.sh: [[: not found
noti.sh: 4: noti.sh: [[: not found

whereas, running the script with bash does what you want.

To run the script as you intended, you might need to rewrite it to be compatible with /bin/sh (dash in your case), see www.shellcheck.net for some help with this.

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.