How to script at job creation?
Karl Auer
kauer at biplane.com.au
Fri Dec 11 08:19:34 UTC 2020
On Fri, 2020-12-11 at 08:12 +0100, Bo Berglund wrote:
> #!/bin/bash
> NEXTDAY=`date --date="tomorrow" +%Y-%m-%d`
> CMDTIM1="echo \"timeout --signal=2 65m getmsnbcstream ${NEXTDAY}_"
> #Now create the at jobs
> CMDAT="${CMDTIM1}inp19.mp4\" | at 00:58 tomorrow"
> $CMDAT
> exit
You are hiding shell control from the current shell. To fix, just put
"eval" at the start of the second-last line:
eval $CMDAT
Read "man bash" for a description of what eval does - basically the
arguments to it become a shell command again (instead of a string
argument to echo, which is what you've ended up with).
There is no need to build commands like that unless you do actually
want to echo them. Here is an alternative (untested!):
#!/bin/bash
PREFIX=`date --date="tomorrow" +%Y-%m-%d`
SUFFIX="inp19.mp4"
FILE="$PREFIX$SUFFIX"
ATINPUT="timeout --signal=2 65m getmsnbcstream $FILE"
AT="at 00:58 tomorrow"
echo $ATINPUT | $AT
BTW if you want to see what commands are executing put "-x" at the end
of the shebang line ("#!/bin/bash -x"). To see just some lines, put
"set -x" in front of and "set +x" after the section you want to see.
Also, there is no need to explicitly exit a shell script unless you
want to set a specific return value. The script will exit with the
return value of the most recently executed command.
Regards, K.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)
http://www.biplane.com.au/kauer
GPG fingerprint: 2561 E9EC D868 E73C 8AF1 49CF EE50 4B1D CCA1 5170
Old fingerprint: 8D08 9CAA 649A AFEF E862 062A 2E97 42D4 A2A0 616D
More information about the ubuntu-users
mailing list