Cron updates

This cmd will update the user's crontab with the quoted line.
But how to script the update using a previously stored variable?

crontab -l | awk '{print} END {print "* * * * * echo test >> /tmp/testing"}' | crontab
crontab -l | awk '{print} END {print "$storedvariable"}' | crontab

Does not get it done, nor does

...."\$stored...."

The shell won't expand parameters or variable within single quotes. So - either use double quotes for the awk command but pay attention to escape the double quotes in the script,

crontab -l | awk "{print} END {print \"$storedvariable\"}"

or use the correct mechanism for awk : the -v option:

crontab -l | awk -v SV="$storedvariable" '{print} END {print SV}' 

Why that complicated, by the way? How about

{ crontab -l; echo "$storedvariable"; }
1 Like

The final line....

crontab -l |awk -v CRON_add="$CRONadd" '{print} END {print CRON_add}' |crontab

...does do the deed
Thank you RudiC

---------- Post updated at 11:24 AM ---------- Previous update was at 11:20 AM ----------

RudiC, I am not following the line...

{ crontab -l; echo "$storedvariable"; }

Try it, and compare the result to the others'. Dissect it. run it in parts.