Image

Image

Search This Blog

Sunday, November 06, 2011

IP Changing notification

Because sometimes the dyndns updater goes to hell, a little crontab script executed every couple of hours it's a life saver:

#!/bin/sh
#
# Send an email message to notify about the external IP.
#

#set a file where we can store the ip
logfile=/var/log/extip
#to whom we send the email
recipient="my_account@provider.tld"
#if we are using an external smtp relay
smtp=relay.smtp.provider.tld
export smtp=$smtp
#put a nice sender address on the email
sender="IP Checker <ipcheck@server.tld>"
#find the name of of this server
HOSTNAME=`hostname -a | cut -f1 -d" "`
# format a nice subject
subj="Change of IP on $HOSTNAME"
#now let's get the external ip
ip=`/usr/bin/lynx -dump 'http://whatismyip.org'`
#and create a message body
mesg="$HOSTNAME IP address on `date  +%a' '%b' '%e' '%H.%M.%S' '%Z' '%Y` is $ip"
#see if the ip has changed
oldip=`cat $logfile`
#or if the last message has been sent more than one week ago
age=`find $logfile -mtime +7`

if [ ! "$oldip" == "$ip" ] || [ ! "$age" == "" ]
then
 #keep the new ip into the logfile

 echo $ip &gt; $logfile
 #send email about it
 echo "$mesg" | mail -r"$sender" -s"$subj" "$recipient"
fi

exit 0


Of course, having an external web server, capable of running a little php script will allow us to replace http://whatismyip.org with our own webserver. The php script is really simple:


<?php
$ip = getenv('REMOTE_ADDR');
#$ip = $_SERVER['REMOTE_ADDR'];
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
' . $ip . '
</body>
</html>';
?>

Sunday, October 16, 2011

Sunday, August 07, 2011

AUTOTBACK 3.0

A new version of the backup utility.
This is an evolution of the old AUTOTBACK script.
If the script is called without any command-line parameters it will check if "dialog" is installed on the system and it will start the "semi-graphical" interface, otherwise it will display the "usage parameters" and it will exit.

 The command line parameters are still the same:
$autotback ACTION DIRECTORY ARCHIVE MAIL PRINTER, where
- ACTION is backup or restore
- DIRECTORY represent, in case of ACTION=backup the source (what we will backup), or the destination (where the backup will be restored) when ACTION=restore. The default value is "/".
- ARCHIVE represent the location of backup. It is usually the tape device (by default is /dev/st0), but it can also be a simple file (/mnt/disk/archive_name.cpio - if we use an external drive mounted on /mnt/disk)
 - MAIL represent the email address(es) that will receive the backup report. If more than one email address is required, then, on the command line, those must be surrounded by double quotes ("aa@bb.c dd@ee.f gg@hh.i"). The default emails are "backupreport@xxxxxxxx.com root@localhost"
-PRINTER represents the name of the printer used for the report. The default value is empty. The printer MUST be already installed on the system!

#!/bin/sh
#       @(#) AUTOTBACK 3.4 08/09/12
#
# 08/06/2012 (sorin@xxxxxxxx.com) add pre/post actions, embedd dialog
# 17/10/2011 (sorin@xxxxxxxx.com) modify to use tar
# 18/07/2011 (sorin@xxxxxxxx.com) add the restore section, add command-line parmeters
# 10/08/2010 (sorin@xxxxxxxx.com) autoremove lock after 8hrs and reenable backup. remove hit report
# 28/08/2008 (sorin@xxxxxxxx.com) modified for rhel5. skip /proc /sys /tmp. send mail with the result
# modified 9/14/2000 to provide hit reporting on web site
#
#  Usage: $0 backup /source /dev/destination email@notification.address (printer)
#               if no source nor destination is provided, / will be saved to /dev/st0
#         $0 restore /destination /dev/source email@notification.address (printer)
#  when restore is called, the script  will ask you to select a partial restore
#  by typing a file mask. Just type Enter to do a full restore.
#  if no destination is provided, the restore is performed on / from /dev/st0
#  All the reports and temp files are kept in the /var/autotback directory
#
#
# Exit Codes: 0 - OK
#   1 - [ESC] pressed
#   2 - A lockfile exists
#   3 - Can't create dir (am I root? is it /var mounted rw?)
#   
#

# If not provided on the commandline, set local Variables. Must specify at least the main action (backup/restore)
unset SRC DES REC PRN
#if [ "$1" = "" ]; then echo "Usage: $0 {backup|restore} (files) (archive) (email) (printer)"; fi # if dialog exists start anyway
if [ ! "$2" = "" ]; then SRC=$2; else SRC=/; fi
if [ ! "$3" = "" ]; then DES=$3; else DES=/dev/st0; fi
if [ ! "$4" = "" ]; then REC=$4; else REC="backupreport@xxxxxxxx.com root@localhost"; fi
if [ ! "$5" = "" ]; then PRN=$5; fi

# System variables
#PRECOMMAND='/bin/mount -t cifs -o guest //192.168.1.16/images /mnt'
#POSTCOMMAND='/bin/umount /mnt'
ARCHIVER=tar
DEFAULTDIR=/var/autotback
LOCK=$DEFAULTDIR/backlock
REPORTFILE=$DEFAULTDIR/backrep$$
TEMPFILE=$DEFAULTDIR/backtmp$$
TEMPFILE2=$DEFAULTDIR/backtemp$$
TEMPFILEV=$DEFAULTDIR/vertmp$$
TEMPFILEV2=$DEFAULTDIR/vertemp$$
LIST=$DEFAULTDIR/list$$
TITLE="AUTOTBACK 3.4"
BACKTITLE="A dialog driven backup utility  (press [ESC] twice to exit)"
INTERRUPT="echo -en [ESC] Pressed, exiting...  "
HEADER="Backup Report for $HOSTNAME
(c)1991-2012 xxxxxxxx Inc.
===============================================================================
`date`
"

#########################
# Define main functions #
#########################

########
# lock #
########

