Monday, May 23, 2011

Check Today's and Tomorrow's temperature - Skopje R. Macedonia

For all who lives in Skopje, R.Macedonia:

#!/bin/sh
#export http_proxy=
fajl=`wget -q -O temp.vreme http://www.weather.com/weather/today/Skopje+Macedonia+MKXX0001`
denes=`cat temp.vreme | grep Today | grep Column | cut -d "\"" -f 2 | cut -d " " -f 1`
noke=`cat temp.vreme | grep Tonight | grep Column | cut -d "\"" -f 2 | cut -d " " -f 1`
utre=`cat temp.vreme | grep Tomorrow | grep Column | cut -d "\"" -f 2 | cut -d " " -f 1`
temperatura_utre_f=`cat temp.vreme | grep $utre | grep forecast-temperature\" | cut -d ">" -f 3 | cut -d "&" -f 1`
temperatura_utre_c=`echo "(5.0 / 9.0) * ($temperatura_utre_f -32)" | bc -l | cut -d "." -f1`

temperatura_denes_f=`cat temp.vreme | grep $denes | grep forecast-temperature\" | cut -d ">" -f 3 | cut -d "&" -f 1`
temperatura_denes_c=`echo "(5.0 / 9.0) * ($temperatura_denes_f -32)" | bc -l | cut -d "." -f1`
temperatura_noke_f=`cat temp.vreme | grep $noke | grep forecast-temperature\" | cut -d ">" -f 3 | cut -d "&" -f 1`
temperatura_noke_c=`echo "(5.0 / 9.0) * ($temperatura_noke_f -32)" | bc -l | cut -d "." -f1`
zenity --info --title "Vremesnka Prognoza - Skopje, Makedonija" --text "Utre: $temperatura_utre_c stepeni \nDenes: $temperatura_denes_c stepeni\nNokeska: $temperatura_noke_c stepeni"
#echo Temperaturata utre ke bide $temperatura_utre_c stepeni
rm temp.vreme

Friday, May 20, 2011

Make "stable" CCcam



One who is using CCcam know that usually CCcam after some time generate segmentation fault so there is no more active soft-cam reader in your linux based STB, and even you have your subscription card inside STB, you'll get black screen. Therefore you must re-start CCcam manualy. Other solution is to use following script which will check every 10 seconds if CCcam is running.



#!/bin/sh
while :
do
proces=`ps -A | grep CCcam | cut -f2 -d " "`
if [ -z $proces ]
then
/var/bin/CCcam &
sleep 5
fi
sleep 10
done

Wednesday, May 18, 2011

NAGIOS plugin - Check for number of active users on Windows Terminal Server

Following is NAGIOS plugin (windows batch script) which check for number of logon users on Windows Terminal Server. Plugin is useful to create statistic so later you can check and plan if you need one more Terminal server in your TS farm :)

Here is the code:

@set norm=%1
@set warn=%2
@set crit=%3
@echo %norm% , %warn% , %crit%
@for /f "delims=" %%a in ('"query user | find /C /v"USERNAME""') do @set brojka=%%a
@if %brojka% LEQ %norm% goto :zeleno
@if %brojka% LEQ %warn% goto :zolto
@if %brojka% GEQ %crit% goto :crveno
:zeleno

@echo OK, %brojka% Users
@echo "|currentloggedusers=%brojka%

:crveno
@echo CRITICAL, %brojka% Users
@echo "|currentloggedusers=%brojka%

:zolto
@echo WANRNING, %brojka% Users
@echo "|currentloggedusers=%brojka%

Solaris shell script for parsing large XML file into multiple XML files. Create PDF and prepare meta data for email sending mechanism

This script I wrote because billing system in my company produces complex and big XML output - 1 file with multiple invoices inside. Request from business department was to split this large file into multiple XML files - one file per invoice. In same time, header and footer section from large XML must be merged into every single small file. Main goal is to create PDF invoice file and send it as attachment by email using customer's email address.

After splitting process, every file should be used as input for generating PDF file. For generating PDF file from XML I am using DETEC's product "LaserSoft". At top of all, meta data file should be created with email client address extracted from XML file and name of PDF file generated for that invoice. This meta data file will be used later in post process of sending PDF file to customer's email address.




[quote]
#!/bin/sh
rm /u01/app/company/fileio/billing/efakturi/meta.txt
input_fajl=$1
red=0
sleden_red=0
broj_linii=`cat $input_fajl | /usr/xpg4/bin/grep -n '' | cut -d ":" -f 1`
pocetok_footer=`cat $input_fajl | /usr/xpg4/bin/grep -n '' | cut -d ":" -f 1`
cat $input_fajl | /usr/xpg4/bin/grep -n ''| cut -d ">" -f2 | cut -d "<" -f 1 > ./tmp/kunde
nawk -v pocetok_footer="$pocetok_footer" -v krajna_linija="$krajna_linija" 'NR== pocetok_footer,NR== krajna_linija' $input_fajl > ./tmp/footer
nawk -v kraj_header="$kraj_header" 'NR==1,NR== kraj_header' $input_fajl > ./tmp/ header
while [ $broj_linii -gt 0 ]
do
red=$red+1
sleden_red=$red+1
linija=`awk 'NR=='$red ./tmp/client_pocetoci`
sledna_linija=`awk 'NR=='$sleden_red ./tmp/client_pocetoci`
kunde=`awk 'NR=='$red ./tmp/kunde`
if [ $broj_linii -eq 1 ]
then
sledna_linija=`cat $input_fajl | /usr/xpg4/bin/grep -n '' | c ut -d ":" -f 1 | tail -1`
fi
taman=`expr $sledna_linija - 1`
cat ./tmp/header > ./xml/$kunde.xml
nawk -v linija="$linija" -v taman="$taman" 'NR== linija,NR== taman' $input_fajl | /usr/xpg4/bin/grep -v '' | cut -d ">" -f2 | cut -d "<" -f 1 | grep -n '@' | cut -d ":" -f 2`
perl -pi -e s/"$izbrisi"/""/g ./xml/$kunde.xml
/opt/detec/lsoft/bin/lsmain -Q LS_PDF_FILE <./xml/$kunde.xml >./tmp/1
echo $adresa",e"$kunde.pdf >> /u01/app/company/fileio/billing/efakturi/meta.txt
pomal=$broj_linii
broj_linii=`expr $broj_linii - 1`
done


[/quote]

Check GMAIL for new messages:

Here is small simple shell script for checking if there is new message arrived in your GMAIL inbox. It will show popup GUI window in your KDE GUI environment:


#!/bin/sh
user= # Enter your GMAIL username here
pass= # Enter your password
stara=0
# export https_proxy=IP:PORT # If you are using proxy, set it up here
while :
do
novi=`wget -T 3 -t 1 -q --secure-protocol=TLSv1 --no-check-certificate --user=$user --password=$pass https://mail.google.com/mail/feed/atom -O - | grep "fullcount" | cut -d ">" -f 2 | cut -d "<" -f 1`
if [ $novi -ne $stara ]
then
stara=$novi
zenity --info --title "Gmail Check" --text "You have $novi new messages"
fi
sleep 5
done

Note that if you want to run this in background, then you can choose one of two ways:

1. Insert it into crontab
2. Run it in background.