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.

  • Pantherina@feddit.de
    link
    fedilink
    arrow-up
    0
    ·
    9 months ago
    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