lock ()
{
# Check if another job is running
if [ -r $LOCK ]
then
    # if we have wall, announce the trouble
    if [ ! "$(whereis wall | cut -d: -f2)" = "" ]; then wall " We have a little issue with the BACKUP ! Please verify $DEFAULTDIR"; fi
    echo "`date` - Another job is running or the last backup did not finished well. Please check $DEFAULTDIR !" >> $REPORTFILE
    # check the age of the lockfile, if it is older then 23 hrs, chances are that nobody checked the log
    ((DIFF=`date +%s`-`cat $LOCK`))
    if [ $DIFF -gt 82800 ]; then echo "`date` - Lockfile more than 23 hours old, autocleaning... the backup will run!" >> $REPORTFILE; rm -f $LOCK; fi
    if [ -r $LOCK ]
    then
        if [ ! "$(whereis mail | cut -d: -f2)" = "" ]; then cat $REPORTFILE | mail -s "$0 Warning from $HOSTNAME" $REC 2>/dev/null; fi
        if [ "$PRN" = "" ]; then echo "Skip print, no printer defined" >> $REPORTFILE; elif [ ! "$(whereis lp |cut -d: -f2)" = "" ]; then lp -d $PRN $REPORTFILE; fi
        exit 2
    fi
fi

# Cleanup obsolete traces and create defaultdir
rm -rf $DEFAULTDIR 2> /dev/null
mkdir -p $DEFAULTDIR 2> /dev/null
if [ ! -d $DEFAULTDIR ] ; then echo "CAN'T MAKE $DEFAULTDIR"; exit 3; fi
touch $REPORTFILE $TEMPFILE $TEMPFILE2 $TEMPFILEV $TEMPFILEV2 $LIST

# Create lockfile
echo "`date +%s`">$LOCK
}

##################
# extract dialog #
##################

extract_dialog ()
{
# If dialog is not in path and the system is linux - !!! TBD - NOT USED IN v3.4 !!!
if [ ! "`uname -a | grep Linux`" == "" ]; then
    echo "Dialog not found, Do you want to try to extract our own dialog? y/n"
    read extract
    if [ "$extract" = "y" ] || [ "$extract" = "Y" ]; then 
     # Find the tar archive at the end of this script. It starts after the line "---DEMARK---"
     # It was added there with a simple 'cat binary.tar.bz2 >> $this_script'
     binstart=`expr $(grep --text --line-number '^---DEMARK---$' $0 | cut -f1 -d:) + 1`
     # Extract the tar archive on /tmp
     tail -n +$binstart $0 | tar -C/tmp -xjvf -
    fi
fi
}

#####################
# graphic interface #
#####################

