-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestping
More file actions
executable file
·42 lines (37 loc) · 904 Bytes
/
testping
File metadata and controls
executable file
·42 lines (37 loc) · 904 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
37
38
39
40
41
42
#!/bin/bash
#special strings allow color in terminal
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
if [[ $# -eq 0 ]]; then
echo "Please enter filename as argument"
exit 1
fi
file=$1
status_good="${green}online ${reset}"
status_bad="${red}offline ${reset}"
format="normal"
if [[ $# -eq 2 && $2 = "yesnoformat" ]]; then
format="yesno"
status_good="Yes"
status_bad="No"
fi
#loop through first words of each line, before ' ' symbol
for computer in $(cut -d ',' -f1 $file); do
computer="${computer/\"}"
#ping -c 1 only does 1 packet and only care about exit status not output
# -w 1 only waits 1 second per ping
ping -c 1 -w 1 $computer > /dev/null 2>&1
result=$?
status=""
if [ $result = "0" ]; then
status=$status_good
else
status=$status_bad
fi
if [ "$format" = "yesno" ]; then
echo -e "$status"
else
echo -e "$computer: $status"
fi
done