Sunday, March 8, 2015

setting up autofs users home dir local and nfs

bash-3.2# cat /etc/auto.home
#!/bin/ksh
NONAS='
# specify local mounts
jay -rw     samserv01:/export/home:&
dev -rw     samserv01:/export/home:&
ram -rw     samserv02:/export/home:&
'
if [ -x /etc/auto_home_local ]; then
        exec /etc/auto_home_local $1
        exit 0
fi
if ( echo "$NONAS" |grep "^$1[  ]" >/dev/null 2>&1 ); then
        echo "$NONAS" | grep "^$1[      ]" | awk '{print $NF}'
        exit 0
fi
case $1 in
        nobody|nobody2) exit
        ;;
        [rk][0-9][0-9]*) echo sama:/export/home/$1
        ;;
        [A-Za-z]*) echo sam:/export/home/$1
        ;;
esac
bash-3.2# hostname
myclienthost
bash-3.2#
bash-3.2# ls -l /etc/auto_home_local
/etc/auto_home_local: No such file or directory

$ more remove-kernel.nsh
#!/opt/bladelogic/NSH/bin/nsh

OLD_KERNEL="kernel-devel-2.6.18-238.el5"

USER_CHOICE=$1
SERVER_FILE=$2
if [ -z $USER_CHOICE ]
then
    echo usage: remove-kernel-5.6.nsh --check  {server_list_file}
    echo usage: remove-kernel-5.6.nsh --remove {server_list_file} --yes
    exit 0
fi
if [ -z $SERVER_FILE ]
then
    echo usage: remove-kernel-5.6.nsh --check  {server_list_file}
    echo usage: remove-kernel-5.6.nsh --remove {server_list_file} --yes
    exit 0
fi
if [ ! -f $SERVER_FILE ]
then
    echo file $SERVER_FILE does not exist
    echo please check and try again
    exit 4
fi
if [ "$USER_CHOICE" = "--check" ]
then
    for i in $(cat $SERVER_FILE)
    do
        echo
        echo checking $i
        nexec $i uname -a
        nexec $i rpm -qa | grep kernel
    done
    echo
elif [ "$USER_CHOICE" = "--remove" ]
then
    CONFIRM=$3
    if [ "$CONFIRM" != "--yes" ]
    then
        echo
        echo please provide the confirmation parameter
        echo and try again
        exit 8
    fi
    for i in $(cat $SERVER_FILE)
    do
        echo
        echo removing $i
        nexec $i uname -a

        # make sure the current kernel is not the one we want to remove
        CURR_KERNEL=$(nexec $i uname -r)
        if [ "$CURR_KERNEL" = "$OLD_KERNEL" ]
        then
            echo
            echo WARNING!
            echo Server $i is running on kernel $CURR_KERNEL
            echo this kernel version will NOT be removed!
            echo please investigate
            echo
        else
            echo before
            nexec $i rpm -qa kernel
            echo removing 5.6
            nexec $i rpm -e $OLD_KERNEL
            echo after
            nexec $i rpm -qa kernel
        fi
    done
    echo

else
    # no valid choice
    echo usage: remove-kernel-5.6.nsh --check  {server_list_file}
    echo usage: remove-kernel-5.6.nsh --remove {server_list_file}
fi
$

