-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatchdog.sh
More file actions
32 lines (23 loc) · 770 Bytes
/
watchdog.sh
File metadata and controls
32 lines (23 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
# Ping to get ART table (in case there were no activity for some time)
/sbin/ping -t 1 255.255.255.255
# Scan network and find UG (U - Up, G - Gateway)
netstat=$(/usr/sbin/netstat -nr | grep UG)
# Get only IP address
gatewayip=$(echo $netstat | cut -d ' ' -f 2)
# Get gateway's MAC address
arpoutput=$(echo "/usr/sbin/arp -an | grep '($gatewayip)'")
arpgateway=$(eval $arpoutput)
gatewaymac=$(echo $arpgateway | cut -d ' ' -f 4)
# Check if gateway MAC addres is empty
# => you are offline
if [ "$gatewaymac" == "" ]
then
gatewaymac="0:00:00:00:00:00"
fi
# Get timestamp
timestamp=`date +%Y%m%d%H%M`
# Create input string (what will be witten to a file)
input=$timestamp#$gatewaymac
# Write to file
echo $input >> /path/to/txt/file.txt