Image

Image

Search This Blog

Friday, November 21, 2008

tape backup

quick and dirty, ofc. adapted after pjl, whom adapted a script from sco sysV made in 1988. 

 #!/bin/sh 

# Local Variables recipient1=service@xxxxxxx.com recipient2=sandra@xxxxxxx.com printer=office TAPE=/dev/st0 # System variables LOCK=/var/autotback/backlock DEFAULTDIR=/var/autotback REPORTFILE=/var/autotback/backrep TEMPFILE=/var/autotback/backtmp TEMPFILE2=/var/autotback/backtmp2 # Check if another backup is running if [ -r $LOCK ] then echo “Another backup is running or the last backup has not finished well. Please check!” echo “Another backup is running or the last backup has not finished well. Please check!” | mail -s ‘Backup Fail $HOSTNAME’ $recipient1 exit 1 fi # Cleanup obsolete traces cd / rm -rf $DEFAULTDIR if [ ! -d $DEFAULTDIR ] then mkdir $DEFAULTDIR fi # Create lockfile echo “backup started”>$LOCK # Start backup banner “ Automatic Backup Report “>$REPORTFILE echo “(c)1991-2008 Xxxxxxx Services Inc.”>>$REPORTFILE echo “======================================================================================”>>$REPORTFILE echo “”>>$REPORTFILE echo “Backup of $HOSTNAME Started on `date` “>>$REPORTFILE echo “”>>$REPORTFILE # Exclude /proc /sys /tmp find . -depth -print >$DEFAULTDIR/list grep -v “./sys/” $DEFAULTDIR/list >$DEFAULTDIR/list2 grep -v “./proc/” $DEFAULTDIR/list2 >$DEFAULTDIR/list3 grep -v “./tmp/” $DEFAULTDIR/list3 >$DEFAULTDIR/list4 # Start saving echo “BACKUP OF `date`”>$TEMPFILE cat $DEFAULTDIR/list4 | cpio -ocvB >$TAPE 2>>$TEMPFILE backstat=$? tail $TEMPFILE >>$REPORTFILE echo “”>>$REPORTFILE echo “$backstat = exit status”>>$REPORTFILE echo “”>>$REPORTFILE if [ $backstat -ne 0 ] then echo “*** Backup may contain an error ***”>>$REPORTFILE fi echo “Tape Save completed on `date`”>>$REPORTFILE echo “”>>$REPORTFILE set `tail -1 $TEMPFILE` BACKTOT=$1 echo “Total of amount of Backup was $1 blocks Starting Verify”>>$REPORTFILE echo “”>>$REPORTFILE #Tape rewind / Verify cpio -icvtB <$TAPE >>$TEMPFILE 2>>$TEMPFILE2 verstat=$? tail $TEMPFILE2 >>$REPORTFILE echo “$verstat = exit status”>>$REPORTFILE echo “”>>$REPORTFILE if [ $verstat -ne 0 ] then echo “*** Verify may contain an error ***”>>$REPORTFILE echo “”>>$REPORTFILE fi echo “Verify completed for server $HOSTNAME `date` “>>$REPORTFILE echo “”>>$REPORTFILE set `tail -1 $TEMPFILE2` VERTOT=$1 if [ “$BACKTOT” != “$VERTOT” -o $backstat -ne 0 -o $verstat -ne 0 ] then echo “*** WARNING BACKUP TRANSFER TOTALS DID NOT MATCH ***”>>$REPORTFILE echo “*** PLEASE VERIFY ***”>>$REPORTFILE echo “”>>$REPORTFILE else echo “*** Transfer Totals Concur ***”>>$REPORTFILE echo “”>>$REPORTFILE fi # Send the report cat $REPORTFILE | mail -s ‘Backup Report $HOSTNAME’ $recipient1, $recipient2 #lp -d $printer $REPORTFILE # Remove lock and exit sleep 5 rm $LOCK exit 0

Monday, November 03, 2008

hp notifier

open source version :)

#!/bin/bash

# hp/compaq notifier. to be run from cron. require psp

#define addresses where warnings will be sent

