Skip to content

Instantly share code, notes, and snippets.

@jfberry
Created May 27, 2020 19:49
Show Gist options
  • Save jfberry/06095beaf0b55221288c3d3a5316ef21 to your computer and use it in GitHub Desktop.
Save jfberry/06095beaf0b55221288c3d3a5316ef21 to your computer and use it in GitHub Desktop.
Work out power and network status for use pre backup
# Gather current power status
AC_POWER=`ioreg -l | grep ExternalConnected | cut -d"=" -f2 | sed -e 's/ //g'`
# Gather details about current wifi network
WIFI_NETWORK=`networksetup -getairportnetwork en0 | grep 'Current Wi-Fi Network' | cut -c 24-`
WIFI=No
if [[ "$WIFI_NETWORK" != "" ]]
then
WIFI=Yes
fi
# networksetup -getinfo Wi-Fi
server="10.0.1.250"
# Work out if specified server is reachable
REACHABLE=No
ping -c1 -W1 -q $server &>/dev/null
status=$( echo $? )
if [[ $status == 0 ]] ; then
REACHABLE=Yes
fi
echo On AC Power: $AC_POWER
echo On Wifi: $WIFI
echo Wifi Network: $WIFI_NETWORK
echo Server Reachable: $REACHABLE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment