Thursday 30 December 2010

My workplace :)

Yep, there's a AT-AT.

Log transfer and update script

The ideas of this script are:
-Download all the files for yesterday (the date must be inside the filename) and save in disk for 61 days.
-Download all the new files generated any day for other days (something like "residual logs... the system generates the log for the day n-1 the n day, but maybe any of the n-m (m<61) day, the system generates another log for any of the n-m days... and the script must download it, verifying the content for every day in the ftp against the disk... it's that clear :P

So, it's not very finished yet, but here is:
(I know, all the comments and vars are in spanish... but just watch a Cheech and Chong's movie and you'll be ok)

AYER=`/bin/date +"%Y%m%d" --date "24 hour ago"`
LOGFILE="/path/to/log"
REMOTEHOST="x.x.x.x"
USER="user"
PASS="pass"
DESTINO="/path/to/disk"

#### ARCHIVOS MENSAJERIA DIA ANTERIOR

if [ ! -d  $DESTINO ]; then
   /bin/mkdir -p $DESTINO
fi

if [ ! -d  $LOGFILE ]; then
   touch $LOGFILE
fi

echo "=Inicio mensajeria============================================" >> $LOGFILE
echo "`/bin/date`" >> $LOGFILE
wget --no-passive-ftp -c -nv -P ${DESTINO} ftp://${USER}:${PASS}@${REMOTEHOST}:/*$AYER* >> $LOGFILE 2>&1
echo "`/bin/date`" >> $LOGFILE
echo "=Fin de mensajeria============================================" >> $LOGFILE

#### TRAYENDO ARCHIVOS REZAGADOS

cat /dev/null > rezagados_m.sh
curl -u$USER:$PASS -l ftp://$REMOTEHOST > ftp.lst
d=1
echo "Buscando rezagados mensajeria============================================" >> $LOGFILE
echo "`/bin/date`" >> $LOGFILE
while [ $d -le 61 ]
do
        old=`/bin/date +"%Y%m%d" --date "$d days ago"`
        grep $old ftp.lst > $old.ftp
        ls ${DESTINO}|grep $old > $old.hdd
        grep -v $old.ftp -f $old.hdd |awk -v destino=${DESTINO} -v user=${USER} -v pass=${PASS} -v remotehost=${REMOTEHOST} '{print "wget --no-passive-ftp -c -nv -P "destino" ftp://"user":"pass"@"remotehost":/"$1}' >> rezagados_m.sh
        if [ `grep -v $old.ftp -f $old.hdd |wc -l` -gt '0'  ]; then
                echo " Se encontraron `grep -v $old.ftp -f $old.hdd |wc -l` archivos rezagados para el dia $old" >> $LOGFILE 2>&1
        fi
        rm $old.*
(( d++ ))
done
echo "`/bin/date`" >> $LOGFILE
echo "Fin busqueda rezagados mensajeria============================================" >> $LOGFILE
echo "Bajando rezagados mensajeria============================================" >> $LOGFILE
bash ./rezagados_m.sh >> $LOGFILE 2>&1
rm -rf ftp.lst
rm -rf rezagados*

I'm not codeconomics  gifted :)

Thursday 9 December 2010

Display execution data inside awk command

The easiest way to use output from, i.e, a command inside awk, is capturing the output and assign it to a variable. For example, if we need to print the current date, we can use:

awk -v D=$(date +%Y%m%d-%H%M) '{print D "-"$12}'

Obviously, you've to customize it according your needs.

Monday 15 November 2010

List installed Perl modules

perl -MFile::Find=find -MFile::Spec::Functions -Tlwe 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'

Thursday 28 October 2010

HTML redirect

META HTTP-EQUIV="Refresh" CONTENT="0; URL=http://another.stite"

Between <>

Tuesday 26 October 2010

Hot-Handling of MyISAM files


I (not me, J Jorgenson via stackoverflow.com) found the following will ensure integrity of MyISAM tables for any file-level manipulation:

LOCK TABLE x WRITE; 
FLUSH TABLE x; -- closes all file handles into table by mysql.
Now you can perform file-level manipulations.
FLUSH TABLE x; -- A 'stat' of the table occurs and info-schema is updated appropriately. 
UNLOCK TABLES; 

If you do NOT lock-write your table, mysql may access it (reads or writes) while you are doing your file-level copy/manipulation. This is also the same mechanism used to allow 'myisampack', 'myisamchk' for tables on an HOT database that even has external locking disabled, without worries of corruption.

Friday 5 March 2010

Tuesday 23 February 2010

My 10 UNIX Command Line Mistakes

A very good (and tragicomic) article. Sometimes we play down the importance of an enter in the cli.

One of my greatest errors was a typo in a Solaris... crontab -r it's not the same as crontab -e (despite the position of the keys!)

Link here

Testing email posting

I hope this works!

Enviado desde mi iPhone

Tuesday 16 February 2010

Bonding interfaces in Linux

Bonding interfaces provides lb/ft to a network connection. So, if you have a lot of nics and a managed switch (supporting trunking), bonding will be a very good option!

First, create a bond interface file:

# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=x.x.x.x
NETWORK=x.x.x.x
NETMASK=x.x.x.x
USERCTL=no
BOOTPROTO=none
ONBOOT=yes

Next, set the first interface in the bond:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

Then, the second interface:
# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

Add the bonding module to the modules configuration:
# vi /etc/modprobe.conf
alias bond0 bonding
options bond0 mode=0  miimon=100

Mode 0 for fault tolerance, mode 1 for load balance.

To see a full list of the bonding available modes, go to the official Red Hat KB article here.

Check the bonding module:
# modprobe bonding

Restart the network service:
# service network restart

Check the status of the bond:
# less /proc/net/bonding/bond0

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:c6:be:59

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:c6:be:63

Thats all... always remember to check /proc/net/bonding/bond0 for link failures.

Monday 11 January 2010

Remove all Outlook rules

To remove all the Outlook rules (in case this are corrupted), just execute Outlook with /cleanrules parameter.

So simple!