# more master.sh
if [ -f /var/tmp/exclude.file ]
then
mv /var/tmp/exclude.file /var/tmp/sethu/bak/exclude.file.$$
fi
ls /opt/ | egrep -v "TWeagent|autosys|SUNW|sfw|sun|taddm|jumpstart|local|patrol|" | awk '{print "/opt/" $1 "/"}'
ls /usr | egrep -v `cat /var/tmp/usr.d` |awk '{print "/usr/" $1"/"}'
echo list opt and usr do manually
echo /system/ > /var/tmp/exclude.file
cat /etc/mnttab |grep  /fmacdata/ | egrep   "nfs|autofs" |  awk '{print $2}' | sed 's,/fmacdata,,g' >> /var/tmp/sethu/exclude.fmacdata
cat /etc/mnttab |grep  /fmac/ | egrep   "nfs|autofs" |  awk '{print $2}' | sed 's,/fmac,,g' >> /var/tmp/sethu/exclude.fmac
#
$ cat User_compare_script.ksh
for id in `/opt/quest/bin/vastool search -b dc=fhlmc,dc=com cn=hac_$1_gg member 2>/dev/null |cut -f2 -d'='|sed s/,CN//|sed s/,OU//|grep -v -i GG`
do id $id 2>/dev/null;
done | awk -F"(" '{if(NF==3) {print $2"     "$3};}' | sed 's/) gid=/    /g' | sed 's/)//' | awk '{print $1}' | sort | uniq>/tmp/$1_oldserver_userlist.txt
for id in `/opt/quest/bin/vastool search -b dc=fhlmc,dc=com cn=hac_$2_gg member 2>/dev/null |cut -f2 -d'='|sed s/,CN//|sed s/,OU//|grep -v -i GG`
do id $id 2>/dev/null;
done | awk -F"(" '{if(NF==3) {print $2"     "$3};}' | sed 's/) gid=/    /g' | sed 's/)//' | awk '{print $1}' | sort | uniq>/tmp/$2_newserver_userlist.txt
diff /tmp/$1_oldserver_userlist.txt /tmp/$2_newserver_userlist.txt 2>&1 /dev/null
RESULT=$?
if [ ${RESULT} -ne 0 ]
then
    echo "Differences found in the user list between servers $1 and $2 ...."
    echo "Please chk the list under tmp ..Output Of the Diff command ...."
    diff /tmp/$1_oldserver_userlist.txt /tmp/$2_newserver_userlist.txt  | egrep "<|>"
fi
$


bash-3.2# cat /etc/auto_home
#!/bin/ksh
NONAS='
# specify local mounts
jay -rw     samserv01:/export/home:&
dev -rw     samserv01:/export/home:&
ram -rw     samserv02:/export/home:&
'
if [ -x /etc/auto_home_local ]; then
        exec /etc/auto_home_local $1
        exit 0
fi
if ( echo "$NONAS" |grep "^$1[  ]" >/dev/null 2>&1 ); then
        echo "$NONAS" | grep "^$1[      ]" | awk '{print $NF}'
        exit 0
fi
case $1 in
        nobody|nobody2) exit
        ;;
        [rk][0-9][0-9]*) echo sama:/export/home/$1
        ;;
        [A-Za-z]*) echo sam:/export/home/$1
        ;;
esac
bash-3.2# hostname
myclienthost
bash-3.2#
bash-3.2# ls -l /etc/auto_home_local
/etc/auto_home_local: No such file or directory

listing remote server filesystem info

$ more checkfs.ksh
#!/bin/ksh
ssh -q sunserv2.fhlmc.com df -h $1
ssh -q sunserv1.fhlmc.com df -h $1

$ sh checkfs.ksh /opt

directory space use

Disk Usage
# more disk-opt.ksh
#!/bin/ksh
sudo du -h /opt | grep G | sed 's/^[ \t]*//' > /tmp/tmp1.$$
while read line
do
  space=$(echo $line | awk '{print $1}')
  dir=$(echo $line | awk '{print $2}')
  usr=$(ls -ld $dir | awk '{print $3}')
  echo "$usr $dir $space" >> /tmp/tmp2.$$
done < /tmp/tmp1.$$
cat /tmp/tmp2.$$|sort -k 1
rm -f /tmp/tmp1.$$ /tmp/tmp2.$$
#

Some scripting practice

# vi mycase.sh
#!/bin/sh
#
if [ $# -lt 1 ]
then
        echo
        echo "Invalid usage: Usage is $0 <interface>"
        echo
        exit
fi
if [ -f $0 -a -x $0 ]
then
        ifconfig $1 | grep "inet addr" | cut -d ":" -f2 | cut -d " " -f1
else
        chmod u+x $0
        ifconfig $1 | grep "inet addr" | cut -d ":" -f2 | cut -d " " -f1
#       echo check the permission
fi

[nepal@localhost lab1]$ cat mycase.sh
#!/bin/sh
echo "Please select from the list below"
echo "start|restart|reload - to restart the process"
echo "stop - to stop the process"
echo "Please enter the selection"
read choice
echo
case $choice in
start|restart|reload)
        service httpd restart;;
stop)
        service httpd stop;;
*)
        echo "Invalid selection"
esac
[nepal@localhost lab1]$



[nepal@localhost lab1]$ cat mypara.sh
#!/bin/sh
a=$1
b=$2
echo first value is $1
echo Second value is $2
if test  $a == $b
then
        echo "A equal to B"
