DevOps

Tuesday, 5 August 2014

Scripting Lab Exercise-2

Lab Exercise-2
1.    Create a data file called employee in the format given below:
a. EmpCode    Character
b. EmpName   Character
c. Grade           Character
d. Years of experience    Numeric
e. Basic Pay     Numeric
$vi employee
A001           ARJUN       E1      01      12000.00
A006           Anand         E1      01      12450.00
A010           Rajesh         E2      03      14500.00
A002           Mohan         E2      02      13000.00
A005           John             E2      01      14500.00
A009           Denial SmithE2      04      17500.00
A004           Williams      E1      01      12000.00
2.)  Sort the file on EmpCode.
$cut –f1 employee | sort
1.    Sort the file on EmpName.
$cut –f2 employee | sort
1.    Sort the file on
(i) Decreasing order of basic pay
(ii) Increasing order of years of experience.
(i) $cut –f5 employee | sort –r
(ii) $cut –f4 employee | sort
1.    Display the number of employees whose details are included in the file.
wc –l
1.    Display all records with ‘smith’ a part of employee name.
cut –f2 –d “ ” employee | grep ‘^[smith]’ | wc –l
1.    Display all records with EmpName starting with ‘B’.
$cut –f2 employee | grep ‘^[B]’ | wc –l
1.    Display the records on Employees whose grade is E2 and have work experience of 2 to 5 years.
$cut –f3 employee | grep ‘[*2] | cut –f4 employee | grep ‘[2-5]’
1.    Store in ‘file 1’ the names of all employees whose basic pay is between 10000 and 15000.
$cut –f2,5 employee | grep ‘[10000-15000]’ > rec
10. Display records of all employees who are not in grade E2.

$cut –f3 employee | grep ‘[*1]’

Scripting Lab Exercise-1

Lab Exercise-1
1.    WAP that accepts user name and reports if user logged in.
echo “Press or enter the user name”
read a
who >userlist
if grep $a userlist
then
echo “user logged on”
else
echo “user not logged on”
fi

2.    WAP that takes a filename as input and checks if it is executable, if not make it executable.
echo “Enter your file name”
read a
if [ ! –e $a ]
then
echo “file not exist”
elif [ ! –x $a ]
then
echo “file is not executable”
else
echo “we made it executable”
chmod 777 $a
fi

3.  WAP to take string as command line argument and reverse it.
echo “ Enter the string you want to reverse”
read string
len=`echo –n $string |wc –c`
echo “No. of characteristics : $len”
while test $len –gt 0
do
rev =$rev `echo $string | cut –c $len`
len=`expr $len – 1`
done
echo “The reverse string is : $rev”

4. WAP which displays the following menu and executes the option selected by user:
1. ls
2. pwd
3. ls –l
4. ps -fe
printf “\n\t 1. ls \n\t 2. pwd \n\t 3. ls -l \n\t 4.ps -fe\n\t “
echo “Enter your choice”
read a
case $a in
1) ls ;;
2)pwd ;;
3)ls -l;;
4)ps -fe;;
*)echo “Enter correct value”
esac

5. WAP to print 10 9 8 7 6 5 4 3 2 1 .
for i in 10 9 8 7 6 5 4 3 2 1
do
echo “$i”
done

6. WAP that prompts user for a starting value & counts down from there.
echo “Enter any value for countdown”
read a
while test $a -gt 0
do
echo $a
a=`expr $a – 1`
done
7. WAP that accepts initial value as a command line argument for ex.         If user writes contdown2 12 it should display the value from 12 to 1.
a=$1
while test $a -gt 0
do
echo $a
a=`expr $a – 1`
done

8. WAP that replaces all “*.txt” file names with “*.txt.old” in the current.
for i in *.txt
do
mv “ $i ” “ $i”.old

done

Monday, 14 July 2014

NDD commands

Here are the commands that are used to change the speed of the NIC(Ethernet) card:

Interface       Speed           Duplex
---------       -----           ------
hme0            100 Mbit/s      full
hme1            100 Mbit/s      full
hme2            100 Mbit/s      full
Setting NIC speed and duplex
Solaris is often unable to correctly auto-negotiate duplex settings with a link partner (e.g. switch), especially when the switch is set to 100Mbit full-duplex. You can force the NIC into 100Mbit full-duplex by disabling auto-negotiation and 100Mbit half-duplex capability.

Example with
hme0:

1. Make the changes to the running system.
# ndd -set /dev/hme adv_100hdx_cap 0
# ndd -set /dev/hme adv_100fdx_cap 1
# ndd -set /dev/hme adv_autoneg_cap 0


2. Make kernel parameter changes to preserve the speed and duplex settings after a reboot.
# vi /etc/system

Add:
# set hme:hme_adv_autoneg_cap=0
# set hme:hme_adv_100hdx_cap=0
# set hme:hme_adv_100fdx_cap=1


Note: the
/etc/system change affects all hme interfaces if multiple NICs are present (e.g. hme0, hme1).


The /etc/system settings listed above are not supported for configuring ce Ethernet adapters during system startup; you may either use ndd commands in an /etc/rc?.d script or create a /platform/sun4u/kernel/drv/ce.conf file with appropriate settings.

Example:
/etc/init.d/nddconfig

