Skip to content

Instantly share code, notes, and snippets.

@hoylen
hoylen / route-repair.sh
Last active August 29, 2015 14:07
Init script to detect lost default network route and to restart network services to fix it. This script is useful when an unknown problem causes the default route to be lost (e.g. certain deployments of CentOS 7 and Fedora 20). Copy to /etc/init.d/route-repair and run "chkconfig route-repair on" and "service route-repair start".
#!/bin/sh
#
# chkconfig: 2345 15 85
# description: Maintains default route by restarting network
#
# This script (when run with the "run-loop" argument) checks if the
# default route is still present, and if not the network service is
# restarted. The timestamp of when the failure was detected is
# logged.
#
@hoylen
hoylen / getopt-example.sh
Last active July 23, 2020 11:59
Portable getopt argument processing in shell scripts. Detects which version of getopt is installed. When available, it uses GNU enhanced getopt to support long option names and whitespaces in arguments. Otherwise, defaults to using the original getopt.
#!/bin/sh
#
# Example showing use of getopt detection and use of GNU enhanced getopt
# to handle arguments containing whitespace.
#
# Written in 2004 by Hoylen Sue <hoylen@hoylen.com>
#
# To the extent possible under law, the author(s) have dedicated all copyright and
# related and neighboring rights to this software to the public domain worldwide.
# This software is distributed without any warranty.