void ()
{
# Make the TERM display white on blue
setterm -clear all -foreground white -background blue 

# Check if another job is running
lock

# present the user the choice of backup, resctore or scheduler
dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel --menu "Choose an Option" 11 30 3 1 "Create a Backup" 2 "Restore from Backup" 3 "Schedule a Backup" 2>/tmp/input.$$
sel=$?
choice=`cat /tmp/input.$$`
rm -f /tmp/input.$$
case $sel in
    0)
    if [ "$choice" = "1" ]; then 
 #dialog choose what, where, to backup, to whom we send email, where we print (if we print)
 dialog --title "$TITLE (SPACE to select what to save)" --backtitle "$BACKTITLE" --nocancel \
 --fselect "/" 12 46 2>/tmp/input.$$
        sel=$?
        SRC=`cat /tmp/input.$$`
        rm -f /tmp/input.$$
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK && exit 1;;
        esac
 dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel \
 --inputbox "Select the destination device" 8 25 /dev/st0 2>/tmp/input.$$
        sel=$?
        DES=`cat /tmp/input.$$`
        rm -f /tmp/input.$$
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK && exit 1;;
        esac
 dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel \
 --inputbox "Type the notification emails" 8 47 "backupreport@xxxxxxxx.com root@localhost" 2>/tmp/input.$$
        sel=$?
        REC=`cat /tmp/input.$$`
        rm -f /tmp/input.$$
        REC=\"$REC\"
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK &&  exit 1;;
        esac
 dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel \
 --inputbox "Type the Printer name (if any)" 8 25 2>/tmp/input.$$
        sel=$?
        PRN=`cat /tmp/input.$$`
        rm -f /tmp/input.$$
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK && exit 1;;
        esac
 dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel \
        --infobox "Performing the Backup procedure. Please wait..." 6 25
        # call the backup function with the right command line options. Remove lock before
 rm -f $LOCK && backup
    fi
    
    if [ $choice = 2 ]; then 
        ##dialog choose where to restore, from where, to whom we send email, where we print (if we print)
 dialog --title "$TITLE (SPACE to select where to save)" --backtitle "$BACKTITLE" --nocancel \
 --fselect "/" 12 47 2>/tmp/input.$$
        sel=$?
        SRC=`cat /tmp/input.$$`
        rm -f /tmp/input.$$
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK && exit 1;;
        esac
 dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel \
 --inputbox "Select the source device" 8 25 /dev/st0 2>/tmp/input.$$
        sel=$?
        DES=`cat /tmp/input.$$`
        rm -f /tmp/input.$$
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK && exit 1;;
        esac
 dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel \
 --inputbox "Type the notification emails" 8 47 "backupreport@xxxxxxxx.com root@localhost" 2>/tmp/input.$$
        sel=$?
        REC=`cat /tmp/input.$$`
        rm -f /tmp/input.$$
        REC=\"$REC\"
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK &&  exit 1;;
        esac
 dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel \
 --inputbox "Type the Printer name (if any)" 8 25 2>/tmp/input.$$
        sel=$?
        PRN=`cat /tmp/input.$$`
        rm -f /tmp/input.$$
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK && exit 1;;
        esac
 dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel \
        --infobox "Performing the Restore procedure. Please wait..." 6 25
        # call the restore function with the right command line options. remove lock before
        rm -f $LOCK && restore
    fi

    if [ $choice = 3 ]; then 
 # before schedule a new backup, check is there is another one already programmed
 myname=`echo $0 | sed -e's/\.\///'` # Remove ./ from $0
 if [ ! `crontab -l | grep -c $myname` = 0 ]; then 
 dialog --title "$TITLE" --backtitle "$BACKTITLE" --yes-label "Keep" --no-label "Delete" --yesno "A backup is alredy scheduled, What do you want to do with it? \n `crontab -l | grep $myname`" 10 46
 sel=$?
        case $sel in
        0) # keep the old scheduled backups in crontab, nothing to do
        ;;
        1)
        # delete old backup from crontab
 crontab -l | sed -e "/$myname/d" > /tmp/tmpcron.$$
        /usr/bin/crontab < /tmp/tmpcron.$$
        rm -f /tmp/tmpcron.$$
        ;;
        255) $INTERRUPT && rm -f $LOCK && exit 1;;
        esac
 fi

 ##start to schedule. choose days of week (MON-FRI preselected)
        dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel --checklist "Choose days of Backup (Use SPACE to select)" 18 26 12 0 Sunday off 1 Monday on 2 Tuesday on 3 Wednesday on 4 Thursday on 5 Friday on 6 Saturday off --and-widget 2>/tmp/input.$$
        sel=$?
        sed -i -e 's/\"//g' -e 's/\ /\,/g' /tmp/input.$$
        week=`cat /tmp/input.$$`
        rm -f /tmp/input.$$
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK && exit 1;;
        esac
 ##choose time of backup (23:30 seems to be a good default choice)
        dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel --timebox "Choose time for Backup (Use arrows to modify)" 5 26 23 30 00 2>/tmp/input.$$
        sel=$?
        hr=`cat /tmp/input.$$ | cut -f1 -d:`
        min=`cat /tmp/input.$$ | cut -f2 -d:`
        rm -f /tmp/input.$$
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK && exit 1;;
        esac

        # choose what, where, to whom we send email, where we print (if we print)
 dialog --title "$TITLE (SPACE to select what to save)" --backtitle "$BACKTITLE" --nocancel \
 --fselect "/" 12 46 2>/tmp/input.$$
        sel=$?
        SRC=`cat /tmp/input.$$`
        rm -f /tmp/input.$$
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK && exit 1;;
        esac
 dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel \
 --inputbox "Select the destination device" 8 25 /dev/st0 2>/tmp/input.$$
        sel=$?
        DES=`cat /tmp/input.$$`
        rm -f /tmp/input.$$
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK && exit 1;;
        esac
 dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel \
 --inputbox "Type the notification emails" 8 47 "backupreport@xxxxxxxx.com root@localhost" 2>/tmp/input.$$
        sel=$?
        REC=`cat /tmp/input.$$`
        rm -f /tmp/input.$$
        REC=\"$REC\"
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK &&  exit 1;;
        esac
 dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel \
 --inputbox "Type the Printer name (if any)" 8 25 2>/tmp/input.$$
        sel=$?
        PRN=`cat /tmp/input.$$`
        rm -f /tmp/input.$$
        case $sel in
        0);;
        255) $INTERRUPT && rm -f $LOCK && exit 1;;
        esac

 #insert the line in crontab
        crontab -l > /tmp/tmpcrontab.$$
        echo "$min $hr * * $week $myname backup $SRC $DES $REC $PRN" >> /tmp/tmpcrontab.$$
        /usr/bin/crontab < /tmp/tmpcrontab.$$
        rm -f /tmp/tmpcrontab.$$
 dialog --title "$TITLE" --backtitle "$BACKTITLE" --nocancel \
        --infobox "New crontab is installed...\n `crontab -l | grep $myname`" 10 45
    fi
    ;;
    255) $INTERRUPT && rm -f $LOCK && exit 1;;
esac

# end of graphical part, restore TERM
setterm -default

# remove lock
sleep 1
rm $LOCK
}

###################
# backup & verify #
###################

