-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckConnection
More file actions
executable file
·36 lines (30 loc) · 876 Bytes
/
checkConnection
File metadata and controls
executable file
·36 lines (30 loc) · 876 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
33
34
35
36
#!/bin/bash
#
# Author: Artur O. Commander.Alchemy@gmail.com (Justice @ Freenode #Archlinux)
# Description:
# Checks for connection status to host.
# Uses sendmsg to send desktop notification
log=~/.connectionstatus.log
host=8.8.8.8
# Check connection to host
check_connection() {
ping -c 4 -n -q "$host" > /dev/null
response=$?
if [[ $response = 0 ]]; then
echo "$(date)" " Connection established to "$host"" >> "$log"
sendmsg "Connection establsihed to "$host"" "Connection Status"
else
echo "$(date)" " Connection failed to "$host"" >> "$log"
sendmsg "Connection failed to "$host"" "Connection Status"
fi
}
# Create log if it does not exist
create_log() {
if [[ ! -a $log ]]; then
echo "no "$log" found, generating a new one"
echo "Log generated automatically" "$(date)" > "$log"
fi
}
create_log
check_connection
exit 0