Dark Matter
Dark Matter

Reputation: 2311

Issue with scheduling in Linux

I scheduled a script using at scheduler in linux.

The job ran fine but the echo statements which I had redirected to a file are no where to be found.

The at scheduling command is as follows:

at -f /app/data/scripts/func_test.sh >> /app/data/log/log.txt 2>&1 -v 09:50

Can anyone point out what is the issue with the above command.

I cannot see any echo statements from the script in the log.txt file

Upvotes: 1

Views: 91

Answers (1)

chepner
chepner

Reputation: 530970

To include shell syntax like I/O redirection, you'll need to either fold it into your script, or pass the input to at via standard input, like so:

at -v 09:50 <<EOF
sh /app/data/scripts/func_test.sh >> /app/data/log/log.txt 2>&1
EOF

If func_test.sh is already executable, you can omit the sh from the beginning of the command; it's there to ensure that you are passing a valid command line to at.

You can also simply ensure that your script itself redirects all its output to a specific log file. As an example,

#!/bin/bash

echo foo
echo bar

becomes

#!/bin/bash

{ 
echo foo
echo bar
} >> /app/data/log/log.txt 2>&1

Then you can simply run your script with at using

at -f /app/data/scripts/func_test.sh -v 09:50

with no output redirection, because the script itself already redirects all its output to that file.

Upvotes: 3

Related Questions