Monday, March 30, 2015

Configuring iSCSI on RHEL 6

How to set up and configure ISCSI on RHEL 6

RHEL 7 - Setting up Network Bonding

Steps to set up Network Bonding on RHEL 7

RHEL6/7 - Configure telnet server

RHEL6 - Configure telnet server

telnet is managed by xinetd service on Redhat. To enable telnet server install the package the

# yum search telnet
# yum install telnet-server
# service xinetd status/restart

restart of xinetd does not work telnet. You have to edit the file /etc/xinet.d/telnet and go to 'service telnet' section and set diabled = yes to no.
Once you changed it, restart the inetd service

# service xinetd restart

# chkconfig telnet on && chkconfig xinetd on

If you are using iptable/firewall, add the line below

# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW --dport 23 -j ACCEPT
# service iptables restart


or RHEL7
# systemctl start telnet.socket
# systemctl enable telnet.socket

Firewall entry for RHEL 7

# firewall-cmd --permanent --add-port=23/tcp
# firewall-cmd --reload


Now, to go the client server and try to login to the server.


Note: You should use ssh but there time comes, you have to enable telnet services which is not secure.

Sunday, March 29, 2015

LVM_FS_Creation


[root@puppet tmp]# more my_LVM
# VG     FS      Size MPoint
 test_vg FS_WWW  500 /www
 test_vg FS_WWW2 500 /www2
 test_vg FS_WWW3 500 /www3
 test_vg FS_WWW4 500 /www4
[root@puppet tmp]# cat my_LVM.sh
#!/bin/sh
#
PATH=$PATH:/bin:/usr/bin; export PATH
echo "Please wait, filesystem creation task on progress ..."
sleep 5
cat my_LVM | grep -v "^#" | while read myvg myfs mysize mymnt
do
 lvremove /dev/${myvg}/${myfs}
 lvcreate -L ${mysize}M -n ${myfs} ${myvg} 2>/dev/null
 mkfs.ext4 /dev/${myvg}/${myfs} 2>/dev/null
 mkdir -p ${mymnt}
 echo "/dev/${myvg}/${myfs} ${mymnt} ext4 defaults 1 2" >>/etc/fstab
done
mount -a; df -h
echo "Task completed. Please verify"

Saturday, March 28, 2015

sudo-ssh-link

Notes: 3/28/2015


[khem@puppet Desktop]$ id khem
uid=500(khem) gid=500(khem) groups=500(khem),557(larry)
[khem@puppet Desktop]$ ping yahoo.com
PING yahoo.com (206.190.36.45) 56(84) bytes of data.
64 bytes from ir1.fp.vip.gq1.yahoo.com (206.190.36.45): icmp_seq=1 ttl=52 time=87.4 ms
64 bytes from ir1.fp.vip.gq1.yahoo.com (206.190.36.45): icmp_seq=2 ttl=52 time=92.2 ms
^C
--- yahoo.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1927ms
rtt min/avg/max/mdev = 87.482/89.864/92.247/2.401 ms
[khem@puppet Desktop]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/khem/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/khem/.ssh/id_rsa.
Your public key has been saved in /home/khem/.ssh/id_rsa.pub.
The key fingerprint is:
00:0e:f2:be:84:9f:15:48:54:29:eb:71:c2:57:87:7e khem@puppet.mydomain.local
The key's randomart image is:
+--[ RSA 2048]----+
|..+.o. .         |
| +.+..o .        |
| .oooo..         |
| o= o...E        |
|..o=.  .S        |
| o.+             |
|  +              |
|                 |
|                 |
+-----------------+
[khem@puppet Desktop]$ pwd
/home/khem/Desktop
[khem@puppet Desktop]$ pwd
/home/khem/Desktop
[khem@puppet Desktop]$ cd ../.ssh
[khem@puppet .ssh]$ ls
id_rsa  id_rsa.pub  known_hosts
[khem@puppet .ssh]$ ls -l
total 12
-rw-------. 1 khem khem 1675 Mar 28 06:36 id_rsa
-rw-r--r--. 1 khem khem  408 Mar 28 06:36 id_rsa.pub
-rw-r--r--. 1 khem khem  395 Mar  1 06:56 known_hosts
[khem@puppet .ssh]$ ssh-copy-id -i id_rsa.pub sham@192.168.0.149
The authenticity of host '192.168.0.149 (192.168.0.149)' can't be established.
RSA key fingerprint is a4:ea:95:ed:0c:53:49:35:f8:bf:89:fc:32:e7:bb:76.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.149' (RSA) to the list of known hosts.
sham@192.168.0.149's password:
Now try logging into the machine, with "ssh 'sham@192.168.0.149'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[khem@puppet .ssh]$ id
uid=500(khem) gid=500(khem) groups=500(khem),557(larry) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[khem@puppet .ssh]$ ssh sham@192.168.0.149
Last login: Thu Mar 26 20:44:28 2015 from mohan.home
[sham@ldap ~]$


===========================================================



Q. Please create a run control script of a file hello.sh which start at runlevel 3 up on reboot.

# cat hello.sh
#!/bin/sh
echo "Testing ....."
echo "Hello.World !!!"

# cd /etc/rc3.d; ls -l S51hello
# ln -s /etc/init.d/hello.sh ./S51hello

Q. Please update a link S51hello at rc3.d from a file located at /opt/apps/hello.sh
# cp hello.sh hello.sh.oldie
# cp /var/tmp/hello.sh /etc/init.d/hello.sh

planning..
ln -s /opt/apps/hello.sh /etc/rc3.d/S51hello
ln -s /opt/apps/hello.sh S51hello

# ls -l S51hello
lrwxrwxrwx. 1 root root 20 Mar 28 09:01 S51hello -> /etc/init.d/hello.sh
# rm S51hello

# ln -s /opt/apps/hello.sh S51hello
ln: creating symbolic link `S51hello': File exists
# ln -s /opt/apps/hello.sh /etc/rc3.d/S51hello
ln: creating symbolic link `/etc/rc3.d/S51hello': File exists
# ln -s /opt/apps/hello.sh /etc/rc3.d/S51hello
# ls -l S51hello
lrwxrwxrwx. 1 root root 18 Mar 28 09:28 S51hello -> /opt/apps/hello.sh



SUDO
----
syntax
user   machine/host = command

Q. give user sham access to create account
# visudo
sham  ALL = /usr/sbin/useradd, /usr/bin/passwd

Q. Give multiple user to create account.
# visudo
# User Alias
User_Alias MYADMIN = sham,juliet,ramsing

# Command Alias
Cmnd_Alias MYCMD = /usr/sbin/useradd, /usr/bin/passwd

# Host Alias, since we are working on local host, we don't have to create hostalias.

# Specify the user machine command.
# here MYADMIN is user alias, ALL is list of hosts, its local here in this example
# MYCMD is the list of commands that user has access to
MYADMIN ALL=MYCMD

# if you want user without prompting pw
MYADMIN ALL=NOPASSWD: MYCMD


# su - ramsing
$ sudo useradd hari
$ sudo passwd hari
Changing password for user hari.
New password:
BAD PASSWORD: it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.
[ramsing@ldap ~]$ logout


# for i in sam hari geeta; do usermod -aG sysadmin $i; done

# cat /etc/group
sysadmin:x:505:sam,hari,geeta

# visudo
%sysadmin       localhost=NOPASSWD: /usr/sbin/useradd, /usr/bin/passwd

# su - hari
$ sudo useradd devi
$ id devi
uid=506(devi) gid=507(devi) groups=507(devi)

Monday, March 16, 2015

showmount command - get nfs share



# more showmount.ksh
#!/bin/ksh
server=`echo $1 | cut -f1 -d':'`
fs=`echo $1 | cut -f2 -d':'`
showmount -e $server | grep "$fs"
#

Some tips

Some tips

Friday, March 13, 2015

How To install/repair grub on RHEL 6

How To install grub.
If you have corrputed grub, you can install it using the follwing instructions.

Pre-requisite
1. Access to OS boot image or CD.
2. Access to console if virtual environment.

Steps
1. Boot your system using your boot (1st cd/DVD/Image) image.
2. Boot your system and go to rescue mode

linux rescue


Note: Make sure you have same version of OS copy that of the installed OS.
3. Just follow the prompt.



The rescue environment will try to find the Linux installation and mount it under /mnt/sysimage.

Your root fs is mounted at /mnt/sysimage and cd to it.
# cd chroot /mnt/sysimage

if you know your disk, just run the grub install command.

