Running script on startup, Fedora 30

I have a script that runs forever using watch. It is started with watch -n1 -x /bin/bash /sh/ &>/dev/null &, contained in the file /root/ 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 && chmod 664 $FILENAME && chown username.groupname $FILENAME

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/ 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.

How do I run this script at startup?


it may throwing an error, because the shebang is missing from the begining of the script, please try making this the first line:


You could also temporarily direct standard output & error to a log file for the cronjob, it may give insight to whats going on; try:

@reboot /bin/bash /root/ &>> /root/startsnap.log

Thanks Tom.

There are several ways you can use them, including creating systemd unit .

And you can try make desktop entry file and put it in /etc/xdg/autostart or for user wide ~/.config/autostart

file example :

1 Like

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.

I will give thiis a try.

Edit: the log file says: Error opening terminal: unknown.



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:

Description=Start Snap



Thanks Tom.

systemd-run /path/to/
journalctl -u unit_name

What does it say?

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.


Although watch is probably not a command you should use in a non-interactive script.

1 Like

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.

while sleep 2

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.