linuxbashparametersat-job

Passing arguments to at -f script


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?


Solution

  • 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.