grub-install /dev/sda

exit from the prmpt and boot the system.

9. System will Reboot !!! enjoy

How to install grub


Sunday, March 8, 2015

RHEL7 - How to assign ip address


How to assign static ip to RHEL 7 host.

Note: Network Manager is installed by default.

To verify the status of Network Manager service:

$ systemctl status NetworkManager.service
under Active section, you will see active (running)


Find out the active interface managed by Network Manager
$ nmcli dev status

You will find the output with status.


Assigning static IP without Network Manager

Go to network config location
# cd /etc/sysconfig/network-scripts
# vi ifcfg-interface

Now change the following parameter
BOOTPROTO=static
IPADDR=192.168.10.120
NETMASK=255.255.255.0
NM_CONTROLLED=no
ONBOOT=yes

wq!
other stuff,  you can leave as it is not you can remove all reference to ipv6

Restart netwok service
# systemctl restart network.service

Verify if ip is assigned
# ip add


Using Network Manager to set up ip address

nmtui (Network Manager Text User Interface) can be used to configure on terminal window.

# yum search NetworkManager
# yum install NetworkManager-tui

find your interface and use nmtui to configure it.
# nmtui edit interface
it infact allow you to make changes to /etc/sysconfig/network-scripts/ifcfg.interface file.

make changes based on your requirement options.
and restart your service
# systemctl restart network.service


Please remember to add gateway info either on ifcfg-interface or /etc/sysconfig/network file

Find the size of the disk that is part of ASM disk

# lvs
# fdisk -l
# multipath -ll | more
# multipath -ll | grep -A 1 ASMDISK
# multipath -ll | grep -A 1 ASMDISK | awk '{l1=$0;getline;print l1 " " $0}'
# multipath -ll | grep -A 1 ASMDISK | awk '{l1=$0;getline;print l1 " " $0}' | awk '{print $1 " " $5}'
# multipath -ll | grep -A 1 ASMDISK | awk '{l1=$0;getline;print l1 " " $0}' | awk '{print $1 " " $5}' | sed -e 's/[features=1//'
# multipath -ll | grep -A 1 ASMDISK | awk '{l1=$0;getline;print l1 " " $0}' | awk '{print $1 " " $5}' | sed -e 's/[features=1//'
# multipath -ll | grep -A 1 ASMDISK | awk '{l1=$0;getline;print l1 " " $0}' | awk '{print $1 " " $5}' | sed -e 's/\[features=1//'
# multipath -ll | grep -A 1 ASMDISK | awk '{l1=$0;getline;print l1 " " $0}' | awk '{print $1 " " $5}' | sed -e 's/\[features=1//' | grep ASM
# multipath -ll | grep -A 1 ASMDISK | awk '{l1=$0;getline;print l1 " " $0}' | awk '{print $1 " " $5}' | sed -e 's/\[features=1//' | grep ASM
# multipath -ll | grep -A 1 ASMDISK | awk '/ASMDISK/ {print $1} /size=/ {print substr($0,1,11)}' | awk '/ASMDISK/ {l1=$0; getline; print l1 " " $0}'  | sort
ASMDISK01 [size=101G]
ASMDISK02 [size=101G]
ASMDISK02 [size=101G]
ASMDISK04 [size=101G]
ASMDISK05 [size=101G]
ASMDISK06 [size=101G]
ASMDISK07 [size=101G]
ASMDISK08 [size=101G]
ASMDISK09 [size=101G]
ASMDISK10 [size=101G]
ASMDISK19 [size=101G]
ASMDISK21 [size=101G]



# ls -l /dev/mapper
# multipath -ll
# multipath -ll  | grep -A 1 3600

# multipath -ll  | grep -A 1 3600
SANDISK03 (360060160ccd02600481caca40112e011) dm-2 DGC,VRAID
[size=100G][features=1 queue_if_no_path][hwhandler=1 emc][rw]
--
SANDISK02 (360060160ccd02600491caca40112e011) dm-0 DGC,VRAID
[size=100G][features=1 queue_if_no_path][hwhandler=1 emc][rw]
--
SANDISK01 (360060160ccd026004a1caca40112e011) dm-1 DGC,VRAID
[size=100G][features=1 queue_if_no_path][hwhandler=1 emc][rw]

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/cciss/c0d0p3      20G  5.4G   14G  30% /
/dev/mapper/system-oraclelv
                       34G  208M   32G   1% /opt/oracle
