-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscan-office.sh
executable file
·40 lines (33 loc) · 1.02 KB
/
scan-office.sh
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
#!/bin/bash
source env.sh
# people who have been sent a message, flushed daily
touch pinged.out
# scan network
sudo nmap -sP 192.168.1.* > nmap.out
# checked in slack users
wget --quiet -O- $usersEndpoint | jq '.[] | select(.atOffice) | .slack' | sed 's/"//g' > checked-in.out
function slack {
escapedText=$(echo $1 | sed 's/"/\"/g' | sed "s/'/\'/g" | sed 's/+/%2b/g' )
json="{\"channel\": \"@$2\", \"text\": \"$escapedText\", \"username\": \"$slackName\", \"icon_emoji\": \"$slackIcon\"}"
curl -s -d "payload=$json" $slackEndpoint
}
function checkUser {
echo Checking $1 for $2
if grep -iq "$1" nmap.out; then
echo $2 " is in the office"
if ! grep -iq "^$2$" checked-in.out; then
echo $2 " is not checked in"
if ! grep -q "^$2$" pinged.out; then
echo $2 " is not pinged yet"
echo $2 >> pinged.out
result=$(curl --silent --data "user_name=$2" $checkEndpoint)
slack "Welcome to the office! $result" $2
fi
fi
fi
}
while read line; do
if [ -n "${line}" ]; then
checkUser $line
fi
done < users.list