msgbartop
A cronological documentation test project, nothing serious, really!
msgbarbottom

23 Jan 2009 Copy files using tar

This is a oneliner to copy files from current directory to another target directory using tar, preserving file attributes, dates etc.

#!/bin/sh

fromdir=/path/from
todir=/path/to/target

echo "cd $fromdir; tar cf - . | (cd $todir; tar xpf -)"

cd $fromdir; tar cf - . | (cd $todir; tar xpf -)

Tags: , ,

Posted by Hans-Henry Jakobsen

21 Jan 2009 IP address change notifier script

This is a simple bash script that is run by crontab every 5 minutes on a linux box.
It e-mails me the new address when a change of IP address is detected.

The script (ipchangemail.sh)

#!/bin/bash 

# Check if IP-address has changed. If a change has occured, mail me the new address
# Add the following line to crontab if you would like it to be run every 5 minutes:
# */5 * * * * ./ipchangemail.sh

# The network interface I want to monitor
NET_INTERFACE=eth0

# File to keep the latest IP address
IP_FILE=myip.txt

# Mail to this address when a change occur
MAILTO=mail@example.com

# Read the previous IP address from file
source $IP_FILE

CURRENT_IP=`/sbin/ifconfig $NET_INTERFACE | sed -n "/inet addr:.*255.255.25[0-5].[0-9]/{s/.*inet addr://; s/ .*//; p}"`

if [ "$CURRENT_IP" != "$OLD_IP" ]
then
        # Send email about address change
        `echo "New IP address detected: $CURRENT_IP" | mail -s "New IP address" $MAILTO`

        # Write new address to file
        `echo "OLD_IP=$CURRENT_IP" > $IP_FILE`
fi

The script can be downloaded here.

Tags: , , ,

Posted by Hans-Henry Jakobsen

24 Oct 2008 Rename file name suffix to uppercase or lowercase

This is a little oneliner to rename a files suffix from/to uppercase/lowercase.

Rename a jpg suffix to JPG in the current folder

# find -name "*.jpg" | while read a; do mv "$a" "${a%%.jpg}.JPG" ; done

The work JPG can be replaced by any other word :)

Tags: , , ,

Posted by Hans-Henry Jakobsen

04 Sep 2008 Share a bash session using screen

This is a short post on how you can “share” a bash session/prompt with other users.

  1. User A connects to the server and types in the command
    # screen
  2. User A hist the key combination <Ctrl + a> and the type
    :multiuser on
  3. User B connects to the same server as user A and can the join the session by typing
    # screen -x

Serveral users can connect and share the same session at once.

To close the screen session just use the key combination <Ctrl + a>

Tags: ,

Posted by Hans-Henry Jakobsen

23 Jun 2008 Oneliner to determine directory size

This is a simple oneliner to determine which user has used most diskspace in their /home directory

du -sm $(find /home -type d -maxdepth 1 -xdev) | sort -g

The result could look something like this

...
215     /home/userT
1367    /home/userB
10865   /home/userL
25326   /home/userY
116328  /home/userH
154426  /home/

The numbers to the left is size i MB.

Tags:

Posted by Hans-Henry Jakobsen