Larger Scripts

One-liners & Smaller Scripts


fragcount.sh

usage: ./fragcount.sh [directory]

e.g.,

mjbommar@metagnosis:~/Scripts$ sudo bash fragcount.sh /etc
Fragmented file found: /etc/xdg/openbox/rc.xml
Fragmented file found: /etc/devscripts.conf
Fragmented file found: /etc/defoma/hints/gsfonts-other.hints
Fragmented file found: /etc/elinks/elinks.conf
Fragmented file found: /etc/mplayer/codecs.conf
Fragmented file found: /etc/java-1.5.0-sun/content-types.properties
Fragmented file found: /etc/java-1.5.0-sun/security/cacerts
Fragmented file found: /etc/java-1.5.0-sun/security/java.security
Fragmented file found: /etc/ld.so.cache
1296 files, 9 fragmented files
24 fragments, 1311 total extents
1.83066361556064% fragmentation
Source
if [ -z $1 ]
then
	TARGET="/"
else
	TARGET="$1"
fi

fileN=0
fragN=0
fragFileN=0
fragFileFragN=0

calcFrag() {

	if [ ! -z "$1" ]
	then
		fragdata="`filefrag \"$f\"`"
		fragdata="`echo $fragdata | rev | cut -d':' -f1 | rev | awk '{print $1}'`"
		let fileN++
		if [ $fragdata -gt 1 ]
		then
			echo "Fragmented file found: $f"
			fragFileFragN=$(($fragFileFragN+$fragdata))
			let fragFileN++
		fi
		fragN=$(($fragN+$fragdata))
	fi
}


find $TARGET -xdev -type f > /tmp/fragcount.tmp
while read f;
do
	calcFrag $f
done  < /tmp/fragcount.tmp
rm -f /tmp/fragcount.tmp

echo "$fileN files, $fragFileN fragmented files"
echo "$fragFileFragN fragments, $fragN total extents"
perl -e "print ${fragFileFragN}*100/${fragN}, \"% fragmentation\n\""
				
				

intrate.sh

usage: ./intrate.sh module [samples]

e.g.,

mjbommar@metagnosis:~/Scripts$ sh intrate.sh bcm43xx 10
Sampling bcm43xx interrupt rate:
194157/sec
Source
# Usage:
# intrate.sh module [samples]

if [ -z $1 ]
then
	echo "usage: intrate.sh module [samples]"
	exit
fi

module=$1

if [ -z "$2" ]
then
	samples=5
else
	samples=$2
fi

s=0
n=0

echo "Sampling $module interrupt rate:"
y=`cat /proc/interrupts | grep "$module" | awk '{print $2}'`
sleep 1

while [ $n -lt "$samples" ]
do
	z=`cat /proc/interrupts | grep "$module" | awk '{print $2}'`
	s=$(($s+($z-$y)))
	n=$(($n+1))
	y=$(($z))
	sleep 1
done

echo "$(($s/$n))/sec"

rsync-backup.sh

usage: ./rsync-backup.sh

Source
targets="user@host1:backup user2@host2:public_html/backup"
source="~/"
for target in $targets
do 
	echo "Mirroring to $target..."
	
	rsync -e 'ssh -p22 -ax' -arpgtzi --partial \
	--delete --delete-excluded --safe-links\
	--exclude-from=/home/`whoami`/.rsync/exclude \
	$source $target > /home/`whoami`/.rsync/`date +%Y%m%d%H%M%S`.$target.log
done

dumpmods.sh

usage: ./dumpmods.sh

e.g.,

mjbommar@metagnosis:~/Scripts$ sh dumpmods.sh
Dumping module info for  2.6.18-git18...
filename:       /lib/modules/2.6.18-git18/kernel/crypto/michael_mic.ko
author:         Jouni Malinen 
description:    Michael MIC
license:        GPL v2
depends:        crypto_algapi
vermagic:       2.6.18-git18 preempt mod_unload

filename:       /lib/modules/2.6.18-git18/kernel/crypto/deflate.ko
author:         James Morris 
description:    Deflate Compression Algorithm for IPCOMP
license:        GPL
depends:        zlib_inflate,zlib_deflate,crypto_algapi
vermagic:       2.6.18-git18 preempt mod_unload

...
Source
echo "Dumping module info for  `uname -r`...";
for f in `modprobe -l`
do 
	modinfo $f | grep -v 'alias:'
	echo
done