recipient1=service@XXXXXXXXX.com

recipient2=sxxxxxx@XXXXXXX.com

#let’s check if we have events in the ILO log

/sbin/hplog -v | grep -B 1 -E ‘Error|Failure|Screen|ASR’ >> /tmp/ciss2.$$

set `wc /tmp/ciss2.$$`

if [ $1 -eq 0 ]

then

#if the ILO log is empty get out

exit 0

fi

#if there is something in the log, check if we have a previous logfile

if [ ! -f /var/log/ciss.log ]

then

#create one if we don’t have it yet

touch /var/log/ciss.log

fi

#compare the newly readed infos from ILO with those from previous logfile

grep -v -f /var/log/ciss.log /tmp/ciss2.$$ > /tmp/ciss3.$$

#if there are differences

if [ -s /tmp/ciss3.$$ ]

then

#replace previous log with the new one

cat /tmp/ciss2.$$ > /var/log/ciss.log

#add some cosmetic informations

echo -en “End of report on: ” >> /tmp/ciss2.$$

date >> /tmp/ciss2.$$

#and warn the administrators

#
cat /tmp/ciss2.$$ | /bin/mail -s ‘Error on $HOSTNAME’ $recipient1
# cat /tmp/ciss2.$$ | /bin/mail -s ‘Error on $HOSTNAME’ $recipient2

echo “comment this line and uncomment the line before” ; cat /tmp/ciss2.$$ fi

#then let’s do some cleanup

rm -f /tmp/ciss*

exit 0

PS: the script is modified a bit, as blogger.com does not allow some strings such as: < followed by /location/file...

printers restart

se dau urmatoarele:

- una bucata cups

- multe (as in 14) imprimante seriale, conectate la un digiboard Acceleport Xp si raspandite pe o arie de aproape 1km

- o aplicatie de 0.02$ portata cu chiu cu vai dupa un sco sysV

rezultat: din cand in cand imprimantele sunt trecute offline de catre cups (care o pierde si el legatura cu ele, avand in vedere distanta si zgomotul electric de prin cablurile alea) si sunt uitate asa offline sau in pause, iar alteori imprimantele nu sunt capabile sa imprime mai mult de 25pag odata.

se cere: sa functioneze!

pentru problema de offline am facut asa: cron, every 10min, run this:

!/bin/bash# a script that restarts stopped printers

# (c)2007 neXt GPL'ed

/bin/cut --delimiter=| -s -f1 /etc/printcap > /tmp/printname.$$/bin/cat /tmp/printname.$$ | while read line; do lpstat -p ${line} 2>/dev/null | /bin/grep -E 'not|disabled' && /usr/sbin/lpadmin -p ${line} -E ; done

#old method that restart even active printers - NOT GOOD!

#/bin/cat /tmp/printname.$$ |while read line; do /usr/bin/cupsenable ${line}; done

/bin/rm -f /tmp/printname.*

exit 0

pentru problema cu >25 pagini am incercat sa tin porturile deschise in digi (crezand ca nu le lasa cups deschise) “cat/dev/null &”

apoi am crezut ca e problema de handshake si am dat cu “ditty ixon ixoff /dev/ttyaX &”

nici asa n-a mers. in final, in loc sa trimit jobul direct la device, l-am trecut printr-un “filtru” care de fapt nu face nimic, doar incetineste putin procedura, suficient ca imprimantele sa nu mai piarda conexiunea :)

am creat un socket pentru cups:

#!/usr/bin/perl

use IO::Socket::INET;

$port=14000;
$psrv=IO::Socket::INET->new(LocalPort => $port.Type=>SOCK_STREAM.Reuse=>1.Listen=>1) or print “can’t bind $! n”;

while ($pjob=$psrv->accept()) { open(J.”>/dev/ttyaX”) or print “can’t send to $!n”;
while (<$pjob>) {

print J “$_”;

} close J;

close $pjob;

}

iar in /etc/cups/printers.conf am schimbat tipul de device din “DeviceURI serial://dev/ttyaX” in “DeviceURI socket://localhost:14000”

Blog Archive