You've got a couple of choices here.
The only tricky bit is that you can't give all the info to "at" on its command line, you have to feed it via stdin or from a file. You can give stdin directly from your script via a pipe, or you can do it from an invoked shell.
"at" jobs run on the system, not the shell. The shell is just used for invoking normally at a CLI. You don't need it, and when posssible I avoid interacting with it because it can do powerful things that you're not expecting. But in this case it may be simpler.
Since I don't know of any python modules that directly interface with "at", I'd just use subprocess to run the command, and open a pipe to the subprocess for the necessary commands.
^D is a signal to your keyboard driver that you want to close the file down. In general when you're not using the keyboard, you just close the file. You don't send an explicit EOF. Also, most external communication requires a bytes object, not a str, so it has to be encoded.
Example 1, use a process and a pipe for commands
The only tricky bit is that you can't give all the info to "at" on its command line, you have to feed it via stdin or from a file. You can give stdin directly from your script via a pipe, or you can do it from an invoked shell.
"at" jobs run on the system, not the shell. The shell is just used for invoking normally at a CLI. You don't need it, and when posssible I avoid interacting with it because it can do powerful things that you're not expecting. But in this case it may be simpler.
Since I don't know of any python modules that directly interface with "at", I'd just use subprocess to run the command, and open a pipe to the subprocess for the necessary commands.
^D is a signal to your keyboard driver that you want to close the file down. In general when you're not using the keyboard, you just close the file. You don't send an explicit EOF. Also, most external communication requires a bytes object, not a str, so it has to be encoded.
Example 1, use a process and a pipe for commands
import subprocess at_command = "at now + 1 hour".split() p = subprocess.Popen(at_command, stdin=subprocess.PIPE) p.communicate("/bin/ls > /tmp/foo\n/bin/ls /tmp/ > /tmp/bar\n".encode())Example 2, use the shell. Note since the shell is doing all the work here, we pass the shell a string and it parses out everything.
import subprocess at_command = "echo '/bin/ls > /tmp/foo' | at now + 1 hour" p = subprocess.Popen(at_command, shell=True).communicate()