Here's the script which is going to run the two programs. I'm presuming you want them to run root, there's no indication otherwise and so we'll call that a separate question.
# Redirect standard out and standard error to a file.
exec &> /var/log/whatever.log
echo $(date +"%D %T")" Begin."
echo $(date +"%D %T")" 5m elapsed, starting foo and bar."
/path/to/foo arg1 arg2 &
exec /path/to/bar arg1
bar represent your two programs. The parentheses they and everything that takes time (e.g., the
sleep) are inside of, with the
& (fork) at the end, are critical. This is a subshell. It is an independent, child process. The parent is going to exit right away (last line), leaving it running in the background. Note the output redirection (
exec &> ...) applies to it as well. This makes it important that you use
bash in the first line (the "shebang", think # = "shh" ! = "bang") and not just
&> is a bash-ism. They are the same program anyway but how it is invoked affects how it runs.
bar have their own logging arranged; you may also redirect their individual ouput when you launch them above.
This is started with the following systemd service file:
Description=Plotly and Sensor stuff
Put that in
/etc/systemd/system and call it
local_waitAndPlot.service. Make sure that and the script are owned root, the easiest way to do all this is
su root but since user
pi has such broad permissions you could do it that way and use
chown. The script must be executable:
chmod 755 script.sh. The service file doesn't, the default mode should be fine.
sudo systemctl enable local_waitAndPlot.service
Obviously you don't need the
sudo if you already
su root. Anyway, it should mention something about adding a symlink. Check inside
/etc/systemd/system/default.target.wants and you should see it there.
Reboot. You should be able to immediately check
/var/log/whatever.log and see that "Begin" statement. Five minutes later you'll see the other one and hopefully
bar start with no problems. Pay attention to the structure there, namely the
& on the first process and the
exec on the second. This is very simple but necessary stuff.
The script will occupy < 1 KB RAM and use zero processor time for the five minutes it waits. Details about the
date format are in
man date, about the service file entries see
man systemd.service and
man systemd.unit. Systemd itself has timers, if you research that you may be able to do it that way, see
apropos systemd and more specifically
man systemd.timer -- I've never used one for anything and you probably need the launcher script anyway.