Enjoy life as it comes...

Stephen Weblog

All about me…
Subscribe

Archive for the ‘Unix Scraps’

Disable proxy settings on linux

April 04, 2009 By: admin Category: Tech, Unix Scraps No Comments →

Steps to disable proxy on Linux:

1. vi /etc/profile.d/proxy.sh
2. comment the proxy setting in that file
3. recycle the network configuration or else reboot the server

SED screwed me up

June 14, 2008 By: admin Category: Unix Scraps 4 Comments →

Here is a simple shell script which I wrote to search and replace a pattern recursively, it was finding the file properly but did not replacing. Was wondering what the hell was going wrong and in the end found that ‘ should be replaced with ” for sed in shell scripting…

#!/bin/ksh
echo “Enter the search string”
read search;

echo “Enter the substituite string”
read replace;

echo “Enter the base directory location from where we need to start searching”
read baseloc;

for i in `find $baseloc -type f -exec grep -il “$search” {} \;`
do
echo “Pattern $search matched on file $i, going ahead to replace with $replace”
sed -e ’s/$search/$replace/g’ $i > $i.bkpb4replace
mv $i.bkpb4replace $i
done

Happy debugging!!!

Find number of CPU’s

June 09, 2008 By: admin Category: Unix Scraps No Comments →

Ever wanted to find the number of CPU’s you are running with, here we go this is what everyone will say

/oracle>cat /proc/cpuinfo | grep processor | wc -l
4
But we can do it without using double “|” as shown below

/oracle>grep -c processor /proc/cpuinfo
4

Unix file system for a newbie

May 03, 2008 By: admin Category: Unix Scraps No Comments →

Any newbie to Unix, searching for any tips to understand unix file system have a look at this

http://www.linuxconfig.org/Filesystem_Basics

Useful unix tips

May 03, 2008 By: admin Category: Unix Scraps No Comments →

pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to stdout.pgrep sshExecute The Last Executed CommandThe heading sounds a bit confusing but it’s exactly what it does.!!This will execute the last command you used on the command line.

Execute The Last Command Starting With..

If you want to execute a command a command from history starting with the letter S you can use the following:!sThis will execute the last command used on the command line that started with s.

Run a Command Repeatedly and Display the Output

watch runs command repeatedly, displaying its output (the first screenfull). This allows you to watch the program output change over time. By default, the program is run every 2 seconds. watch is very similar to tail.watch -d ls -lThis will watch the current directory for any file changes and highlight the change when it occurs.

Save Quickly in VI/VIM

If you’re in a hurry, you can save and quit the file you’re editing in vi by exiting insert mode, holding shift, and hitting z twice.

shell scripting at the worst level :o)

April 28, 2008 By: admin Category: Unix Scraps No Comments →

Had a call from Vinod (my school friend) this evening and he wanted a script to search through 1000 directories and on a specific file he wanted to do a search and replace of a text of specific pattern. So I came up with one of the most pathetic shell script which I had ever written in my career, containing fix after fixes, at last it went through fine hehehe

for k in `cat dirname`
do
echo $k
if [ -d $k ]; then
cd $k
if [ -f sfile ]
then
echo “ste”
for i in `ls -l sfile | awk ‘{ print $9 }’`
do
sed -e ’s/abc/def/g’ >$PWD/$i $PWD/$i
done
fi
cd ..
fi
done

Unix commands

March 25, 2008 By: admin Category: Unix Scraps No Comments →

Came across a useful site in which you can find most of the useful Unix commands…

http://cb.vu/unixtoolbox.xhtml

IP Address

March 25, 2008 By: admin Category: Unix Scraps No Comments →

For Solaris use:

ifconfig -a | grep “inet” |  grep -v “127.0.0.1″ | awk ‘{print $2;}’

For HP-UX use:

ifconfig foo | grep “inet” | awk ‘{print $2;}’

Where foo is the interface, generally lan0, lan1 etc.

Adjusting file times

March 16, 2008 By: admin Category: Unix Scraps No Comments →

To Make a file look older.

Use touch -t option to change the time stamp of a file syntax is:

touch -t ccyymmddhhMMSS filename

gzip znew and compress

March 12, 2008 By: admin Category: Unix Scraps 5 Comments →

In HP Unix “compress” command will compress around 50 to 60%. “gzip” will compress the file upto 80%. There is a command available in HP’s unix to convert a compress file to a zip file. “znew” will automatically convert compressed files(*.Z) to gunzip files(*.gz).

Example:
$ znew test.Z