user2809888
user2809888

Reputation:

Using at command in shell script for scheduling a command

I am trying to use the feature of "at" command to schedule the execution of any specific command at some user defined time. Wondering if its possible using "at" command. I am hoping "at" could help me because I do not have privileges to schedule a cron task.

Things I have tried :

user>touch testfile |at 03:00  
job 30 at 2014-12-31 03:00  
user>ls -lrt testfile  
-rw-rw-r--  1 user group 0 Dec 31 02:59 testfile  <-----file created with command execution  
user>  

user> touch testfile1 | at -f 03:01
Garbled time
user>ls -lrt testfile*
-rw-rw-r--  1 user group 0 Dec 31 02:59 testfile
-rw-rw-r--  1 user group 0 Dec 31 02:59 testfile1

Upvotes: 1

Views: 1298

Answers (1)

Barmar
Barmar

Reputation: 781058

Use:

echo "touch testfile" | at 03:00

You're running touch testfile immediately, and piping its output to at. The input to at should be the command you want to run, not the output of the command.

If you want to run multiple commands, use a here-doc:

at 03:00 <<EOF
touch testfile
touch testfile1
EOF

Upvotes: 3

Related Questions