backup ()
{

# Check if another job is running
lock

# Start backup
if [ ! "$PRECOMMAND" == "" ]; then
$PRECOMMAND >>$REPORTFILE
fi

echo "$HEADER 
Backup of $HOSTNAME started
The command line was: $0 backup $SRC $DES $REC $PRN
 ">>$REPORTFILE

# Start saving
cd $SRC
echo "Start WRITING $SRC to $DES on `date`">>$REPORTFILE 
# In any case exclude /proc /sys /tmp /mnt
if [ "$ARCHIVER" == "tar" ]
then 
 tar --verbose --exclude=/proc --exclude=/sys --exclude=/tmp --exclude=/mnt --totals -b2048 -cpvf $DES $SRC >>$TEMPFILE 2>$TEMPFILE2
else
 echo "Enumerating the list of files and removing special folders
 ">>$REPORTFILE
 find . -depth -print | grep -v "./sys/" | grep -v "./proc/" | grep -v "./tmp/" | grep -v "./mnt/" >$LIST
 cat $LIST | cpio -ocvB >$DES 2>>$TEMPFILE
fi
backstat=$?
echo "
Following are the last lines recorded during saving:" >>$REPORTFILE
tail $TEMPFILE | head -9 >>$REPORTFILE
tail -n1 $TEMPFILE >>$REPORTFILE
echo "
WRITE exit status = $backstat
">> $REPORTFILE
if [ $backstat -ne 0 ]
then
 if [ $backstat -eq 1 ]
 then
    echo "*** Backup may be incomplete or have missing files ***">>$REPORTFILE
 elif [ $backstat -eq 2 ]
 then
  if [ `grep "Error exit delayed from previous errors" $TEMPFILE2` ]
   then
    echo "*** Backup may be incomplete or have missing files ***">>$REPORTFILE
   else
    echo "*** Backup has encounter a fatal ERROR. Please check ***">>$REPORTFILE
   fi
 else
    echo "*** Backup may contain an ERROR ***">>$REPORTFILE
 fi
else
    echo "*** Backup COMPLETED OK ***">>$REPORTFILE
fi

echo "Tape WRITING completed on `date`">>$REPORTFILE

if [ ! "$ARCHIVER" == "tar" ]
then 
set `tail -1 $TEMPFILE | cut -d: -f2 | cut -d" " -f2`
BACKTOT=$1
else
BACKTOT=`grep "Total bytes" $TEMPFILE2 | cut -d: -f2 | cut -d" " -f2`
fi
echo "
Total of amount of saved bytes was $BACKTOT
">>$REPORTFILE

#Tape Verify
echo "Starting VERIFY on $DES `date`">>$REPORTFILE
if [ "$ARCHIVER" == "tar" ]
then 
 tar --verbose --exclude=/proc --exclude=/sys --exclude=/tmp --exclude=/mnt --totals -b2048 -tpvf $DES >>$TEMPFILEV  2>>$TEMPFILEV2
else
 cpio -icvtB <$DES >>$TEMPFILEV 2>>$TEMPFILEV2
fi
verstat=$?
echo "
Following are the last lines recorded during verify:" >>$REPORTFILE
tail $TEMPFILEV | head -9 >>$REPORTFILE
tail $TEMPFILEV2 | head -9 >>$REPORTFILE
echo "
VERIFY exit status = $verstat
">>$REPORTFILE
if [ $verstat -ne 0 ]
then
    echo "***  Verify may contain an ERROR ***
    ">>$REPORTFILE
fi
echo "Verify completed for $HOSTNAME on `date` 
">>$REPORTFILE
if [ ! "$ARCHIVER" == "tar" ]
then 
set `tail -1 $TEMPFILEV2 | cut -d: -f2 | cut -d" " -f2`
VERTOT=$1
else
VERTOT=`grep "Total bytes" $TEMPFILEV2 | cut -d: -f2 | cut -d" " -f2`
fi
echo "Total of amount of verified bytes was $VERTOT
">>$REPORTFILE

if [[ $backstat -ne 0 || ($verstat -ne 0 || "$BACKTOT" != "$VERTOT") ]]
then
 if [ $verstat -eq 1 ]
 then
    echo "***  Verify may be incomplete ***">>$REPORTFILE
 elif [ $verstat -eq 2 ]
 then
    echo "***  Verify has encounter a fatal ERROR. Please check ***">>$REPORTFILE
 else
    echo "***  The backup may contain an ERROR  ***">>$REPORTFILE
 fi
 # put a warning
 echo "***  WARNING!!! BACKUP TRANSFER TOTALS DID NOT MATCH  ***
***                   PLEASE VERIFY                   ***
">>$REPORTFILE
 # Send the report
 if [ ! "$(whereis mail | cut -d: -f2)" = "" ]; then cat $REPORTFILE | mail -s "Backup ERROR on $HOSTNAME" $REC 2>/dev/null; fi
else
 # Gives the OK
 echo "*** Transfer Totals Concur ***
">>$REPORTFILE
 # Send the report
 if [ ! "$(whereis mail | cut -d: -f2)" = "" ]; then cat $REPORTFILE | mail -s "Backup OK on $HOSTNAME" $REC 2>/dev/null; fi
fi
# Print the report
if [ "$PRN" = "" ]; then echo "Skip print, no printer defined" >> $REPORTFILE; elif [ ! "$(whereis lp |cut -d: -f2)" = "" ]; then lp -d $PRN $REPORTFILE; fi

# Eject if mt is installed
if [ ! "$(whereis mt |cut -d: -f2)" = "" ]; then mt -f $DES rewoffl; fi

# remove lock
sleep 1
rm $LOCK

if [ ! "$POSTCOMMAND" == "" ]; then
$POSTCOMMAND >>$REPORTFILE
fi
}

###########
# restore #
###########
restore ()
{
# Check if another job is running
lock

# Start restore
if [ ! "$PRECOMMAND" == "" ]; then
$PRECOMMAND >>$REPORTFILE
fi

echo "$HEADER Restore started on `date`
The command line was: $0 restore $SRC $DES $REC $PRN
Choosing the files to restore...">>$REPORTFILE

#choose the files to restore
echo "Type the name of the files you want to restore (CR = all the archive)
(ex: to restore everything from /etc/sysconfig type etc/sysconfi*):"
read RES

echo "Restoring $RES from $DES to $SRC." >> $REPORTFILE
mkdir -p $SRC 2>/dev/null
cd $SRC

if [ "$ARCHIVER" == "tar" ]
then 
 tar --exclude=/proc --exclude=/sys --exclude=/tmp --exclude=/mnt --totals -b2048 -xpvf $DES $RES >>$TEMPFILE 2>>$TEMPFILE2
else
 cpio -icvdmB $RES < $DES >>$TEMPFILE 2>>$TEMPFILE2
fi
resstat=$?

echo "RESTORE exit status = $resstat
">>$REPORTFILE

if [ $resstat -ne 0 ]
then
    echo "***  RESTORE may contain an ERROR ***
    ">>$REPORTFILE
fi

# Prepare the report
echo "Following are the special cases reported during restore:" >>$REPORTFILE
tail $TEMPFILE | head -9 >> $REPORTFILE
tail $TEMPFILE2 | head -9 >> $REPORTFILE
set `tail -1 $TEMPFILE2 | cut -d: -f2 | cut -d" " -f2`
RESTOT=$1
echo "Total of amount of restored bytes was $RESTOT
">>$REPORTFILE
# Send the report
if [ ! "$(whereis mail | cut -d: -f2)" = "" ]; then cat $REPORTFILE | mail -s "Restore report for $HOSTNAME" $REC 2>/dev/null; fi
# Print the report
if [ "$PRN" = "" ]; then echo "Skip print, no printer defined">> $REPORTFILE; elif [ ! "$(whereis lp |cut -d: -f2)" = "" ]; then lp -d $PRN $REPORTFILE; fi

# Eject if mt is installed
if [ ! "$(whereis mt |cut -d: -f2)" = "" ]; then mt -f $DES rewoffl; fi

# remove lock
sleep 1
rm $LOCK

if [ ! "$POSTCOMMAND" == "" ]; then
$POSTCOMMAND >>$REPORTFILE
fi
}