elif [ $a -lt $b ]
then
        echo "A is less than B"
elif [ $a -gt $b ]
then
        echo "A is greater than B"
else
        echo "Selection does not meet the condition"
fi
[nepal@localhost lab1]$


[nepal@localhost lab1]$ more mycase.sh
#!/bin/sh
echo "Please select from the list below"
echo "start|restart|reload - to restart the process"
echo "stop - to stop the process"
echo "Please enter the selection"
read choice
echo
case $choice in
start|restart|reload)
        service httpd restart;;
stop)
        service httpd stop;;
*)
        echo "Invalid selection"
esac
[nepal@localhost lab1]$

[nepal@localhost lab1]$ more mycmd.sh
#!/bin/sh
#
echo the first value is $1
echo the fifth valie is $5
echo  the 10th value is ${10}
echo  the 10th value is shift  $9
echo The 14th value is $14
echo
echo the file name of the script is $0
echo all value passed on the command are: $*
[nepal@localhost lab1]$

[nepal@localhost lab1]$ cat king.sh
#!/bin/sh
#
if [ $# -lt 1 ]
then
        echo "Please supply the name of a file: usage $0 <filename>"
        exit
else
        . ./$1
        echo "$raja was a king of Nepal"
fi
[nepal@localhost lab1]$ cat raja
raja="Birendra Shah"
[nepal@localhost lab1]$

[nepal@localhost lab1]$ cat raja
raja="Birendra Shah"
rani="Aisharya Shah"
[nepal@localhost lab1]$ cat king1.sh
#!/bin/sh
#
# sourcing
. ./raja
echo "$raja was king of Nepal"
echo "$rani was a queen of Nepal"
[nepal@localhost lab1]$

[nepal@localhost lab1]$ cat myip
myip() {
ifconfig eth0 | grep "inet addr" | cut -d ":" -f2 | cut -d " " -f1;
}
[nepal@localhost lab1]$ cat myip.sh
. ./myip
echo The ip address of `hostname` is `myip`
[nepal@localhost lab1]$ sh myip.sh
The ip address of localhost.localdomain is 192.168.10.29
[nepal@localhost lab1]$



[nepal@localhost lab1]$ cat myip.sh
. ./myip
echo The ip address of `hostname` is `myip`
[nepal@localhost lab1]$ vi myip.sh
[nepal@localhost lab1]$ sh myip.sh
The ip address of localhost.localdomain is 192.168.10.29
Birendra Shah and Aisharya Shah were popular in Nepal
[nepal@localhost lab1]$ cat myip.sh
. ./myip
. ./raja
echo The ip address of `hostname` is `myip`
echo "$raja and $rani were popular in Nepal"


[nepal@localhost lab1]$ cat myip
myip() {
ifconfig eth0 | grep "inet addr" | cut -d ":" -f2 | cut -d " " -f1;
}
[nepal@localhost lab1]$ cat raja
raja="Birendra Shah"
rani="Aisharya Shah"
[nepal@localhost lab1]$


[nepal@localhost lab1]$ cat listfiles
listfiles() {
ls -l | grep "^-" | tr -s " " | cut -d " " -f9
}

[nepal@localhost lab1]$ listfiles
-bash: listfiles: command not found
[nepal@localhost lab1]$ ls -l listfiles
-rw-rw-r--. 1 nepal nepal 66 Mar  8 07:56 listfiles
[nepal@localhost lab1]$ chmod u+x listfiles
[nepal@localhost lab1]$ listfiles
-bash: listfiles: command not found
[nepal@localhost lab1]$ sh -xv listfiles
listfiles() {
ls -l | grep "^-" | tr -s " " | cut -d " " -f9
}
[nepal@localhost lab1]$ listfiles
-bash: listfiles: command not found
[nepal@localhost lab1]$ . ./listfiles
[nepal@localhost lab1]$ listfiles
cmdp.sh
king1.sh
king.sh
listfiles
mycase.sh
mycmd.sh
myfile1.3324
myfile.3324
myip
myip.sh
mypara.sh
mypat.sh
myshell.sh
raja
usage.sh
[nepal@localhost lab1]$ cat

[nepal@localhost lab1]$ cat >lmfiles
lmf() {
ls -l | grep "^-"| awk '{print $9}'
}
[nepal@localhost lab1]$ lmfiles
-bash: lmfiles: command not found
[nepal@localhost lab1]$ . ./lmfiles
[nepal@localhost lab1]$ lmfiles
-bash: lmfiles: command not found
[nepal@localhost lab1]$ lmf
cmdp.sh
king1.sh
king.sh
listfiles

[nepal@localhost lab1]$ cat lmfiles
lmf() {
ls -l | grep "^-"| awk '{print $9}'
}
users() {
cat /etc/passwd | awk -F: '{print $1}'
}
[nepal@localhost lab1]$ lmf
cmdp.sh
king1.sh
king.sh
listfiles
[nepal@localhost lab1]$ users
root
bin
daemon

Find the list of users who owned directory content
$ ls -lh | awk '{print $3}' | sort | uniq -c | sort -nk 1

[nepal@localhost lab1]$ cat >forsed
/usr/local/bin/myfile
/usr/local/bin/yourfile
/usr/local/bin/cool

[nepal@localhost lab1]$ sed 's//usr/local//opt/' forsed
sed: -e expression #1, char 8: unknown option to `s'

[nepal@localhost lab1]$ sed 's/\/usr\/local/\opt/' forsed
opt/bin/myfile
opt/bin/yourfile
opt/bin/cool
[nepal@localhost lab1]$ sed 's/\/usr\/local/\/opt/' forsed
/opt/bin/myfile
/opt/bin/yourfile
/opt/bin/cool
[nepal@localhost lab1]$

[nepal@localhost lab1]$ cat forsed
/usr/local/bin/myfile
/usr/local/bin/yourfile
/usr/local/bin/cool
[nepal@localhost lab1]$
[nepal@localhost lab1]$ sed 's/\/usr\/local/\/opt/' forsed
/opt/bin/myfile
/opt/bin/yourfile
/opt/bin/cool
[nepal@localhost lab1]$ sed 's/\/usr\/local/(\/opt)/' forsed
(/opt)/bin/myfile
(/opt)/bin/yourfile
(/opt)/bin/cool
[nepal@localhost lab1]$
[nepal@localhost lab1]$ cat names
Ram Sing
Sam bdr
Ajay Sing
Bir Bal

[nepal@localhost lab1]$ sed 's/Sing/Singh/; s/Ram/Shyam/; s/Bir/Bir Bahadur/' names
Shyam Singh
Sam bdr
Ajay Singh
Bir Bahadur Bal

[nepal@localhost lab1]$ sed -e 's/Sing/Singh/' -e 's/Sam/Shyam/' -e 's/Ajay/Ajay Pratap Singh/' names
Ram Singh
Shyam bdr
Ajay Pratap Singh Singh
Bir Bal

[nepal@localhost lab1]$ cat >names.f
s/Sing/Singh/
s/Sam/Shyam/
s/Ajay/Ajay Pratap Singh/
[nepal@localhost lab1]$ sed -f names.f names
Ram Singh
Shyam bdr
Ajay Pratap Singh Singh
Bir Bal
[nepal@localhost lab1]$ cat names
Ram Sing
Sam bdr
Ajay Sing
Bir Bal
[nepal@localhost lab1]$
[nepal@localhost lab1]$ ls -l | grep "^-"
[nepal@localhost lab1]$ ls -l | grep "^-" | awk '{print $9 $5}'
[nepal@localhost lab1]$ ls -l | grep "^-" | awk '{print $9 "\t"  $5}'

[nepal@localhost lab1]$ cat names
,Ram Sing
,Sam bdr
,Ajay Sing
,Bir Bal
l

[nepal@localhost lab1]$ awk -F, '{print "Name:"  $2}' names
Name:Ram Sing
Name:Sam bdr
Name:Ajay Sing
Name:Bir Bal

[nepal@localhost lab1]$ awk '/VA/' address
[nepal@localhost lab1]$ awk '/VA/' new
newaddr     newhile.sh
[nepal@localhost lab1]$ awk '/VA/' newaddr
Barry Chu, 22 East Broadway, Richmond, VA
Harry Peters, 328A Brook Road, Roanoke, VA
[nepal@localhost lab1]$ awk '/VA/ {print $1}' newaddr
Alice
Harry
[nepal@localhost lab1]$ awk -F, '/VA/ {print $1}' newaddr
Marry Chu
Harry Peters
[nepal@localhost lab1]$
[nepal@localhost lab1]$ sed 's/Marry Chu/Barry Johnson/' address >address1;mv address1 address

[nepal@localhost lab1]$ sed 's/Alia Thomas/Anita Ghose/' address >adress1;mv adress1 address; cat address | awk '{print $1}'
Mike
Barry
Anita


Friday, March 6, 2015

backout the kernel patch on Redhat

How to backout already installed patch.
I upgraded the server from RHEL 6.3 to RHEL 6.6 and I had to back it out to the old one. And upgrade it to RHEL 6.5. This is how it was done.

[root@sama ~]# yum history
Loaded plugins: product-id, refresh-packagekit, rhnplugin, security,
              : subscription-manager
This system is receiving updates from RHN Classic or RHN Satellite.
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     2 | Dev  <dev>    | 2015-02-02 14:20 | I, O, U        |  497 E<
     1 | System <unset>           | 2013-02-22 10:14 | Install        |  878 >
history list

Now, you can either do  "yum history undo last"  or  "yum history undo 2"  based on the output above.

[root@sama ~]# yum history undo last

Once removal is completed. Reboot the system and run the upgrade. Remember to do "yum clean all" before "yum update"
# yum clean all

Register the key
# rhnreg_ks --activationkey=your-key  --serverUrl https://your_server/abc --force

# yum update

once completed, reboot and again register with new channel and update to correct version.
 

Wednesday, March 4, 2015

inode info

Find where inodes are being used
df -i

Basically an inode is used for each file on the filesystem. So running out of inodes generally means you've got a lot of small files laying around. So the question really becomes, "what directory has a large number of files in it?"

so we can use the following command:
# find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n
Note: You can always replace the \n with \0 and use sort -z above).
http://unix.stackexchange.com/questions/117093/find-where-inodes-are-being-used

