Run a command at boot

Hello all.
I am currently looking for a way to configure my Fedora 36 workstation to begin pinging the gateway continuously at boot time. has anyone else had any success running new commands at start time could help?
thanks in advance. :sunglasses:

2 Likes

At boot time do you mean once logged in to GNOME or during the boot process?

1 Like

Wow. Pinging the gateway continuously will consume an inordinate amount of unnecessary bandwidth both on the interface and on the gateway.

It is easy to write a script to do what you ask. It is also easy to create a crontab entry to do the same with the output going to a log file so you can check it whenever needed.

A crontab entry could run your script or run the command directly.

It is also possible with gnome to configure an app to launch when you log in.

1 Like

at boot time, I want to start the ping as soon as the computer gets an address from the router.

What are you trying to achieve with this?

its a little old trick i learnt from my friends in networking. its on the internal network of the modem with the wifi etc so it shouldnā€™t matter if I ping the gateway of the workstation at near the interface speed.

my concern is that if I create a command to run continuously with crontab will it stop at boot time and just keep running that command?

An old trick you learned from friends in networking???
What is the benefit to be gained?

Any time you have a ping running it will consume network resources and will impact the ability for other apps to use the network. It may possibly be negligible in your opinion, but also could potentially slow down all network traffic on the local LAN.

Any experienced network admin would tell you that a short ping is acceptable, but a continuous ping is not normally responsible behavior. On a corporate network the admins would quickly be tracking down the user doing such a trick. Your ā€˜friendsā€™ IMHO donā€™t seem to be giving you very good advice. The only similar ā€˜trickā€™ I have ever seen is referred to as a ā€˜ping floodā€™ and that is totally verbotten. It swamps the network and slows everything down to a standstill.

While I certainly do not care if you shoot your own foot with this behavior on your own local LAN, you really should know if there is a benefit and what that benefit is, as well as understand the potential negative consequences before doing so.

I am in doubt too about the benefit of this, but I have to admit that the PfSense firewall does the same. But in this case, it is listening to the ping responses to evaluate availability of the router and performance monitoring. Anyhow, you can limit the impact of the system by using e.g. ā€œping -i 30ā€ which sends a ping each 30 seconds. But I do not think that, even with a WiFi connection, there is any need for keep-alive pings. Started from cron, it runs in background and only fills up your mail spool (cron output is mailed).

There are cases where keep-alive pings are necessary: e.g. VPN behind a NAT router. If there is no activity, the return channel is closed and access from the remote site is lost. A ping with e.g. 30 second interval keeps it open. OpenVPN and Wireguard offer configuration options to take care of this.

Once upon a time I had to use something like that, but there was no constant pinging.
I did a job for a contractor who was tasked with deploying automation systems controlling dams and pumping stations. Being the miserly bastard that he was, instead of buying the professional equipment that was required for interconnections over a 3G network, he bought 20ā‚¬ consumer routers, paired with 15ā‚¬ 3G dongles. These dongles had a nasty firmware bug and after a while they would hang and had to be re-initialized, i.e. by rebooting the router. Since most of them were installed in remote locations, it wasnā€™t practical to have someone go over there and do that by hand. I wrote a script that pinged two high-availability external hosts, three times each, every 10 minutes (an acceptable interval for the whole system) and if no ping got a response, the router was rebooted. The script was set to run via a cron job.
That said, I cannot imagine another scenario were such a solution would be the most appropriate one, but necessity is the mother of inventionā€¦

I have this question too ā€“ where best to run a command at boot time.

Example.

Create a systemd service unit.
sudo nano /etc/systemd/system/endlessping.service

Content of such file.

[Unit]
Description=endless ping
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/ping -i 5 192.168.0.1
ExecStop=/bin/kill $MAINPID

[Install]
WantedBy=multi-user.target

Let systemd learn about the new service
sudo systemctl daemon-reload

Enable and start the service
sudo systemctl enable endlessping --now

ExecStart and ExecStop could contain your script. Please read systemd documentation (i.e. systemd.service)

1 Like

Great! Thank you for the example and pointer for more reading. Itā€™s just what I need to begin experimenting on a personal project.

Interestingly enough, on the International Space Station we have to run a continuous ping from a device in one module to a device in another module to keep a piece of network equipment we donā€™t manage passing data properly. It seems it otherwise has problems managing its arp table and floods the network with arp packets which causes all sorts of congestion which blocks the cyclic data for dozens of devices, creating a cacophony of alarms in the control center.