I have a script that runs forever using watch. It is started with watch -n1 -x /bin/bash /sh/lapse.sh &>/dev/null &, contained in the file /root/startsnap.sh. The script contains
ISMOUNTED=`mount | grep -c unit_1`
if [ $ISMOUNTED -eq 1 ]; then
FILENAME=/share/unit_1/public/henyard/`date +%Y%m%d%H%M%S`.jpg
wget -qO $FILENAME http://10.168.0.200/ISAPI/Streaming/channels/1/picture && chmod 664 $FILENAME && chown username.groupname $FILENAME
fi
When I start the script manually, it runs perfectly. However, I would like it to start at startup. To that end, I have @reboot /bin/bash /root/startsnap.sh in crontab.
The script does not run after reboot. journalctl does not show anything related to this. Setting up a systemd service did not work, either. Nothing seems to run.
Possibly the easiest way would be to put it in /etc/rc/rc.d and name it rc.local. This way it will get executed at the very end of startup by rc.local.service, which is automatically acitve if that file exists. One nice thing about Linux is that there’s almost always more than one way to do just about anything, so that if you’re having trouble getting one of them to work, there are others you can try.
Thank you for this suggestion. As per the original post, the systemd service refuses to do anything. And I did not mention in the post that I do not log onto that computer locally and never start the graphical user interface. I will, however, read the other links you mentioned regarding systemd.
Thanks. I was thinking myself of the rc.local first but it has been my understanding that all the easy, guaranteed-to-work features of Fedora are being phased out and replaced by unnecessarily complex and bloated options with either too sparse or excessively detailed help or man pages (replace /var/log/messages with journalctl, replace /etc/init.d with systemd, replace network scripts by NetworkManager etc.) and therefore didn’t honestly even expect it work anymore.
Not sure what the error means, but I suspect cron is starting the script before the network is up, which maybe causing an issue. My only other suggestion is systemd:
Got it fixed based on the error message. At that stage, the variable TERM is not yet set, and therefore watch does not know where to put its content. I added export TERM=linux to the script and now it works.
I will happily use some other method when one comes up with a way of running a command every 1 or 2 seconds until terminated. Crontab does not work for this purpose.
I’m sure I had some reason why I didn’t choose this. Maybe I tried it first and noticed it wouldn’t do what I wanted (probably because of the missing TERM variable) and chose another way. Maybe I wanted something that would spawn a background process and settled for watch. Who knows, I cannot remember.
I do thank you for that reply, as well, and am happy with my watch solution.