Friday, July 25, 2008

How to get log file from another unix box using shell script

Use run3.sh for getting a remote file to current directory.

cplogs.sh
=========
#!/bin/sh
if [ $# -eq 0 ]
then
echo "Usage: cplogs "
echo "Options"
echo "1: Managed_Server_1.log"
echo "2: Managed_Server_2.log"
echo "3: Managed_Server_3.log"
echo "4: Managed_Server_4.log"
echo "5: Managed_Server_5.log"
exit 1
fi
rm *.log 2>/dev/null
for i in $*
do
case $i in
1) cp /sundev/osmenv01/bea92mp2_user_projects/domains/osm7ClustDomain/servers/managedServer_1/logs/managedServer_1.log . ;;
2) cp /sundev/osmenv01/bea92mp2_user_projects/domains/osm7ClustDomain/servers/managedServer_2/logs/managedServer_2.log . ;;
3) cp /sundev/osmenv01/bea92mp2_user_projects/domains/osm7ClustDomain/servers/managedServer_3/logs/managedServer_3.log . ;;
4) . ./run4.sh ;;
5) . ./run5.sh ;;
esac
done


run3.sh
========
#!/bin/sh
HOST='Ur Ip'
USER='Username'
PASSWD='password'

ftp -n $HOST <quote USER $USER
quote PASS $PASSWD
bi
cd /sundev/osmenv01/bea92mp2_user_projects/domains/osm7ClustDomain/servers/managedServer_4/logs
get managedServer_4.log
quit
END_SCRIPT

Monday, July 21, 2008

How to exit all telnet session at one shot

function stopall
{
if [ $# -eq 0 ]
then
echo "stopall "
echo "1:Kill all the Tail process"
echo "2:Kill all the telnet session(including kill tail process)"
else

if [ $1 -eq 1 ]
then
psef|grep "tail"|awk '{print $2}'|xargs kill -9 2>/dev/null
echo "All Tail process are killed"
elif [ $1 -eq 2 ]
then
psef|grep "tail"|awk '{print $2}'|xargs kill -9 2>/dev/null
psef|grep "ksh"|grep -v `echo $$`|awk '{print $2}'|xargs kill -9 2>/dev/null
kill -9 `echo $$`
else
echo "Please provide correct input"
fi
fi
}