###################
# Starting script #
###################
case "$1" in
backup)
    backup;;
restore)
    restore;;
*)
# If it was called without parameters check if dialog exist and call the interface
    if [ "$(whereis dialog | cut -d: -f2)" = "" ]; then
    extract_dialog
     echo "Usage: $0 backup (source) (destination) (email) (printer)
     $0 restore (destination) (source) (email) (printer)     
     "
   else
    void
   fi
   ;;
esac

# ensure a safe exit
exit 0

---DEMARK---

Monday, July 11, 2011

rotate kde cube using the accelerometer

ain't that fun? tilt the laptop and the cube rotates :) all thanks to the ST LIS3LV02DL Accelerometer
#!/bin/bash
# kde-cube-rotate
#

while true ; do
# vertical axis
#POS1=`cat /sys/devices/platform/lis3lv02d/position | awk -F , '{print$2}'`
#sleep .1
#POS2=`cat /sys/devices/platform/lis3lv02d/position | awk -F , '{print$2}'`
#horizontal axis
POS1=`cat /sys/devices/platform/lis3lv02d/position | awk -F , '{print$1}' | awk -F "(" '{print$2}'`
#sleep .1
POS2=`cat /sys/devices/platform/lis3lv02d/position | awk -F , '{print$1}' | awk -F "(" '{print$2}'`

DIS=$( wmctrl -d | grep "*" | awk '{sub(/x[0-9]+/, "", $1); print $1}'| tail -n1)
((POS=$POS1-$POS2))

#echo "pos1=$POS1 pos2=$POS2 pos=$POS display=$DIS"

if [ $POS -ge 20 ]; then
wmctrl -s $(( ${DIS} - 1 )) 2>/dev/null
sleep 1

elif [ $POS -le -20 ]; then
wmctrl -s $(( ${DIS} + 1 )) 2>/dev/null
sleep 1

fi
done

Saturday, May 28, 2011

/etc/udev/rules.d/80-automount.rules

KERNEL=="sd[a-z]", NAME="%k", SYMLINK+="usb%m", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="usb%n", GROUP="users", NAME="%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /mnt/usb%n"
ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/lib/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,flush,quiet,nodev,nosuid,noexec,noatime,dmask=000,fmask=111 /dev/%k /mnt/usb%n", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/lib/udev/vol_id -t %N", RESULT=="ntfs", RUN+="/bin/mount -t ntfs-3g -o rw,noauto,flush,quiet,nodev,nosuid,noexec,noatime,dmask=000,fmask=111 /dev/%k /mnt/usb%n", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /mnt/usb %n", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /mnt/usb%n"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /mnt/usb%n", OPTIONS="last_rule"

Sunday, April 24, 2011

VPN to Sonicwall's Virtual Office

#!/bin/bash
# 2011/04/22 sorin@XXXXXXXX.com
# A script to start the Sonicwall netExtender and create the necessary routes
# Sonicwall's netExtender binary is available from the VirtualOffice web interface.
#
# Define variables. In the config file the data format is TAB separated as follow:
# username password domainname ExternalIP port
#testusr tespassword LocalDomain 123.45.67.89 443
#
# Alternatively, you can define $user $pass $dom $ip $port here

prog="/usr/sbin/netExtender"
conf="/etc/sysconfig/gvpn.conf"
log="/dev/null"
if [ ! -f $prog ]; then
echo "No binary - fatal!"
exit 2
fi
if [ ! -f $conf ]; then
echo "No config, trying to set some defaults"
user=testusr
pass=testpassword
dom=LocalDomain
ip=123.45.67.89
port=443
fi

# Let's see how this script has been called
case "$1" in
start)
# if we have a conf file read the data from there
if [ -f $conf ]; then val=`sed '/^ *#/d;s/#.*//' $conf`; read user pass dom ip port < <( echo $val ); fi echo -e "Starting $prog..." $prog -u $user -p $pass -d $dom $ip:$port & >$log 2>&1
sleep 3
# after a few seconds we can try to add the route, but first \
# if we're in the same IP range, die gracefully, otherwise add the route
routenet=`sudo ifconfig | grep P-t-P | cut -d: -f2 | cut -d. -f1-3` >$log 2>&1
grp=`sudo ifconfig | grep -v P-t-P | grep '$routenet.255'` >$log 2>&1
if [ -z "$grp" ]; then
# mac users does not have "dev" in route's options, so let's add the route via a gateway
# routedev=`sudo ifconfig | grep ppp | cut -dL -f1` >$log 2>&1
# sudo route add -net $routenet netmask 255.255.255.0 dev $routedev >$log 2>&1
newip=`sudo ifconfig | grep P-t-P | cut -d: -f2 | cut -d" " -f1` >$log 2>&1
sudo route add -net $routenet.0 netmask 255.255.255.0 gw $newip >$log 2>&1
else
echo "We are in the same IP range, can't assign a route to the remote network!"
$0 stop
exit 1
fi
;;
stop)
echo -e "Stopping $prog..."
# first let's bring down the ppp interface
routedev=`sudo ifconfig | grep ppp | cut -dL -f1` >$log 2>&1
sudo ifconfig $routedev down >$log 2>&1
# then ask the pogram to terminate
sudo killall $prog >$log 2>&1
sleep 5
# if netExtender is still alive after 5 sec, force kill
if [ `ps xau | grep -v grep | grep $prog | awk '{print $2}' | wc -l` -ne "0" ]; then
sudo killall -9 $prog >$log 2>&1
fi
;;
status)
if [ `ps xau | grep -v grep | grep $prog | awk '{print $2}' | wc -l` -ne "0" ]; then
echo "$prog running with pid(s) `ps xau | grep -v grep | grep $prog | awk '{print $2}' | tr '
' ', '`"
echo "Showing route via ppp devices..." ; sudo route | grep ppp | grep -v 255.255.255.255
else
echo "$prog NOT running"
fi
;;
restart)
$0 stop
sleep 3
$0 start
;;
*)
printf "Usage: %s\n" "$(basename $0) {start|stop|status|restart}"
exit 1
esac
exit 0

