-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslg-client.sh
executable file
·53 lines (47 loc) · 1.29 KB
/
slg-client.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
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
base_url="http://slg.kurtkraut.net/api"
content_from_server=$(mktemp)
content_from_task=$(mktemp)
version="0.1"
### Functions ###
clioutput ()
{
#Adds timestamps to message. Used for default CLI output.
time=$(date +%X)
echo "($time) $*"
}
mtrtask ()
{
mtr --raw --no-dns -c 3 $2 > $content_from_task
if test $? -eq 0
then
clioutput "Sending results of $1 to central server."
wget --user-agent="slg-client v$version" --base="$base_url/incoming.php" --post-file="$content_from_task"
else
clioutput "mtr exited with an error. See output above."
fi
}
### Procedural Logic ###
#Fetching the jobs list.
clioutput "Querying central server for more jobs."
wget --quiet --user-agent="slg-client v$version" --output-document=$content_from_server --timeout=30 $base_url/jobs.php
#Parsing the jobs list from the central server.
while read line
do
param1=$(echo $line | cut -d"," -f 1)
param2=$(echo $line | cut -d"," -f 2)
param3=$(echo $line | cut -d"," -f 3)
if test $param1 = "0"
then
clioutput "No jobs to be done. Exiting."
exit 0
fi
if test $param2 = "mtr"
then
clioutput "Found mtr job ($param1) to target $param3. Performing it right now."
mtrtask $param1 $param3
fi
done < $content_from_server
#Cleaning temporarying files
rm -f $content_from_server
rm -f $content_from_task