Useful Scripts

From WTFwiki
Revision as of 16:28, 14 January 2019 by Anexit (talk | contribs)
Jump to navigation Jump to search

Script to check a file with hosts in that file. We will be using the ping command, if we can't ping the host we can do some magic;

Lets say the file guardfile.txt contains 1.1.1.1

#!/bin/sh
cat /usr/home/anexit/guard/guardfile.txt | while read line
do
if [ ! -z $line ]; then
PINGCOUNT=2
PING=$(ping -c $PINGCOUNT $line | grep received | cut -d ',' -f2 | cut -d ' ' -f2)
if [ $PING -eq 0 ]; then
echo "Attempting to establish connection..: $line"
sh /etc/netstart
sh /etc/rc.local

else
echo "Connection is live.: $line"
fi
fi
done

This script was used as a con job when using the an ssh tunnel. SSH supports tunnels but when they crash there is no mechanism at the time of this writing to keep or bring interfaces back online. Man SSH and look for;

SSH-BASED VIRTUAL PRIVATE NETWORKS

Theory;

Ping a host, if ping is ok do nothing, if ping fails do something. In this case we bring up all the tun interfaces using netstart and rc.local and reload.