Hi folks, Does anyone know how to instruct cron to carry out a command when a connection to the internet is first made after boot? I have a few jobs that only need to be done once per day and require an internet connection e.g downloading the weather forecast and my rss feeds. I’m not always connected to the internet on boot and do not have the computer switched on at the same times every day. Many thanks for any suggestions.
Systemd timers are able to do this. Set it up to run daily and make it require the network-online.target.
sudo cat /etc/systemd/system/CUSTOM-networkstuff.service <<EOF [Unit] Description=Ping Wikipedia.org After=network-online.target Wants=network-online.target [Service] Type=oneshot ExecStart=/usr/bin/ping -c 1 wikipedia.org EOF sudo cat /etc/systemd/system/CUSTOM-networkstuff.timer <<EOF [Unit] Description=Daily ping to Wikipedia.org [Timer] OnCalendar=*-*-* *:*:00 Persistent=true [Install] WantedBy=timers.target EOF sudo systemctl enable --now CUSTOM-networkstuff
Would it not just be the easiest way to put your scripts under /etc/network/if-up.d/? Then they get run once that connection is brought up.
Would it be a problem to just poll every few minutes?
You could script it to only actually do anything if the downloaded data is old, and if it is, then download new.