0

I use a script file to run some tasks using the AT command, but in the log file the date echoed is the date when I set up AT command not the execution date.

What can I do to display the actual time of end of execution?

This is my script file content:

logFILE="/tmp/loggfile.log"

if [[ -z "$1" ]]; then echo "Please specify the run time, HH:MM "; exit 1; fi
runTIME=$1

at $runTIME <<< "
echo 'Running a task....'
echo 'An other task....'
echo 'END : (`date '+%H:%M'`)' >>$logFILE
"
echo "The command was scheduled to run at $runTIME"

If I run it at 16:00 with ./script.sh 23:20, the task will be executed at 23:20 but in the log file I get END : (16:00)

Any help will be appreciated.

1 Answer 1

0

date is executed when the script runs because `…` syntax is inside double quotes. It's also inside inner single quotes but the most outer quotes count. The result is at doesn't "see" `date …` but its output.

Make outer quotes single, inner quotes double. at will get the entire string as is. When the time is right it will run sh which will see `date …` in double quotes and only then date will be evaluated:

at "$runTIME" <<< '
echo "Running a task...."
echo "An other task...."
echo "END : (`date +%H:%M`)" >>"$logFILE"
'

Note I dropped the most inner single quotes ('+%H:%M'). In my version they would vanish while passing the string to at; the code works without them anyway.

0

You must log in to answer this question.

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