Shell tips

Some useful tips in shell

To remove the ^M characters in vi

:%s/^V^M//g

Put program to background after started

/usr/bin/nohup -ap <pid>

Use Shell to calculate

echo $[12 * 16]         #bash
let rc=12*16; echo $rc  #bash
expr 12 \* 16           #bash, ksh

Check file status

stat filename

Show file from specified line

#show from line 42
awk ‘NR>42’ alert.log

Bash check log files

Show how many rows updated
for x in ` find ./ -name “*utrade*log” -print` ; do echo $x; grep updated  $x; done

Find which process using port 1521

for i in `ls /proc`
do
pfiles $i 2>/dev/null | grep AF_INET | grep 1521
if [ $? -eq 0 ]
then
echo “Used by pid `/usr/bin/ps -o pid -o args -p $i | sed 1d`”
fi
done

Find which file are opened by a specified process

lsof -p 9087

while Loop in Korn shell ksh8.8

i=1;while (($i<20));do
print "DB${i}";
exp userid=DB${i}_USER/passwd@DB${i} file=USER_${i}.dmp log=USER_${i}.log
tables=TABLE_${i}
i=$((i+1));
done

for Loop in Bash shell

for((j=1; j<=10; j++))
do
echo =====DB${j}.oracle.com=====
sqlplus -s user/passwd@db${j} <<EOF
select * from v\$version;
EOF
done;

while Loop in Bash shell

while true loop
do
sqlplus -s alex/alex@db1 <<EOF
select count(*) from v\$session;
exit;
EOF
sleep 10
done

while(true)
do
ps -ef |grep pmon
echo “”
sleep 10
done

Advertisements

About Alex Zeng
I would be very happy if this blog can help you. I appreciate every honest comments. Please forgive me if I'm too busy to reply your comments in time.

One Response to Shell tips

  1. gege says:

    Thanks for shared information, very helpful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: