Passing arguments to at -f script

357 views Asked by At

I'm trying to schedule a bash script using at command on Linux.

at 22:20 -f /path/to/script.sh

Issuing the command above works just fine. However, the script requires some parameters. Adding Params behind the script path returns an error message:

at 22:20 -f /path/to/script.sh /arg/one argtwo argthree
syntax error. Last token seen: /

Yes, the first parameter passed to the script is another (absolute) path. My guess is, that at doesn't treat my script as a script but rather as a file, as at -help implies.

How can I work around that and add params to the script?

3

There are 3 answers

0
that other guy On BEST ANSWER

Specify the command to run on stdin, e.g. via a here string:

at 22:20 <<< "/path/to/script.sh /arg/one argtwo argthree"

Your command does not try to run /path/to/script.sh at a certain time. Instead, it reads and copies all the commands from /path/to/script.sh and runs those later. Since you're not invoking the script itself, it doesn't make sense to talk about arguments.

0
stark On

You can give any command as input without the -f:

at 22:20 
/path/to/script.sh /arg/one argtwo argthree
^d
0
Gordon Davisson On

You're correct that it's taking just a filename, not a command. You should just run at 22:20, and then as input to that command, give the command you want run at 22:20 (i.e. /path/to/script.sh /arg/one argtwo argthree), and then Control-D on a separate line to mark the end of input. It should look a little like this ($ is my prompt):

$ at 22:20
/path/to/script.sh /arg/one argtwo argthree
job 11 at Thu May 27 22:20:00 2021
$ 

(Note that the "job 11 ..." is a confirmation message at printed.)