this post was submitted on 26 Feb 2024
38 points (95.2% liked)

Linux

48741 readers
1461 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

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.

you are viewing a single comment's thread
view the rest of the comments
[–] limelight79@lemm.ee 7 points 10 months ago (1 children)

Personally I'd write a script to do whatever it is you want to do, checking first whether the internet connection is working. Said script can check the internet is working, if not, sleep for 10 minute or something, and try again, perhaps giving up after a set number of tries. Said script could also check the date and time of the file downloaded and confirm it is out of date.

Then, have the script execute on bootup by adding it to the startup scripts.

[–] taladar@sh.itjust.works 3 points 10 months ago (1 children)

Instead of having it sleep 10 minutes just make it a cronjob that runs every 10 minutes and has a lockfile, much more robust that way.

[–] Valmond@lemmy.mindoki.com 1 points 10 months ago (1 children)

If it should be done say only twice a day, then your way would be completely cumbersome.

[–] taladar@sh.itjust.works 1 points 10 months ago

If it should be done only twice a day sleeping for 12h would be even more error prone and you would be even less likely to have it actually run at that time.

Also, if it should be done only twice a day you don't really want it to run twice a day only since you can not guarrantee that you have internet exactly at the time when your timer expires, you would want to check some "last_updated" timestamp and check if it was more than 12h ago.