Tuesday, April 19, 2011

VT6421 IDE RAID Controller "hotswap"

#!/bin/bash
case "$1" in
start)
echo "Starting sata-via module..."
modprobe sata_via
echo "sleep 5 sec..."
sleep 5
lsmod | if grep sata_via; then echo -e "sata-via module \e[01;32mIS\e[00m inserted"; else echo -e "sata-via module \e[01;31mNOT\e[00m loaded"; fi
echo -e "Module inserted. HDD \e[01;32mavailable\e[00m"
cat /proc/partitions
;;
stop)
echo "Removing sata-via module..."
rmmod sata_via 2>/dev/null
echo "sleep 5 sec..."
sleep 5
lsmod | if grep sata_via; then echo -e "sata-via module \e[01;32mIS\e[00m inserted"; else echo -e "sata-via module \e[01;31mNOT\e[00m loaded"; fi
echo -e "Module removed. \e[01;32mSafe\e[00m to extract HDD."
cat /proc/partitions
;;
status)
lsmod | if grep sata_via; then echo -e "sata-via module \e[01;32mIS\e[00m inserted"; else echo -e "sata-via module \e[01;31mNOT\e[00m loaded"; fi
;;
restart|reload)
$0 stop
$0 start
;;
*)
printf $"Usage: %s {start|stop|restart|status}\n"
exit 1
esac

Saturday, March 05, 2011

clear tempfiles for winXP

usually I call this script at shutdown, gpedit.msc is the name!


@echo off

::Set Search directory to "Documents and Settings" folder
(Set Target=%AllUsersProfile:~0,-10%)

title,Finding the Temp subfolders in %Target%&COLOR 9E

If EXIST "%Target%",(
For /f "Tokens=*" %%* in ('dir "%Target%" /B') Do (
cd /D "%target%\%%*\Local Settings\Temp" && (
ATTRIB -S -H -R -A /D /S >nul & (
For /f "Tokens=*" %%* in ('dir /B') Do (
RD "%%*" /S /Q ||Del /F "%%*" )))>nul)
md "%target%\%%*\Local Settings\Temp"
)
If EXIST "%Target%",(
For /f "Tokens=*" %%* in ('dir "%Target%" /B') Do (
cd /D "%target%\%%*\Local Settings\Temporary Internet Files" && (
ATTRIB -S -H -R -A /D /S >nul & (
For /f "Tokens=*" %%* in ('dir /B') Do (
RD "%%*" /S /Q ||Del /F "%%*" )))>nul)
md "%target%\%%*\Local Settings\Temporary Internet Files"
)
If EXIST "%Target%",(
For /f "Tokens=*" %%* in ('dir "%Target%" /B') Do (
cd /D "%target%\%%*\Local Settings\history\history.ie5" && (
ATTRIB -S -H -R -A /D /S >nul & (
For /f "Tokens=*" %%* in ('dir /B') Do (
RD "%%*" /S /Q ||Del /F "%%*" )))>nul)
md "%target%\%%*\Local Settings\history\history.ie5"
)
If EXIST "%Target%",(
For /f "Tokens=*" %%* in ('dir "%Target%" /B') Do (
cd /D "%target%\%%*\Application Data\Sun\Java\Deployment\cache" && (
ATTRIB -S -H -R -A /D /S >nul & (
For /f "Tokens=*" %%* in ('dir /B') Do (
RD "%%*" /S /Q ||Del /F "%%*" )))>nul)
md "%target%\%%*\Application Data\Sun\Java\Deployment\cache"
)
If EXIST "%Target%",(
For /f "Tokens=*" %%* in ('dir "%Target%" /B') Do (
cd /D "%target%\%%*\Local Settings\Application Data\Apple Computer\QuickTime\downloads" && (
ATTRIB -S -H -R -A /D /S >nul & (
For /f "Tokens=*" %%* in ('dir /B') Do (
RD "%%*" /S /Q ||Del /F "%%*" )))>nul)
md %target%\%%*\Local Settings\Application Data\Apple Computer\QuickTime\downloads
)
If EXIST "%Target%",(
For /f "Tokens=*" %%* in ('dir "%Target%" /B') Do (
cd /D "%target%\%%*\Application Data\Macromedia\Flash Player" && (
ATTRIB -S -H -R -A /D /S >nul & (
For /f "Tokens=*" %%* in ('dir /B') Do (
RD "%%*" /S /Q ||Del /F "%%*" )))>nul)
md "%target%\%%*\Application Data\Macromedia\Flash Player"
)
For /f "Tokens=*" %%* in ('dir "%SystemRoot%\Temp" /B') Do (
cd /D "%SystemRoot%\Temp" && (
ATTRIB -S -H -R -A /D /S >nul & (
For /f "Tokens=*" %%* in ('dir /B') Do (
RD "%%*" /S /Q ||Del /F "%%*" )))>nul)
md "%SystemRoot%\Temp"

For /f "Tokens=*" %%* in ('dir "%SystemRoot%\prefetch" /B') Do (
cd /D "%SystemRoot%\prefetch" && (
ATTRIB -S -H -R -A /D /S >nul & (
For /f "Tokens=*" %%* in ('dir /B') Do (
RD "%%*" /S /Q ||Del /F "%%*" )))>nul)
md "%SystemRoot%\prefetch"
exit

Tuesday, January 18, 2011

Install Windows printers

' replacepr.vbs - Windows NT Logon Script. (c) 2008-2010 sorin@xxxxxxx Inc.
' VBScript - Silently remove ALL network printers, install new ones with default
' this script require 2 additional files: one defining the printers we need to
' install, one printer per line and a second file defining what default printer
' we use, depending on what IP range this computer belongs the format of this
' file is IP_Range, Default_Printer (IP_Range is defined as, ex: 10.0.IP_Range.9)
' -----------------------------------------------------------------------'

