projects
/
shutils.git
/ blob
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
Add ifonline
[shutils.git]
/
ifonline
1
#!/bin/sh
2
3
usage
() {
4
cat
<< EOF
5
Usage:
6
$0
[OPTIONS]
7
$0
-h
8
$0
-c "echo 'online'"
9
10
OPTIONS:
11
-h Show this text
12
-c CMD Command to execute if online
13
EOF
14
}
15
16
CMD
=
""
17
18
while
getopts
"hc:"
OPTION
;
do
19
20
case
"
$OPTION
"
in
21
h
)
22
usage
23
exit
24
;;
25
c
)
26
CMD
=
$OPTARG
27
;;
28
esac
29
done
30
31
if
[
-z
"
$CMD
"
];
then
32
echo
"No command given."
33
usage
34
exit
2
35
fi
36
37
if
ping
-c1
8.8.8.8 2
>&
1
>/
dev
/
null
;
then
38
$CMD
39
fi