How to check inode information of UFS/VxFS.

1. UFS
# df -n /
/                  : ufs
NOTE1: Type of File-Systems: UFS.
# df -t /
/                  (/dev/dsk/c1t0d0s0 ): 62683504 blocks  7241984 files
                                 total: 124632118 blocks  7501312 files
NOTE2:  Free files: 7241984 (Free inodes)
       Total files: 7501312 (Total inodes)
        Used files:  259328 (Used inodes / 7501312-7241984=259328)
# df -g /
/                  (/dev/dsk/c1t0d0s0 ):          8192 block size          1024 frag size
124632118 total blocks   62683504 free blocks 61437184 available        7501312 total files
  7241984 free files      8388608 filesys id
      ufs fstype       0x00000004 flag             255 filename length
NOTE3: Shows the same information with other information.

# df -o i /
Filesystem             iused   ifree  %iused  Mounted on
/dev/dsk/c1t0d0s0     259328 7241984     3%   /
#
NOTE4: 'i' option shows inode information briefly.

2. VxFS (SOLARIS)
# df -n /mnt
/mnt               : vxfs
NOTE5: Type of File-system is 'vxfs'.

# df -t /mnt
/mnt               (/dev/vx/dsk/tdg/testvol-01):  6254930 blocks   781864 files
                                          total:  6291456 blocks   781868 files
NOTE6:  Free files: 781864 (Free inodes)
       Total files: 781868 (Total inodes)
        Used files:      4 (Used inodes / 781868-781864=4)

# df -g /mnt
/mnt               (/dev/vx/dsk/tdg/testvol-01):     8192 block size          1024 frag size
     6291456 total blocks    6254930 free blocks  5864012 available         781868 total files
      781864 free files     77864769 filesys id
        vxfs fstype       0x00000004 flag             255 filename length

# df -e /mnt
Filesystem              ifree
/dev/vx/dsk/tdg/testvol-01   781864

# df -o s /mnt
Free Extents by Size
          1:          1            2:          0            4:          2
          8:          2           16:          1           32:          2
         64:          1          128:          2          256:          1
        512:          1         1024:          1         2048:          0
       4096:          1         8192:          1        16384:          0
      32768:          1        65536:          1       131072:          1
     262144:          1       524288:          1      1048576:          2
    2097152:          0      4194304:          0      8388608:          0
   16777216:          0     33554432:          0     67108864:          0
  134217728:          0    268435456:          0    536870912:          0
 1073741824:          0   2147483648:          0
#


http://www.symantec.com/business/support/index?page=content&id=TECH144018