Dim printer, sServer, i, l, default
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNet = CreateObject("WScript.Network")
Set WshShell = CreateObject("WScript.Shell")
Set wmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set wmiNameSpace = wmiLocator.ConnectServer(objNet.ComputerName, "root\default")
Set objRegistry = wmiNameSpace.Get("StdRegProv")
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
strComputer = "."
'Define the server where printers reside
sServer = "\\sqlsrv"
'If the OS is win7 we need to install printers from a win 2008 server
Set objWMIService = GetObject("winmgmts:" &_
"{impersonationLevel=impersonate}!\\" & strComputer & _
"\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
if objOperatingSystem.Caption = "Microsoft Windows 7 " then sServer = "\\2k8srv"
'wscript.echo sServer
Next

' If this script alredy run once for this user, then EXIT
userprrf = WshShell.Environment("PROCESS")("UserProfile")
'wscript.Echo userprrf
If (objFSO.FileExists(userprrf & "\sctwashere.txt")) Then
Wscript.Quit
Else
blah = "let's have some fun"
End If

' Deletes RegistryKey with all subkeys in Network printers
sPath = "Printers\Connections"
lRC = DeleteRegEntry(HKEY_CURRENT_USER, sPath)
Function DeleteRegEntry(sHive, sEnumPath)
' Attempt to delete key. If it fails, start the subkey enumration process.
lRC = objRegistry.DeleteKey(sHive, sEnumPath)
' The deletion failed, start deleting subkeys.
If (lRC <> 0) Then
' Subkey Enumerator
On Error Resume Next
lRC = objRegistry.EnumKey(HKEY_CURRENT_USER, sEnumPath, sNames)
For Each sKeyName In sNames
If Err.Number <> 0 Then Exit For
lRC = DeleteRegEntry(sHive, sEnumPath & "\" & sKeyName)
Next
On Error Goto 0
' At this point we should have looped through all subkeys, trying to delete the key again.
lRC = objRegistry.DeleteKey(sHive, sEnumPath)
End If
End Function
'Now let's recreate the "root" Key we deleted before
objRegistry.CreateKey HKEY_CURRENT_USER,sPath

'Tell something to the user
'with createobject("wscript.shell")
' .popup "All Printers are now erased, Reinstalling...",5, "Printers Manager"
'end with

'Let's see in what ip range we are, so we can choose a default printer
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration ")

For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) _
to UBound(IPConfig.IPAddress)
strArray=Split(IPConfig.IPAddress(i),".")
if ubound(strArray) > 2 Then
'WScript.Echo strArray(2)
if strArray(0) = 192 And strArray(1) = 168 Then
Exit For
End if
End If
Next
End If
Next
' Read the file containig the pair ip-range, default-printer
'(the ip range is the 3rd digit in the ip - 10.0.X.3 - gives X as range)
Set objFile = objFSO.OpenTextFile("defaultlist.txt", ForReading)
'WScript.Echo strArray(2)
Do Until objFile.AtEndOfStream
defaultArray = split(objFile.ReadLine,",")
if defaultArray(0) = strArray(2) Then
defaultprt=defaultArray(1)
'wscript.Echo defaultArray(1)
exit do
end if
Loop
objFile.Close

default = sServer & "\" & defaultArray(1)
'wscript.Echo default

'Now let's start installing the printers listed in plist.txt
Set objFile = objFSO.OpenTextFile("plist.txt", ForReading)

Do Until objFile.AtEndOfStream
printer = objFile.ReadLine
printer = sServer & "\" & printer
if printer = default then
strCmd = "rundll32 printui.dll,PrintUIEntry /in /n """ & printer & """ /u /q /Gw"
WshShell.Run strCmd,,true
strCmd = "rundll32 printui.dll,PrintUIEntry /y /n """ & printer & ""
else
strCmd = "rundll32 printui.dll,PrintUIEntry /in /n """ & printer & """ /u /q /Gw"
end if
WshShell.Run strCmd
Loop
objFile.Close


with createobject("wscript.shell")
.popup "All Printers Are Now ReInstalled",15, "Printers Management"
end with

'We're done, let's leave a trace in userprofile, so at next login this script will exit
Set objFile1 = objFSO.CreateTextFile(userprrf & "\sctwashere.txt")

Wscript.Quit

Saturday, January 15, 2011

Monitor windows logs

Thanks to Stefan Plattner (http://twitter.com/splattne)
Considering that Intel's Matrix Raid does not have a way to send emails
in case of a HDD failure, I've searched for a way of monitoring the
Windows system log and send a mail in case of an event. The monitoring
part can be solved with a simple vbs script (made by splattne), this
script being run as service by the "Non-Sucking Service Manager"
( http://iain.cx/src/nssm/ ).
You can define the events you want to be alerted on, in the vbs script
with the "PushEventToMonitor" call. The arguments are: event ID, event
log name, source, category, type, user, and a regular expression that
can be matched against the log message. We have an example in the vbs
script that matches the start / stop of the TELNET service, as well as
one that will match the startup of the script itself (which logs an
event out to the Application Log) and a real case for Intel MatrixRaid.
In order to install the service, run in a command prompt: "nssm install
SimpleEventLogMonitor" and in the following window choose
"%SystemRoot%\System32\cscript.exe" as Application and
"c:\Path\to\eventmonitor.vbs" as Option.
To uninstall run: "nssm remove SimpleEventLogMonitor confirm" (Warning:
you can uninstall any service with this command!)


vbs script starts here:


Option Explicit

' Main
Dim objShell, objWMIService, objEventSink, dictEventsToMonitor, eventToMonitor

' =====================( Configuration )=====================

' Set to 0 to disable event log reporting of bans / unbans
Const USE_EVENTLOG = 0
Const EVENTLOG_SOURCE = "SimpleEventMonitor"

' SMTP configuration
Const EMAIL_SENDER = "EventLogMonitor@xxxxxxxxxxxx.ca"
Const EMAIL_RECIPIENT = "sorin@xxxxxxxx.com"
Const EMAIL_SMTP_SERVER = "relais.xxxxxxxxxx.ca"
Const EMAIL_SMTP_PORT = 25
Const EMAIL_TIMEOUT = 20

Set dictEventsToMonitor = CreateObject("Scripting.Dictionary")

' Define events that should be monitored. Matches are based on exact matches of all non-NULL fields
' Order: event ID, event log name, source, category, type, user, and a regular expression
'PushEventToMonitor "100", "Application", EVENTLOG_SOURCE, NULL, NULL, NULL, NULL
'PushEventToMonitor "7036", "System", "Service Control Manager", NULL, NULL, NULL, "Telnet service.*(running|stopped).*state"

' Monitor my Intel service
PushEventToMonitor "7202", "System", " IAANTmon", NULL, "Warning", NULL, NULL

' ===================( End Configuration )===================


Set objShell = CreateObject("WScript.Shell")

' Create event sink to catchevents
Set objWMIService = GetObject("winmgmts:{(security)}!root/cimv2")
Set objEventSink = WScript.CreateObject("WbemScripting.SWbemSink", "eventSink_")
objWMIService.ExecNotificationQueryAsync objEventSink, "SELECT * FROM __InstanceCreationEvent WHERE TargetInstance ISA 'Win32_NTLogEvent'"

' Loop sleeping for one week, logging an event each week to say we're still alive
While (True)
LogEvent 100, "INFORMATION", "Simple Event Log Monitor started"
WScript.Sleep(7 * 24 * 60 * 60 * 1000)
Wend

' Fires each time new events are generated
Sub eventSink_OnObjectReady(objEvent, objWbemAsyncContext)
Dim evt, field, boolAlert, regexpMessage

For Each evt In dictEventsToMonitor.Keys
boolAlert = True

For Each field In dictEventsToMonitor.Item(evt).Keys
If UCase(Field) = "MESSAGE" Then
Set regexpMessage = new Regexp
regexpMessage.Pattern = dictEventsToMonitor.Item(evt).Item(Field)
regexpMessage.IgnoreCase = True
If NOT regexpMessage.Test(objEvent.TargetInstance.Properties_(Field)) then boolAlert = False
Else
If UCase(objEvent.TargetInstance.Properties_(Field)) <> UCase(dictEventsToMonitor.Item(evt).Item(field)) Then boolAlert = False
End If
Next ' field

if boolAlert = True Then
SendMessage "Simple Event Log Monitor notification from " & objEvent.TargetInstance.ComputerName, _
"Event ID: " & objEvent.TargetInstance.EventCode & VbCrLf _
& "Date/Time: " & Mid(objEvent.TargetInstance.TimeGenerated, 5, 2) & "/" & Mid(objEvent.TargetInstance.TimeGenerated, 7, 2) & "/" & Mid(objEvent.TargetInstance.TimeGenerated, 1, 4) & " " & Mid(objEvent.TargetInstance.TimeGenerated, 9, 2) & ":" & Mid(objEvent.TargetInstance.TimeGenerated, 11, 2) & ":" & Mid(objEvent.TargetInstance.TimeGenerated, 13, 2) & VbCrLf _
& "Computer: " & objEvent.TargetInstance.ComputerName & vbCrLf _
& "Event Log: " & objEvent.TargetInstance.LogFile & vbCrLf _
& "Event Source: " & objEvent.TargetInstance.SourceName & vbCrLf _
& "Event Category: " & objEvent.TargetInstance.CategoryString & vbCrLf _
& "Event Type: " & objEvent.TargetInstance.Type & vbCrLf _
& "User Name: " & objEvent.TargetInstance.User & vbCrLf _
& "Message:" & vbCrLf & vbCrLF _
& objEvent.TargetInstance.Message
Exit Sub
End If

Next ' evt
End Sub

Sub LogEvent(ID, EventType, Message)
' Log an event to the Windows event log
If USE_EVENTLOG Then objShell.Exec "EVENTCREATE /L APPLICATION /SO " & EVENTLOG_SOURCE & " /ID " & ID & " /T " & EventType & " /D """ & Message & """"
End Sub

Sub SendMessage(strSubject, strBody)
Dim objCDOMessage
Set objCDOMessage = CreateObject("CDO.Message")

objCDOMessage.From = EMAIL_SENDER
objCDOMessage.To = EMAIL_RECIPIENT
objCDOMessage.Subject = strSubject
objCDOMessage.Textbody = strBody
objCDOMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = EMAIL_SMTP_SERVER
objCDOMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = EMAIL_SMTP_PORT
objCDOMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = EMAIL_TIMEOUT
objCDOMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOMessage.Configuration.Fields.Update
objCDOMessage.send
End Sub

Sub PushEventToMonitor(strID, strLog, strSource, strCategory, strType, strUser, strMessagePattern)
Dim x

x = dictEventsToMonitor.Count
Set dictEventsToMonitor.Item(x) = CreateObject("Scripting.Dictionary")
If NOT IsNull(strID) Then dictEventsToMonitor.Item(x).Add "EventCode", strID
If NOT IsNull(strLog) Then dictEventsToMonitor.Item(x).Add "LogFile", strLog
If NOT IsNull(strSource) Then dictEventsToMonitor.Item(x).Add "SourceName", strSource
If NOT IsNull(strCategory) Then dictEventsToMonitor.Item(x).Add "CategoryString", strCategory
If NOT IsNull(strType) Then dictEventsToMonitor.Item(x).Add "Type", strType
If NOT IsNull(strType) Then dictEventsToMonitor.Item(x).Add "User", strUser
If NOT IsNull(strMessagePattern) Then dictEventsToMonitor.Item(x).Add "Message", strMessagePattern
End Sub

Blog Archive