motd.sh 2.45 KB
Newer Older
Lukáš Krupčík's avatar
Lukáš Krupčík committed
1 2 3 4 5
#!/bin/bash

### MOTD and Downtime history
# autor: kru0052
# 2016 IT4Innovations
Lukáš Krupčík's avatar
update  
Lukáš Krupčík committed
6
# version 1.0
Lukáš Krupčík's avatar
Lukáš Krupčík committed
7 8
###

Lukáš Krupčík's avatar
Lukáš Krupčík committed
9 10 11
printf "update"
wget -q  http://www.it4i.cz/support/?lang=en
printf " ... OK\n"
Lukáš Krupčík's avatar
Lukáš Krupčík committed
12 13 14 15 16 17 18 19 20

i="index.html?lang=en"

HEAD=$(grep -n -m1 'class="matrix light-grey' "$i" |cut -f1 -d: | tr --delete '\n')
END=$(grep -n -m1 '<h3>Other</h3>' "$i" |cut -f1 -d: | tr --delete '\n')
LAST=$(wc -l "$i" | cut -f1 -d' ')
DOWN=$((LAST-END+2))

sed '1,'"$((HEAD-1))"'d' "$i" | sed -n -e :a -e '1,'"$DOWN"'!{P;N;D;};N;ba' | sed '/<div/d' > "TMP.html"
Lukáš Krupčík's avatar
Lukáš Krupčík committed
21
rm "/srv/downtime/$i"
Lukáš Krupčík's avatar
Lukáš Krupčík committed
22 23 24

title="Message of the day"
head=$(cat TMP.html | grep "rss-item-title" | cut -d ">" -f 2 | cut -d "<" -f 1)
Lukáš Krupčík's avatar
Lukáš Krupčík committed
25
date=$(cat TMP.html | grep "<i>" | cut -d ">" -f 2 | cut -d "<" -f 1 | cut -d " " -f 1)
Lukáš Krupčík's avatar
Lukáš Krupčík committed
26
info=$(cat TMP.html | grep "<p>" | cut -d ">" -f 2 | cut -d "<" -f 1)
Lukáš Krupčík's avatar
Lukáš Krupčík committed
27
rm /srv/downtime/TMP.html
Lukáš Krupčík's avatar
Lukáš Krupčík committed
28

Lukáš Krupčík's avatar
Lukáš Krupčík committed
29
echo ""
Lukáš Krupčík's avatar
Lukáš Krupčík committed
30
echo "$title"
31
echo "$date - $head"
Lukáš Krupčík's avatar
Lukáš Krupčík committed
32 33
echo "$info"
echo ""
Lukáš Krupčík's avatar
Lukáš Krupčík committed
34

Lukáš Krupčík's avatar
Lukáš Krupčík committed
35
# poovolene stavy - Salomon Maintenance, Anselm Maintenance, Back in Production, Infrastructure Maintenance, PBS Maintenance, SCRATCH Maintenance, HOME Maintenance, Salomon and Anselm Maintenance
36
if [ "$head" = "Salomon Maintenance" ] || [ "$head" = "Anselm Maintenance" ] || [ "$head" = "Back in Production" ] || [ "$head" = "Infrastructure Maintenance" ] || [ "$head" = "PBS Maintenance" ] || [ "$head" = "SCRATCH Maintenance" ] || [ "$head" = "HOME Maintenance" ] || [ "$head" = "Salomon and Anselm Maintenance" ]; then
Lukáš Krupčík's avatar
Lukáš Krupčík committed
37 38 39 40 41
	dateDown=$(cat /srv/downtime/docs/index.md | sed -n '/---/{n;p;}' | cut -d "|" -f 2 | cut -d " " -f 1)
	headDown=$(cat /srv/downtime/docs/index.md | sed -n '/---/{n;p;}' | cut -d "|" -f 3 | cut -d "*" -f 3)	

	echo "$date - $dateDown"

Lukáš Krupčík's avatar
Lukáš Krupčík committed
42 43

	if [ "$date" = "$dateDown" ] && [ "$head" = "$headDown" ]; then
44
		echo "Everything up-to-date..."
Lukáš Krupčík's avatar
Lukáš Krupčík committed
45
	else
46
		echo "Updating Downtime History..."
Lukáš Krupčík's avatar
Lukáš Krupčík committed
47 48 49 50
		test=" |$date 00:00:00|**$head** $info|"
		sed '/---/a '"$test"'' /srv/downtime/docs/index.md > /srv/downtime/TMP.md
		cat /srv/downtime/TMP.md > /srv/downtime/docs/index.md
	#	rm /srv/downtime/TMP.md
Lukáš Krupčík's avatar
Lukáš Krupčík committed
51
	fi
Lukáš Krupčík's avatar
Lukáš Krupčík committed
52 53 54 55
	
#	echo "### $title" > docs/index.md
#	echo "**$head**" >> docs/index.md
#	echo "$date - $info" >> docs/index.md
56 57
else
	echo "Downtime History not updated..."
Lukáš Krupčík's avatar
Lukáš Krupčík committed
58
fi
Lukáš Krupčík's avatar
Lukáš Krupčík committed
59 60 61 62 63 64 65 66 67 68 69

       echo "# $title" > docs/motd.md
       echo "**$head**" >> docs/motd.md
       echo "$date - $info" >> docs/motd.md

time=$(date)

sed '$d' /srv/downtime/docs/index.md > /srv/downtime/TMP.md
cat /srv/downtime/TMP.md > /srv/downtime/docs/index.md
rm /srv/downtime/TMP.md
echo "updating $time" >> /srv/downtime/docs/index.md