Etusivu

Liisa

Autot
Juhlat
Kotiteatteri
Kuvaaminen
Sukeltaminen
Matkailu
Musiikki
Ohjelmat
Roolipelit
Ruuanvalmistus
Tietokoneet
Arkistot
Sekalainen
Sivuhakemisto

Shelltricks

File rename with running order
Remove non-SVN files
Remove nonexisting files from SVN
Tail a httpd-log with resolve
Print the load average and temperature of mobo/CPU in a console

File rename with running order
This will rename the *.jpg files to something-XXX.jpg where the XXX is a running 3-digit number starting from 1 (CNT):

CNT=1; for i in *.jpg; do j=`printf "%.03d" ${CNT}`; mv -i "${i}" something-${j}.jpg ;CNT=$(($CNT+1)); done

Remove non-SVN files
CAUTION! This will remove all non-SVNed files from the directory.

svn st | grep ^? | cut -c 8- | xargs rm -rf

Remove nonexisting files from SVN
This will remove FROM THE REPOSITORY those files and sub-directories which are no longer present in the current directory.

for i in `svn st | grep ^! | cut -c 8-`; do svn rm ${i}; done

Tail a httpd-log with resolve
This involves a short perlscript. The idea is to see "live" what host has accessed what page. Handy when put into a screen for example. First the perlscript (saved as a file with execute bits set):

#!/usr/bin/perl                                                                                                                                               
                                                                                                                                                              
while( <> )                                                                                                                                             
{                                                                                                                                                             
    chomp;                                                                                                                                                    
                                                                                                                                                              
    if( m/^(\S*)\s*(\S*)\s+(\S*)\s*\[(\S*)\s*(\S*)\]\s*"(\w*)\s*(.*)\s+(\S*)"\s*(\S*)\s*(\S*)\s*"(.*)"\s*"(.*)"\s*(\S*)/ )                                    
    {                                                                                                                                                         
        $ipaddress    = $1;                                                                                                                                   
        ( $dateString = $4 ) =~ s/\[//;                                                                                                                       
        ( $request    = $7 ) =~ s/"//; #"                                                                                                                     
        open( HOST, "/usr/bin/host $ipaddress|" );                                                                                                            
                                                                                                                                                              
        while( $foo = <HOST> )                                                                                                                          
        {                                                                                                                                                     
            if( ! m/not\sfound/ )                                                                                                                             
            {                                                                                                                                                 
                $foo =~m/\s(\S+)\.$/;                                                                                                                         
                $ipaddress = $1;                                                                                                                              
            }                                                                                                                                                 
                                                                                                                                                              
            print( $dateString . " " . $ipaddress . " -> " . $request . "\n" );                                                                            
        }                                                                                                                                                     
    }                                                                                                                                                         
}
Then run it like so:
tail -f /path/to/logfile.log | perlscript.pl

Copyright (c) Paul-Erik Törrönen unless explicitly mentioned otherwise

Masseter koirakoulu

Vempain Publishing System