#!/bin/bash url="http://unappel.ch/public/090309-support-answers/code/current.zip" dir="/root/folders/090309-imap-stats" cd $dir if [ `pwd` = $dir ] then echo "[$0]" working folder found else echo "[$0]" not in working folder exit fi if [ -f current.zip ] then echo "[$0]" removing the previous version rm current.zip else echo "[$0]" .. fi if [ -f current.zip ] then echo "[$0]" cannot remove the old package exit fi /usr/bin/wget $url if [ -f current.zip ] then echo "[$0]" script is downloaded else echo "[$0]" script is not downloaded exit fi if [ -d script ] then echo "[$0]" deleting the old script folder rm -r script fi if [ -d script ] then echo "[$0]" cannot delete the old script folder exit fi mkdir script if [ -d script ] then echo "[$0]" .. else echo "[$0]" cannot access script folder exit fi /usr/bin/unzip current.zip -d script if [ -f script/run.pl ] then echo "[$0]" perl script is extracted else echo "[$0]" cannot extract the perl script exit fi cd script /usr/bin/perl run.pl >> ../std.log 2>> ../err.log cd .. tail -2000 std.log > last.std.log rm std.log mv last.std.log std.log tail -2000 err.log > last.err.log rm err.log mv last.err.log err.log date >> std.log date >> err.log echo "[$0]" end of reporting