Reputation: 314
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?
Upvotes: 0
Views: 679
Reputation: 125728
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.)
Upvotes: 1
Reputation: 13189
You can give any command as input without the -f:
at 22:20
/path/to/script.sh /arg/one argtwo argthree
^d
Upvotes: 0
Reputation: 123410
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.
Upvotes: 7