7

I'm trying to schedule the execution of some programs. I'm using this command:

./tests.o | at 15:00&

If I understood correctly, the intended behaviour was to delay execution until 15:00. However if I run top as soon as I launch the above command, I can see already tests.o eating CPU time.

Since I need to launch multiple tests on a shared resources I am wondering how to correctly use "at"?

What am I doing wrong?

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
  • 1
    This syntax (excluding `&` which is not needed) would be right if `./tests.o` generated (printed to its stdout) the commands you want to run at 15:00. – Kamil Maciorowski Sep 08 '18 at 14:24

1 Answers1

10

at reads commands from standard input. What you are doing is running ./tests.o and feeding its output string(s) as command(s) for at to schedule. Also, there is no need for the trailing &, as at returns immediately.

What you need is:

echo ./tests.o | at 15:00

or:

at 15:00 <<< ./tests.o

You will need to use quoting if you want the scheduled command to use redirection or other shell functions, eg:

at 15:00 <<< './tests.o > tests.log'
AFH
  • 17,300
  • 3
  • 32
  • 48
  • Thanks, now i see what i was doing wrong. @KamilMaciorowski thanks for your clarification. – Mick Hardins Sep 08 '18 at 14:27
  • @KamilMaciorowski - I often cross with other answers and comments, as I frequently realise there are things I should double-check while I'm writing my answer. I don't always remember to check before I post. Sorry to have pipped you at the post. – AFH Sep 08 '18 at 14:46
  • A here-document is another convenient way to deal with shell metacharacters in the command. – Barmar Sep 14 '18 at 19:11
  • @Barmar - I used a here-string in my answer and this was the right answer for the problem posed in the question, but obviously a here-document would be appropriate if more than one command was to be scheduled at the same time. I wouldn't use it for a single command in order to avoid quoting. – AFH Sep 14 '18 at 19:52
  • I'm not criticizing, just mentioning an alternative that generalizes a little better. – Barmar Sep 14 '18 at 19:56
  • @Barmar - I realised that, and I was trying to qualify your comment by illustrating where it would be more relevant. – AFH Sep 14 '18 at 20:07