Archive for the ‘Script’ Category

Replace A Word From A Group of Files

Thursday, March 23rd, 2006

It’s another time to help my friend at office. He started a website and put some google AdSense. I guess it doesn’t make any sense and not as easy as to make some bucks out of it.

Well, the Q0: Hey how could I replace a particular word with another in a file?

Open the file in vi editor, go to the command mode [esc :] and type %s/oldW/newW/g

This search for every occurrence of oldW then replaces it with newW globally.

Q1: Good, I gotta 100+ files under a directory and wanna replace a particular word with another which occurs in some files?

That’s the spirit!

#! /bin/bash

cd /go/to/the/directory/

for file in * # here we can specify *.html or *.txt

do
# if foobar exists, replace it with fubar, make a temp file
# and back to old file

sed ’s/foobar/fubar/’ $file > sedtemp
mv sedtemp $file

done

tail: he needs to replace the AdSence words from the html files

Go away or I will replace you with a simple shell script

Saturday, February 18th, 2006

Hey ya unknown coward… you are Killed !!
….go away or I will replace you with a simple shell script…
Yes, I found a simple snip to do that without yelling it out :)

mongoose # ps -aux | grep [usrname] | awk ‘{print $2}’ | sort -g | xargs kill -9

This simple snip kill all the process invoked by the user in an order of last process, die first so the user too.

R-I-P

How much disk space ya left …??

Friday, January 13th, 2006

I gotta something… something wacky this time….

When one of our dear employee asked ” Is there any script to know the disk
usage of the system I am using….”

well….I snip one and it’s working fine…

++ Those who S [ ] I T before GATE, please excUse…

=====================================================

This shell script will help us to monitor the disk usage
If any of the disk partiotion space is more than 95%, all the users who were
logged into the system will get an ALERT message
Add the below line to “crontab -e” to run the program for every minute
*/1 * * * * sh /ya/path/to/diskUsage.sh
YMMV and if ya find any issue; please..try it out by yourself ‘/ ‘
tfeLYpoC

#! /bin/bash

df -h | grep -iv used |grep -iv media | awk ‘{print $6″ ” $5}’ |
while read ROW;
do PERCY=`echo $ROW | cut -d”%” -f1 | awk ‘{print $2}’`
if [ $PERCY -gt 95 ]; then
wall -n “ALERT..! from `hostname`
$ROW of the partition is FULL…! “
fi
done