Pages

Tuesday, November 3, 2015

Useful shell scripts used as alias for fedora and Linux machine

Useful shell scripts used as  alias for fedora and Linux machine

Here is list of useful shell scripts which used as alias in day to day work






1. connect script .

This list all the hosts to connect , we can pass it in commadline or by choice
if [ $# != 1 ]

then


echo 1.Xtest as root
echo 2.Xtest2 as oracle
echo 3.Xtest3 as oracle
echo 4.Xs5 as oracle
echo 5. Xcluster1 xx.yyy.zz.214 as oracle
echo 6. Xcluster2 xx.yyy.zz.215 as oracle
echo 7. X-portal as oracle
echo 8.X-pc2 as oracle

read ch

else

ch=$1

fi


case $ch in
1)ssh -l root xx.yyy.zz.139 ;;
2)ssh -l oracle xx.yyy.zz.140 ;;
3)ssh -l oracle xx.yyy.zz.141 ;;
4)ssh -l oracle xx.yyy.zz.147 ;;
5)ssh -l oracle xx.yyy.zz.137 ;;
6)ssh -l oracle xx.yyy.zz.138 ;;
7)ssh -l oracle xx.yyy.zz.132 ;;
8)ssh -l oracle xx.yyy.zz.145 ;;
*)echo Enter the right choice ;;
esac

To add in .bashrc
alias connect='/home/sterin/Templates/nm.sh'





2.Pack command : it will make tar file for folder or files

if [ $# != 1 ]

then

echo " usage pack <folderORfileName> "

exit
fi

dateformat=`date +%H%M_%d_%m_%y`


echo $1

folderName=`echo $1 | cut -f1 -d"/"`

echo $folderName

tar -cvf  "$folderName.tar"  "$1"




 



3. Starting browsers ,email client and other apps for day to day work


echo "starting firefox"

firefox "gmail.com" &

sleep 1
echo "starting chrome"

google-chrome "https://support.us.oracle.com/oip/faces/secure/srm/sr/SRQueue.jspx?mc=true" &

echo "starting thunderbird"

sleep 1
thunderbird &

echo "starting pidgin"

sleep 1
pidgin &

sleep 1

gnome-terminal &



sleep 1



gedit "FILE" &





4. Checking server status :

All the server details are menstion in one file . Script will check from the file


#Script:

if [ $# != 1 ]

then

echo "Parameter should pass like checkport <port> for specific port "
echo "OR checkport all for all port "

exit 0

fi

DIR=/home/oracle/latest_opatch/check_bug/list

if [ $1 = "all" ]

then

a=user_projects

else

a=$1

fi



if grep $a $DIR/yo.txt > /tmp/re

then

echo "below servers found from domain list file "
rm /tmp/uot

cat /tmp/re

else

echo "No server found for the keyword "

exit 0

fi

echo "<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>"

g=2

cat /tmp/re | while read LINE

do

g=`echo $LINE | awk -F"," '{print NF-1}'`
count=1

while [ $count -le $g ]
do
p=`echo $LINE | awk '{print $2}' | cut -f$count -d","`
if netstat -an | grep $p | grep LISTEN > /dev/null
then
echo " $p is running & pid is `netstat -anp | grep $p | grep LISTEN | awk '{print $7}' | tail -1` located at `echo $LINE | awk '{print $1}'` " >> /tmp/uot
fi
count=`expr $count + 1`
done

done

echo "<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>"

echo "status of the ports are "


cat /tmp/uot




## Format of the file having IP details
/domains/base_domain 7033,16201,16233
/domains/ps2 7032,16332,16232,
domains/stepsr3 7043,16332,16243


5. Copying boot.properties to every new domain

LOC=/home/oracle/latest_opatch/check_bug/boot.p

if ls -d ucm

then

echo " copying"

else

echo " go to domain dir and run the command "

exit 0

fi

cd servers/UCM_server1

cp -r $LOC/security .

Other required files

$ls -l /home/oracle/latest_opatch/check_bug/boot.p
total 8
-rwxr-xr-x 1 oracle oracle 201 Nov 12 2013 sec.sh
drwxrwxr-x 2 oracle oracle 4096 Nov 12 2013 security

$ ls -l /home/oracle/latest_opatch/check_bug/boot.p/security
total 4
-rw-rw-r-- 1 oracle oracle 36 Nov 12 2013 boot.properties

more /home/oracle/latest_opatch/check_bug/boot.p/security/boot.properties
username=weblogic
password=welcome1

Entry in .bashrc

alias sec='/home/oracle/latest_opatch/check_bug/boot.p/sec.sh'



6.Upload to FTP site :

It will be uploaded per defined FTP site:

HOST='HOSTADDRESS'
ftp -i $HOST <<END_SCRIPT

cd /ftp/anonymous/support/outgoing
#mkdir $1
#cd $1
put $FILE
quit
END_SCRIPT
echo "file copied to ftp URL is ftp://HOSTADDRESS/support/outgoing/$1 "
exit 3

Also you need create .netrc file in home directory for login with out entering password

Format of .netrc

default login hero password heropassord



7 . Run same command in multiple hosts from master server 

(Example to start all hadoop nodes from Master server )

SERVERS="172.31.27.144 172.31.27.145 172.31.27.146 "
# SSH User name
USR="hduser"



command="source ~/.bashrc; cd /usr/local/hadoop/sbin ; ./hadoop-daemon.sh stop datanode ; sleep 5 ;./yarn-daemon.sh stop nodemanager "



# connect each host and pull up user listing
for host in $SERVERS
do
echo "--------------------------------" 

echo "Server $host"

ssh $USR@$host  $command
echo "going to next hostname " 
done




8. Setting ec2 to hostname and using it


alias setec2='echo $1 > /tmp/ec2'
alias ec2='cat /tmp/ec2'

9. Fulltext search example :
To search one word all the files inside folder .

$1 will the keyword to search


alias fulltext='find . -exec grep "$1" {} \; -print'

No comments:

Post a Comment