iyers16
iyers16

Reputation: 42

Running bash script with at command (scheduled script) not working

My scheduled script isn't working this is what I've tried: I have a b.sh file with the following:

#! /bin/bash
echo "hello, $USER"

I want to try using the "at" command for a scheduled send in 1 minute as follows echo b.sh | at now + 1 minute but nothing is executing anywhere...

I checked the queue with atq first and confirmed it was waiting for the next minute to execute, but one minute later, nothing was happening anywhere.

Is it executing somewhere and I'm not looking in the right place? I was under the impression it should execute in the terminal before my eyes...

Upvotes: 0

Views: 1185

Answers (1)

Arnaud Valmary
Arnaud Valmary

Reputation: 2325

In fact, the process used with at command is executed by atd daemon.

atd daemon is not attached to your terminal.

But, if you want to print messages, you have two solutions:

  1. Redirect your outputs to a file like this at the beginning of your script :
exec > /path/to/my_log/file.log
exec 2>&1
  1. Write on the TTY of your bash:

Execute your at command like this:

echo "FATHER_TTY=$(tty) ./b.sh" | at now + 1 minute

And, the content of your ./b.sh script:

#! /bin/bash
exec > "${FATHER_TTY}"
exec 2>&1
echo "hello, $USER"

Upvotes: 2

Related Questions