Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the at command in rest be simplified?

Tags:

linux

bash

shell

rest(){
    echo "have a rest in "$1 " minutes"
    at -f /home/rest.sh now+$1 minutes
}

To edit a rest.sh script.

vim /home/rest.sh
xscreensaver-command --lock

To test it.

rest 60
have a rest in 60  minutes
warning: commands will be executed using /bin/sh
job 7 at Thu Feb  9 11:15:00 2017

Can the at command in rest be simplifed?
To delete the /home/rest.sh, to pass parameter with pipe or other way?

like image 650
showkey Avatar asked Feb 09 '17 02:02

showkey


1 Answers

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

man at

So, you can feed it commands with a HEREDOC, like this:

rest(){
    echo "have a rest in "$1 " minutes"
    at now+$1 minutes <<EOF
    xscreensaver-command --lock
EOF
}

(note that the limit string EOF can not have any whitespace in front of it)

like image 190
zeppelin Avatar answered Sep 21 '22 13:09

zeppelin