0

I made a bash script called test.sh that contains the following:

#!/#bin/bash

echo "Done!"

I enter bash test.sh | at 1549:

myusername@machine:path$ bash test.sh | at 1549
warning: commands will be executed using /bin/sh
job 4 at Fri Sep  3 15:49:00 2021
myusername@machine:path$ date
Fri Sep  3 15:48:22 EDT 2021
myusername@machine:path$ date
Fri Sep  3 15:49:12 EDT 2021

Why does it appear that the script was not executed? Is it because my shell is bash as shown below?

myusername@machine:path$ echo $SHELL
/bin/bash
2
  • 1
    That is a strange shebang. As you use bash as command for the script it would run OK, but if ran as stand-alone the system would likely go bananas trying to interpret the line. You say interpreter is /#bin/sh which I can not see how it would normally exist.
    – ibuprofen
    Sep 3, 2021 at 21:29
  • 1
    that should probably be #!/bin/bash
    – ilkkachu
    Sep 3, 2021 at 22:20

2 Answers 2

5

You are executing the script immediately, and scheduling its output for execution by at. Needless to say this fails.

What I think you want is this

#!/bin/bash
echo "Done!"

Consider you have written this to a file called myscript.

Make it executable:

chmod a+x myscript

Then queue it for execution at 15:49 and capture the output in myscript.log (if you don't capture the output it gets emailed to your local UNIX/Linux account, or if there is no mail subsystem installed at all then it's simply discarded):

at 1549 <<'X'
./myscript > myscript.log 2>&1
X
2
  • Very well written answer! Sep 3, 2021 at 22:41
  • @FKEInternet thank you. I'm glad you found it useful Sep 3, 2021 at 22:46
3

Any output from a command executed through the at system, is sent on via email.

Secondly, when they are executed, it has disassociated itself from your current tty, so is unable to interact with it, even if you wanted it to.

3
  • What does it mean that it is sent on via email?
    – Andrew
    Sep 3, 2021 at 20:09
  • It's sent via /usr/sbin/sendmail. Please read the at man page. If you don't have an email infrastructure set up, then either run mail, or look at the contents of the /var/spool/mail directory.
    – Bib
    Sep 3, 2021 at 20:11
  • 2
    ... thirdly, bash test.sh | at 1549 runs bash test.sh now and passes its output to at, which will therefore attempt to execute a command named Done! at 15:49 Sep 3, 2021 at 20:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .