I am looking for a way to create a command line using 'at' (atd) to schedule a task, that schedules a task to do "more stuff" after a reboot (one time task). What I am looking for right now is a way to make it fly just chaining together "at" schedules.
My problem is, that I get somehow lost with the quoting/escaping in bash.
what I got so far and what works on a manual execution is:
echo "somecommand -someOptions 2>&1 | mail -s \"$HOST after reboot: somecommand -someOptions\" email@example.com" | at now +5 minutes ;\ #do admin stuff before reboot in less than 5 mins here ;\ touch /fastboot ; reboot
as mentioned, that works fine. I now would like to encapsulate the whole thing into ANOTHER NEW 'AT' COMMAND, so that the former command line can be scheduled to a specific starting time and no longer requires a manual execution.
I assume it must be possible to encapsulate/include the whole thing into another "at" command, so I would like to find out how to properly quote/escape it so that it will work.
I tried this (not working):
echo "echo \"somecommand -someOptions 2>&1 | mail -s \\"$HOST after reboot: somecommand -someOptions\\" firstname.lastname@example.org\" | at now +5 minutes ;\ #do admin stuff before reboot in less than 5 mins here ;\ touch /fastboot ; reboot ; " | at now + 1 minute
I see that it schedules 2 jobs, does the admin stuff before reboot and reboots, but the 2nd (later) at job is scrambled/crashed because of some bad quoting/escaping I guess. I would like to know and learn more about what is going on here and where I did wrong on the escaping. I guess I could use single quotes on the outer at, since in this case I don't need any variable expansions, but let's assume that I would like to use variable expansion there, too. In that case, how should I escape/quote this thing properly?