8

I have a bash script that runs periodically once a day using crontab.

The script checks a condition, and if true, it should issue an at command at a specific time.

at 14:10 <notify-send hello>

The question is: how can I add a specific command like notify-send to the at command?

Melebius
  • 11,800
membersound
  • 1,460

2 Answers2

13
echo "notify-send 'hello'" | at 14:10

at is expecting a command from STDIN.

If you want to silence the /bin/sh warning, run it this way:

echo "notify-send 'hello'" | at 14:10 2>/dev/null
Pilot6
  • 92,169
  • I am testing your command I see this error warning: commands will be executed using /bin/sh, what does it mean? – George Udosen Jun 12 '17 at 12:37
  • 1
    This means literally what is said. /bin/sh will be used as a shell for the command. It is OK if you are worried. – Pilot6 Jun 12 '17 at 12:39
  • 1
    @George I added how to silence the warning. – Pilot6 Jun 12 '17 at 12:44
  • ok but I prefer to see it in case I did something dumb :) – George Udosen Jun 12 '17 at 12:45
  • 2
    This is useless use of echo and pipe. A Here String would be more appropriate: at 14:10 <<< "notify-send hello". – Ruslan Jun 12 '17 at 12:53
  • @Ruslan It is an option too. I use it both ways. It looks better as command | at <time> ;-) – Pilot6 Jun 12 '17 at 12:54
  • @Ruslan does it make any practical difference for shells such as bash and dash, where echo is a shell builtin? – steeldriver Jun 12 '17 at 13:26
  • @steeldriver In this case it makes no difference. For some other commands there may be a difference. – Pilot6 Jun 12 '17 at 13:37
  • Regarding @Ruslan comment it makes no difference at all. – Pilot6 Jun 12 '17 at 13:37
  • warning: commands will be executed using /bin/sh warn you that the command will be run as /bin/sh, this is important because dash (the default command interpreter for ubuntu is not 100% compatible with bash (which is probably the shell you're using). – pim Aug 24 '17 at 13:53
2

As I was searching for a fast way to remind myself using dunstify/notify-send I want to promote @Ruslan 's comment, because it involves less typing (which is essential when you want to "just set a timer")

at now + 3minutes <<< "notify-send -t 0 'tee is ready'"

... or with less whitespace/characters:

at now+3min<<<'notify-send -t 0 tee isready'
  • -t 0 don't timeout the notification and keep it open

and just for information: as an improvement to atq or at -l listing I use an alias that also prints the executed command, not just time/queue/user:

alias ,atl='for j in $(atq | sort -k6,6 -k3,3M -k4,4 -k5,5 |cut -f 1); do atq |grep -P "^$j\t" ;at -c "$j" | tail -n 2; done'

(as mentioned here in serverfault)

* tested with Manjaro21/Debian10

muru
  • 207,970
MacMartin
  • 353