-
Notifications
You must be signed in to change notification settings - Fork 1
/
bash.sh
executable file
·45 lines (34 loc) · 1.47 KB
/
bash.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
#! /bin/bash
REPEATS=4
if [ -e ~/.conky_csd/cache/announcements.php ]; then
rm -f ~/.conky_csd/cache/announcements
fi
mkdir -p ~/.conky_csd/cache
wget -q http://www.csd.auth.gr/announcements.php -O ~/.conky_csd/cache/announcements
# test if file announcements exists.
if [ ! -f ~/.conky_csd/cache/announcements ]; then
echo "There is not internet connection"
exit 1
fi
LOOP=1
ID=`tail -n 60 ~/.conky_csd/cache/announcements | grep "<ul><li><a href=\"" | awk '{ print $2 }' | cut -c 35-37`
if [ -f ~/.conky_csd/cache/last_announcementID ]; then
if [ $ID -gt `cat ~/.conky_csd/cache/last_announcementID` ] ; then
echo `date +%j` > ~/.conky_csd/cache/last_announcementDate
echo $ID > ~/.conky_csd/cache/last_announcementID
fi
else
echo `date --date='11 days ago' +%j` > ~/.conky_csd/cache/last_announcementDate
echo $ID > ~/.conky_csd/cache/last_announcementID
fi
COUNTER=1
while [ $LOOP -le $REPEATS ]; do
echo -n $LOOP": "
let "LOOP+=1"
VAR=`tail -n 60 ~/.conky_csd/cache/announcements | grep "<ul><li><a href=\""`
echo `echo $VAR | awk -v i=$COUNTER 'BEGIN {flag = "true"} { i++; while( match(flag,"true")) { if (match($i, "</a></li><li><a")) flag = "false"; print $i ; i++; if (i>100) flag="false" }}' ` | cut -c 40-1000 | sed 's/[a-z,<,/,>]*//g'
#echo counter=$COUNTER
COUNTER=`echo $VAR | awk -v i=$COUNTER 'BEGIN {flag = "true"} { i++; while( match(flag,"true")) { if (match($i, "</a></li><li><a")) flag = "false"; i++;} print i }'`
let COUNTER=COUNTER-1
done
echo