#!/bin/sh

ndd -set /dev/ce instance 0
ndd -set /dev/ce adv_1000fdx_cap 0
ndd -set /dev/ce adv_1000hdx_cap 0
ndd -set /dev/ce adv_100fdx_cap 1
ndd -set /dev/ce adv_100hdx_cap 0
ndd -set /dev/ce adv_10fdx_cap 0
ndd -set /dev/ce adv_10hdx_cap 0
ndd -set /dev/ce adv_autoneg_cap 0


# ln -s /etc/init.d/nddconfig /etc/rc2.d/S31nddconfig

$ dmesg | grep ce0
Jan 20 11:05:01 crmmdb22 genunix: [ID 611667 kern.info] NOTICE: ce0: xcvr addr:0x01 - link up 100 Mbps half duplex
Jan 20 11:05:15 crmmdb22 genunix: [ID 408822 kern.info] NOTICE: ce0: no fault external to device; service available
Jan 20 11:05:15 crmmdb22 genunix: [ID 611667 kern.info] NOTICE: ce0: xcvr addr:0x01 - link up 100 Mbps full duplex
Manually determining NIC speed and duplex
If you have ce or bge interfaces, use kstat ce and kstat bge, respectively, to return NIC settings. All other interfaces may use ndd to determine NIC settings.

ndd example with hme0, assuming "instance" is 0:

# ndd -get /dev/hme link_mode
Interpretation:
0 -- half-duplex
1 -- full-duplex


# ndd -get /dev/hme link_speed
Interpretation:
0 -- 10 Mbit
1 -- 100 Mbit
1000 -- 1 Gbit


To query a different NIC, such as
hme1, set the "instance" to 1, and then perform the link_mode and link_speed queries above.

# ndd -set /dev/hme instance 1

Note: the
ndd commands above must be run as root. Otherwise, you will receive errors such as "couldn't push module 'hme0', No such device or address."
ce Ethernet adapters
Older versions of the Sun GigaSwift Ethernet 1.0 driver do not support the ndd link_mode and link_speed parameters. You may either install the latest Sun GigaSwift Ethernet adapter patch (111883) or you may use kstat ce ce_device to get speed and duplex information for ce Ethernet adapters.

For example (from
http://www.samag.com/documents/s=9142/sam0405l/0405l.htm):

$ netstat -k ce | egrep 'link_speed|link_status|link_duplex'

Interpretation:
link_up - 0 down, 1 up
link_speed - speed in Mbit/s
link_duplex - 1 half duplex, 2 full duplex, 0 down
Host/link partner mismatch example
A large number of output errors or collisions may indicate a host and link partner mismatch. The following is netstat -in output from a system configured for 100 half-duplex while the switch was configured for 100 full-duplex.

Name  Mtu   Net/Dest     Address      Ipkts      Ierrs Opkts       Oerrs     Collis    Queue
ce0   1500  192.168.1.0  192.168.1.1  2707133478 25    2895422910  142310052 182856975 0

In this example, the switch was configured for 100 half-duplex and the system was configured for 100 full-duplex. Note the percentage of Ierrs/Ipkts (~ 1.7%).

Name  Mtu   Net/Dest     Address      Ipkts      Ierrs Opkts       Oerrs     Collis    Queue

qfe1  1500  10.0.0.0     10.0.0.3     1430247    24663 1779341     0         0         0
CHANGELOG
2007/07/10 -- Added e1000g interfaces
2006/11/29 -- Added dmfe interfaces, fixed bge and ce interfaces, many other modifications and fixes.
2006/04/27 -- Solaris 7 and earlier include subinterface information with netstat -i. Patch by Royce Williams to only query physical NIC interfaces.
2006/03/09 -- Fixed bge interfaces, added support for iprb interfaces, added "support" for le interfaces, modified script to only require root access if using /usr/sbin/ndd to determine NIC speed and duplex settings
2005/05/25 -- Fixed ce interface handling.
2004/09/15 -- Added support for ce and bge interfaces

Ip-forwarding
IP forwarding allows you to forward all requests coming for a certain port or URL to be redirected to a specified IP address.
ip forwarding becomes enabled automatically when system detects more then one interface at the booting time . The file involved is /etc/rc2.d/S69inet .
ipforwarding is on by default but can be turned off by following command :
#ndd -set /dev/ip ip_forwarding 0
Router Configuration
After interfaces and ipaddess have been configured the system needs a default router which will allow the machine to talk to world outside of local network .
You can specify a particular route for a particular address as in following example
#route add -net 10.0.0.0 -netmask 255.0.0.0 172.40.30.1 1
if the the destination ipaddess is not defined in this manner system forwards all requests to the default router .
default route is defined manually by editing /etc/defaultrouter file and putting router’s ipaddress entry in it. This file is read by /etc/rc2.d/S69inet file during the booting process and entry added to the routing table .
The route can be defined online also using routeadd command but the changes will be lost on reboot .To make changes permanent make sure to put an entry in /etc/defaultrouter.
#route add default 205.100.155.2 1
#route change default 205.100.155.2 1
The 1 at the end is the number of hops to the next gateway.

If an interface is not responding to the network, check to be sure it has the correct IP address and netmask , network cables are fine .