How to schedule an command with `at` which requires `Eth0` interface to up and running

atemailmuttnetworking

Need here to schedule some email sending at some date with at command, but need first to ensure that Eth0 interface is up and running.

How could I do that?

Currently using Mutt Mail User Agent already configured.

Just adding the information that if Eth0 is down in the scheduled moment, it won't send the email.

Best Answer

First to check if Eth0 (wired) connection is running:

$ nano eth0ch.sh

#!/bin/bash
if grep -Fxq "up" /sys/class/net/eth0/operstate
        then echo "Eth0 Up"
        else echo
fi
exit 0

$ sudo chown root:root eth0ch.sh

$ chmod +x eth0ch.sh

Copy it into /usr/bin

$ sudo cp eth0ch.sh /usr/bin/eth0ch

Second to halt if it is down:

$ nano eth0chk02.sh

#!/bin/bash

until [[ -n "$(eth0chk)" ]]; do
sleep 1
done
exit 0

$ sudo chmod +x eth0chk02.sh

$ sudo chown root:root eth0chk02.sh

Copy it into /usr/bin

$ sudo cp eth0ch.sh /usr/bin/eth0chk02

To start schedulling those emails sending, run it:

$at Scheduletime

Ex.

$at now + 30 days

at> eth0chk02
at> mutt -s "DestinyEmail@xxxx.com" < EmailBody

Ctrl + D

Just adding the info that you can set the date and time in several different ways, as of:

> at 10:15 18 aug 2023, for an email to be sent at 10:15 of august 18 of 2023, or

> now + 40 minutes, to send it 40 minutes ahead of current time.

Related Question