/dev/mapper/system-datalv
                      4.9G  885M  3.8G  19% /data
/dev/mapper/system-data_oraclelv
                       20G  7.4G   12G  40% /data/oracle
/dev/mapper/sanvg-oradblv1
                      249G  115G  121G  49% /data/oradata1
/dev/mapper/sanvg-oradblv2
                       47G  181M   44G   1% /data/oralog1

# pvs -o +devices
  PV                     VG     Fmt  Attr PSize   PFree    Devices
  /dev/cciss/c0d0p5      system lvm2 a--   84.44G    7.44G /dev/cciss/c0d0p5(0)
  /dev/cciss/c0d0p5      system lvm2 a--   84.44G    7.44G /dev/cciss/c0d0p5(384)
  /dev/cciss/c0d0p5      system lvm2 a--   84.44G    7.44G /dev/cciss/c0d0p5(1504)
  /dev/cciss/c0d0p5      system lvm2 a--   84.44G    7.44G /dev/cciss/c0d0p5(1664)
  /dev/cciss/c0d0p5      system lvm2 a--   84.44G    7.44G /dev/cciss/c0d0p5(1824)
  /dev/cciss/c0d0p5      system lvm2 a--   84.44G    7.44G
  /dev/mpath/SANDISK01p1 sanvg  lvm2 a--  100.00G       0  /dev/mpath/SANDISK01p1(0)
  /dev/mpath/SANDISK02p1 sanvg  lvm2 a--  100.00G       0  /dev/mpath/SANDISK02p1(0)
  /dev/mpath/SANDISK03p1 sanvg  lvm2 a--  100.00G 1012.00M /dev/mpath/SANDISK03p1(0)
  /dev/mpath/SANDISK03p1 sanvg  lvm2 a--  100.00G 1012.00M /dev/mpath/SANDISK03p1(13314)
  /dev/mpath/SANDISK03p1 sanvg  lvm2 a--  100.00G 1012.00M

# vgs -o +devices
  VG     #PV #LV #SN Attr   VSize   VFree    Devices
  sanvg    3   2   0 wz--n- 299.99G 1012.00M /dev/mpath/SANDISK01p1(0)
  sanvg    3   2   0 wz--n- 299.99G 1012.00M /dev/mpath/SANDISK02p1(0)
  sanvg    3   2   0 wz--n- 299.99G 1012.00M /dev/mpath/SANDISK03p1(0)
  sanvg    3   2   0 wz--n- 299.99G 1012.00M /dev/mpath/SANDISK03p1(13314)
  system   1   5   0 wz--n-  84.44G    7.44G /dev/cciss/c0d0p5(0)
  system   1   5   0 wz--n-  84.44G    7.44G /dev/cciss/c0d0p5(384)
  system   1   5   0 wz--n-  84.44G    7.44G /dev/cciss/c0d0p5(1504)
  system   1   5   0 wz--n-  84.44G    7.44G /dev/cciss/c0d0p5(1664)
  system   1   5   0 wz--n-  84.44G    7.44G /dev/cciss/c0d0p5(1824)

# lvs -o +devices
  LV            VG     Attr   LSize   Origin Snap%  Move Log Copy%  Convert Devices
  oradblv1      sanvg  -wi-ao 252.00G                                       /dev/mpath/SANDISK01p1(0)
  oradblv1      sanvg  -wi-ao 252.00G                                       /dev/mpath/SANDISK02p1(0)
  oradblv1      sanvg  -wi-ao 252.00G                                       /dev/mpath/SANDISK03p1(0)
  oradblv2      sanvg  -wi-ao  47.00G                                       /dev/mpath/SANDISK03p1(13314)
  data_oraclelv system -wi-ao  20.00G                                       /dev/cciss/c0d0p5(1824)
  datalv        system -wi-ao   5.00G                                       /dev/cciss/c0d0p5(1504)
  optlv         system -wi-ao  12.00G                                       /dev/cciss/c0d0p5(0)
  oraclelv      system -wi-ao  35.00G                                       /dev/cciss/c0d0p5(384)
  tmplv         system -wi-ao   5.00G                                       /dev/cciss/c0d0p5(1664)



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