|Tigor Hutasuhut bf1077651d|
Network on Fail
Executes a program or script when ping fails to all given target host by certain amount of times.
By default it runs command for
systemctl restart NetworkManager, which will restart your network
if you use Network Manager as your primary network management and systemd. (Otherwise it fails, duh).
This program does not assume privilege access and thus if a command requires such thing, you must
run this program as a user that can run that command. For example, by using
network-on-fail --target myamazingwebsite.com,cool.site.io --exec "echo oh no!" # or network-on-fail --target myamazingwebsite.com --target cool.site.io --exec "echo oh no!"
Example above will ping (using default ping parameters set by this program) myamazingwebsite.com at first, then when fails, pings cool.site.io. If that fails too, a counter will then be raised.
When counter reached maximum allowed (default 3), the
exec command will be launched. In which case
at the example command above, "echo oh no" will be executed.
On success ping, counter will be reset to 0.
Command and Arguments
USAGE: network-on-fail [OPTIONS] OPTIONS: -c, --count <COUNT> How many ping run fails before executing command. This means that when a ping run fails (all ping attempt to each target failed), a counter will be raised. When the counter reached this value, command will be executed then restart back to 0. A successful ping will put counter value back to 0. [default: 3] -d, --delay <DELAY> Delay between each ping run in seconds. Delay starts ticking after a ping to a host is a success operation [default: 10] -D, --delay-after-exec <DELAY_AFTER_EXEC> Delay after execute command in seconds [default: 30] -e, --exec <EXEC>... Command to execute when ping fails. Use quotes to handle command with spaces. Repeated argument will be appended [default: systemctl restart NetworkManager] [aliases: command] [short aliases: C] -h, --help Print help information --ping-count <PING_COUNT> Ping number of times before exit waiting for target [default: 1] -t, --target <TARGET>... Target hosts of ping. When one ping fails, the programs tries to ping the others first before rising the counter when all fails [default: google.com cloudflare.com] [aliases: ping] -T, --timeout <TIMEOUT> Timeout to wait between each ping in seconds [default: 5] -V, --version Print version information