Monday, June 18, 2012

Unix Programs

  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
  1. 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 executable”
else
echo “we made it executable”
chmod 777 $a
fi
5.  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”
6. 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
7. 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
8. 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
9. 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
10. WAP that replaces all “*.txt” file names with “*.txt.old” in the current.
for i in *.txt
do
mv “ $i ” “ $i”.old
done

  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
  1. Display records of all employees who are not in grade E2.
$cut –f3 employee | grep ‘[*1]’
  1. WAP that asks for the user’s favorite color and if it is not ‘red’ informs him that it is wrong answer, waits for 3 sec, clears the screen and asks the question again.
b=red
echo “enter your favorite color : ”
read a
c=`expr $a = $b`
if test $c –eq 1
then
echo “your favorite color is : $a”
else
while test $c –eq 0
do
echo “ your answer is wrong”
sleep 3
clear
echo “enter your favorite color :”
read a
c=`expr $a = $b`
done
echo “your favorite color is : $a”
fi
  1. WAP that reads each line of a target file, then writes the line back to stdout, but with an extra blank line following. This has the effect of a double spacing the file. Include all necessary code whether the script gets the necessary command line argument (a filename), and whether the specified file exists. When the script runs correctly, modify it to triple-space the target file. Finally, write a script to remove all blank lines from the target file, single-spacing it.
if test –e $1 –a –f  $1
then
t=’tty’
exec < $1
while read line
do
echo $line
echo
done
exec > $2
exec < $1
while read line
do
echo $line
echo
echo
done
fi
  1. WAP that echoes itself to stdout, but backwards.
echo “enter your text”
cat > f1
rev f1 | cat > f2
cat f2
  1. Write a script function that determines if an argument passed to it is an integer or a string. The function will return TRUE(0) if passed an integer, and FALSE(1) if passed a string.
[HINT: what does the following expression returns when $1 is not an integer? expr $1 + 0
function check()
{
expr $1 + 0
if [ $? –eq 0 ]
then
echo “argument is integer”
else
echo “not integer”
fi
}
check
7.  A “lucky number” is one whose individual digits add upto 7, in successive additions. For ex. 62431 is a lucky no. (6+4+2+3+1=16, 1+6=7). Find all “lucky numbers” between 1000 and 10000.
echo “lucky number between 1000 to 10000:”
a=1001
while [ $a –lt 10000]
do
n=$a
sd=0
sum=0
while [ $n –gt 0 ]
do
sd=$(( $n % 10 ))
n=$(( $n / 10))
sum=$(( $sum + $sd))
done
n=$sum
sumdig=0
while [ $n –gt 0 ]
do
sd=$(( $n % 10 ))
n=$(( $n / 10))
sumdig=$(( $sumdig + $sd))
done
if [ $sumdig –eg 10 ]
then
n=$sumdig
sd=$(( $n % 10 ))
n=$(( $n / 10))
sumdig=$(( $sumdig + $sd))
fi
if [ $sumdig –eq 7]
then
echo “lucky Number : $a”
fi
a=$(( $a + 1))
done
8. Solve a “quadratic” equation of the form Ax^2+Bx +C=0. Have a script take as arguments the coefficients A, B and C and returns the solutions to four decimal places.
[HINT: pipe the coefficients to bc, using the well known formula, x= (-B + /- sqrt (B^2 – 4AC))/2A].
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main
{
int a, b, c, deter;
float r1,r2;
clrscr();
printf(“Enter coefficients A,B and C (Integers)”);
scanf(“%d%d%d”, &a,&b,&c);
deter=(b*b)-(4*a*c);
if(deter<0)
{
printf(“Roots are imaginary”);
}
if(deter>0)
{
printf(“Roots are real as follows”);
r1=(-b+sqrt(deter))/2*a;
r2=(-b-sqrt(deter))/2*a;
printf(“% .4f \n % .4f”, r1,r2);
}
if(deter=0)
{
printf(“Roots are equal”);
r2=-b/2*a;
printf(“% .4f\n% .4f”,r1,r2);
}
getch();
}
1) Write a shell script to ask your name, program name and enrollment number and print it on the screen.
Echo “Enter your name:”
Read Name
Echo “Enter your program name:”
Read Prog
Echo “Enter your enrollment number:”
Read Enroll
Clear
Echo “Details you entered”
Echo Name: $Name
Echo Program Name: $Prog
Echo Enrolment Number: $Enroll
2) Write a shell script to find the sum, the average and the product of the four integers entered
Echo “Enter four integers with space between”
Read a b c d
Sum =`expr $a + $b + $c + $d`
Avg =`expr $sum / 4`
Dec =`expr $sum % 4`
Dec =`expr \ ($dec \* 1000 \) / 4`
Product =`expr $a \* $b \* $c \* $d`
Echo Sum = $sum
Echo Average = $avg. $dec
Echo Product = $product
3) Write a shell program to exchange the values of two variables
Echo “Enter value for a:”
Read a
Echo “Enter value for b:”
Read b
Clear
Echo “Values of variables before swapping”
Echo A = $a
Echo B = $b
Echo Values of variables after swapping
a = `expr $a + $b`
b = `expr $a – $b`
a = `expr $a – $b`
Echo A = $a
Echo B = $b
4) Find the lines containing a number in a file
Echo “Enter filename”
Read filename
Grep [0-9] $filename
5) Write a shell script to display the digits which are in odd position in a given 5 digit number
Echo “Enter a 5 digit number”
Read num
n = 1
while [ $n -le 5 ]
do
a = `Echo $num | cut -c $n`
Echo $a
n = `expr $n + 2`
done
6) Write a shell program to reverse the digits of five digit integer
Echo “Enter a 5 digit number”
Read num
n = $num
rev=0
while [ $num -ne 0 ]
do
r = `expr $num % 10`
rev = `expr $rev \* 10 + $r`
num = `expr $num / 10`
done
Echo “Reverse of $n is $rev”
7) Write a shell script to find the largest among the 3 given numbers
Echo “Enter 3 numbers with spaces in between”
Read a b c
1 = $a
if [ $b -gt $l ]
then
l = $b
fi
if [ $c -gt $l ]
then
l = $c
fi
Echo “Largest of $a $b $c is $l”
8) Write a shell program to search for a given number from the list of numbers provided using binary search method
Echo “Enter array limit”
Read limit
Echo “Enter elements”
n = 1
while [ $n -le $limit ]
do
Read num
eval arr$n = $num
n = `expr $n + 1`
done
Echo “Enter key element”
Read key
low = 1
high = $n
found = 0
while [ $found -eq 0 -a $high -gt $low ]
do
mid = `expr \( $low + $high \) / 2`
eval t = \$arr$mid
if [ $key -eq $t ]
then
found = 1
elif [ $key -lt $t ]
then
high = `expr $mid – 1`
else
low = `expr $mid + 1`
fi
done
if [ $found -eq 0 ]
then
Echo “Unsuccessful search”
else
Echo “Successful search”
fi
9) Write a shell program to concatenate two strings and find the length of the resultant string
Echo “Enter first string:”
Read s1
Echo “Enter second string:”
Read s2
s3 = $s1$s2
len = `Echo $s3 | wc -c`
len = `expr $len – 1`
Echo “Concatenated string is $s3 of length $len ”
10) Write a shell program to find the position of substring in given string
Echo “Enter main string:”
Read main
l1 = `Echo $main | wc -c`
l1 = `expr $l1 – 1`
Echo “Enter sub string:”
Read sub
l2 = `Echo $sub | wc -c`
l2 = `expr $l2 – 1`
n = 1
m = 1
pos = 0
while [ $n -le $l1 ]
do
a = `Echo $main | cut -c $n`
b = `Echo $sub | cut -c $m`
if [ $a = $b ]
then
n = `expr $n + 1`
m = `expr $m + 1`
pos = `expr $n – $l2`
r = `expr $m – 1`
if [ $r -eq $l2 ]
then
break
fi
else
pos = 0
m = 1
n = `expr $n + 1`
fi
done
Echo “Position of sub string in main string is $pos”
11) Write a shell program to display the alternate digits in a given 7 digit number starting from the first digit
Echo “Enter a 7 digit number”
Read num
n = 1
while [ $n -le 7 ]
do
a = `Echo $num | cut -c $n`
Echo $a
n = `expr $n + 2`
done
12) Write a shell program to find the gcd for the 2 given numbers
Echo “Enter two numbers with space in between”
Read a b
m = $a
if [ $b -lt $m ]
then
m = $b
fi
while [ $m -ne 0 ]
do
x = `expr $a % $m`
y = `expr $b % $m`
if [ $x -eq 0 -a $y -eq 0 ]
then
Echo “gcd of $a and $b is $m”
break
fi
m = `expr $m – 1`
done
13) Write a shell program to check whether a given string is palindrome or not.
Echo “Enter a string to be entered:”
Read str
Echo
len = `Echo $str | wc -c`
len = `expr $len – 1`
i = 1
j = `expr $len / 2`
while test $i -le $j
do
k = `Echo $str | cut -c $i`
l = `Echo $str | cut -c $len`
if test $k != $l
then
Echo “String is not palindrome”
exit
fi
i = `expr $i + 1`
len = `expr $len – 1`
done
Echo “String is palindrome”
14) Write a shell program to find the sum of the series sum=1+1/2+…+1/n
Echo “Enter a number”
Read n
i = 1
sum = 0
while [ $i -le $n ]
do
sum = `expr $sum + \ ( 10000 / $i \)`
i = `expr $i + 1`
done
Echo “Sum n series is”
i = 1
while [ $i -le 5 ]
do
a = `Echo $sum | cut -c $i`
Echo -e “$a\c”
if [ $i -eq 1 ]
then
Echo -e “.\c”
fi
i = `expr $i + 1`
done
15) Write a shell script to find the smallest of three numbers
Echo “Enter 3 numbers with spaces in between”
Read a b c
s = $a
if [ $b -lt $s ]
then
s = $b
fi
if [ $c -lt $s ]
then
s = $c
fi
Echo “Smallest of $a $b $c is $s”
16) Write a shell program to add, subtract and multiply the 2 given numbers passed as command line arguments
add = `expr $1 + $2`
sub = `expr $1 – $2`
mul = `expr $1 \* $2`
Echo “Addition of $1 and $2 is $add”
Echo “Subtraction of $2 from $1 is $sub”
Echo “Multiplication of $1 and $2 is $mul”
17) Write a shell program to convert all the contents into the uppercase in a particular file
Echo “Enter the filename”
Read filename
Echo “Contents of $filename before converting to uppercase”
Echo —————————————————-
cat $filename
Echo —————————————————-
Echo “Contents of $filename after converting to uppercase”
Echo —————————————————
tr ‘[a-z]‘ ‘[A-Z]‘ < $filename Echo ————————————————— 18) Write a shell program to count the characters, count the lines and the words in a particular file Echo “Enter the filename” Read file w = `cat $file | wc -w` c = `cat $file | wc -c` l = `grep -c “.” $file` Echo “Number of characters in $file is $c” Echo “Number of words in $file is $w” Echo “Number of lines in $file is $l” 19) Write a shell program to concatenate the contents of 2 files Echo “Enter first filename” Read first Echo “Enter second filename” Read second cat $first > third
cat $second >> third
Echo “After concatenation of contents of entered two files”
Echo —————————————————-
cat third | more
Echo —————————————————-
20) Write a shell program to count number of words, characters, white spaces and special symbols in a given text
Echo “Enter a text”
Read text
w = `Echo $text | wc -w`
w = `expr $w`
c = `Echo $text | wc -c`
c = `expr $c – 1`
s = 0
alpha = 0
j = ` `
n = 1
while [ $n -le $c ]
do
ch = `Echo $text | cut -c $n`
if test $ch = $j
then
s = `expr $s + 1`
fi
case $ch in
a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z) alpha=`expr $alpha + 1`;;
esac
n = `expr $n + 1`
done
special = `expr $c – $s – $alpha`
Echo “Words = $w”
Echo “Characters = $c”
Echo “Spaces = $s”
Echo “Special symbols = $special”
24) Write a shell program to find factorial of given number
Echo “Enter a number”
Read n
fact = 1
i = 1
while [ $i -le $n ]
do
fact = `expr $fact \* $i`
i = `expr $i + 1`
done
Echo “Factorial of $n is $fact”
25) Write a shell script to find the average of the numbers entered in command line
n = $#
sum = 0
for i in $*
do
sum = `expr $sum + $i`
done
avg = `expr $sum / $n`
Echo “Average=$avg”
26) Write a shell script to sort the given numbers in descending order using Bubble sort
Echo
i = 1
k = 1
Echo “Enter no. of integers to be sorted”
Read n
Echo “Enter the numbers”
while [ $i -le $n ]
do
Read num
x[$k] = `expr $num`
i = `expr $i + 1`
k = `expr $k + 1`
done
x[$k] = 0
k = 1
Echo “The number you have entered are”
while [ ${x[$k]} -ne 0 ]
do
Echo “${x[$k]}”
k = `expr $k + 1`
done
k = 1
while [ $k -le $n ]
do
j = 1
while [ $j -lt $n ]
do
y = `expr $j + 1`
if [ ${x[$j]} -gt ${x[$y]} ]
then
temp = `expr ${x[$j]}`
x[$j] = `expr ${x[$y]}`
x[$y] = `expr $temp`
fi
j = `expr $j + 1`
done
k = `expr $k + 1`
done
k = 1
Echo “Number in sorted order…”
while [ ${x[$k]} -ne 0 ]
do
Echo “${x[$k]}”
k = `expr $k + 1`
done
27) Write a shell program to find the sum of all the digits in a given 5 digit number
Echo “Enter a 5 digit number”
Read num
sum = 0
while [ $num -ne 0 ]
do
r = `expr $num % 10`
sum = `expr $sum + $r`
num = `expr $num / 10`
done
Echo “sum = $sum”
28) Write a shell script to generate fibonacci series
Echo “how many fibonacci numbers do u want “
Read limit
a = 0
b = 1
d = 1
Echo “————————————————————-”
Echo -n $a
Echo -n ” “
while test $d -le $limit
do
c = `expr ${a} + ${b}`
Echo -n $c
Echo -n ” “
b = $a
a = $c
d = `expr $d + 1`
done
29) Shell Script to check whether given year is leap year or not
Echo -n “Enter the year(yyyy) to find leap year :- “
Read year
d = `expr $year % 4`
b = `expr $year % 100`
c = `expr $year % 400`
if [ $d -eq 0 -a $b -ne 0 -o $c -eq 0 ]
then
Echo “year is leap year”
else
Echo “not leap year”
fi
30) Shell Script to print alternate digit when a 7 digit number is passed
Echo -n “Enter a 7 digit number:- “
Read number
len = `echo $number | wc -c`
flag = 1
while test $flag -le $len
do
Echo $number | cut -c$flag
flag = `expr $flag + 2`
done
31) Shell script to find average of number at given command line
total = 0
count = $#
for i #or u can append ( in $*) to get same result.
do
total = `expr $total + $i`
done
avg1 = `expr $total / $count`
avg2 = `expr $total % $count`
avg2 = `expr $avg2 \* 100 / $count`
Echo “The Average is :- $avg1.$avg2″
32) Shell Script to reverse a inputted string and show it
Echo -n “enter the string u want to reverse:-”
Read string
len = `Echo -n $string |wc -c`
Echo “no of character is:- $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 “
33) Shell script to find occurrence of particular digit in inputted number
Echo -n “enter any number:-”
Read number
Echo -n “which digit number do u want to count:-”
Read digit
len = `echo -n $number |wc -c`
Echo “the length of number is:-$len”
count = 0
while test $len -gt 0
do
flag = `Echo -n $number |cut -c $len`
if test $flag -eq $digit
then
count = `expr $count + 1`
fi
len = `expr $len – 1`
done
Echo “|$digit| occurred |$count| times in number ($number)”
34) Shell Script to find whether number given is even or odd
Echo -n “enter any integer number to find even and odd :-”
Read number
rem = `expr $number % 2`
if test $rem -eq 0
then
Echo “number is even”
else
Echo “number is odd”
fi
35) write shell script to generate fibonacci series
#!/bin/bash
#shell script to generate fibonacci series
echo “how many fibonacci numbers do u want “
read limit
a=0
b=1
d=1
echo “————————————————————-”
echo -n $a
echo -n ” “
while test $d -le $limit
do
c=`expr ${a} + ${b}`
echo -n $c
echo -n ” “
b=$a
a=$c
d=`expr $d + 1`
done
36) write shell script to find wheather a particular year is a leap year or not
#!/bin/bash
#shell script to find wheather a particular year is a leap year or not
echo -n “Enter the year(yyyy) to find leap year :- “
read year
d=`expr $year % 4`
b=`expr $year % 100`
c=`expr $year % 400`
if [ $d -eq 0 -a $b -ne 0 -o $c -eq 0 ]
then
echo “year is leap year”
else
echo “not leap year”
fi
37) write shell script to print alternate digits when a 7 digit number is passed as input
#!/bin/bash
#shell script to print alternate digits when a 7 digit number is passed as input
echo -n “Enter a 7 digit number:- “
read number
len=`echo $number | wc -c`
flag=1
while test $flag -le $len
do
echo $number | cut -c$flag
flag=`expr $flag + 2`
done
38) write shell script to find average of numbers given at command line
#Tue May 28 11:12:41 MUT 2002
total=0
count=$#
for i #or u can append ( in $*) to get same result.
do
total=`expr $total + $i`
done
avg1=`expr $total / $count`
avg2=`expr $total % $count`
avg2=`expr $avg2 \* 100 / $count`
echo “The Average is :- $avg1.$avg2″
39) write shell script to find wheather a given word is palindrome or not
#Sun Jun 9 12:06:14 MUT 2002 –By Mukesh
clear
echo -n “enter the name :-”
read name
len=`echo -n $name | wc -c`
echo “Length of the name is :-”$len
while [ $len -gt 0 ]
do
rev=$rev`echo $name | cut -c$len`
len=`expr $len – 1`
done
echo “Reverse of the name is :-”$rev
if [ $name = $rev ]
then echo “It is a palindrome”
else
echo “It is not a palindrome”
fi
40) write shell script to reverse a inputed string and show it.
#!/bin/bash
#shell script to reverse a inputed string and show it.
echo -n “enter the string u want to reverse:-”
read string
len=`echo -n $string |wc -c`
echo “no of character is:- $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 “
41) write shell script to count occurence of a perticular digit in inputted number.
#!/bin/bash
#shell script to count occurence of a perticular digit in inputted number.
echo -n “enter any number:-”
read number
echo -n “which digit number do u want to count:-”
read digit
len=`echo -n $number |wc -c`
echo “the length of number is:-$len”
count=0
while test $len -gt 0
do
flag=`echo -n $number |cut -c $len`
if test $flag -eq $digit
then
count=`expr $count + 1`
fi
len=`expr $len – 1`
done
echo “|$digit| occured |$count| times in number ($number)”
42) write shell script to find even or odd.
#!/bin/bash
#shell script to find even or odd.
echo -n “enter any integer number to find even and odd :-”
read number
rem=`expr $number % 2`
if test $rem -eq 0
then
echo “number is even”
else
echo “number is odd”
fi


Monday, June 11, 2012

UNIX – SHELL PROGRAMMING –LAB



1.  Write a shell script to accept even no of file names. Suppose 4 file names are supplied then the first file should get copied into the second file the third file should get copied into the fourth file and so on. If odd no. of file names is supplied then no copying should take place and error message should be displayed?

 
CheckNo=`expr $# % 2`
    if [ $CheckNo -ne 0 ]
    then
            echo "Enter Even Number Of Arguments."else
            cnt=1
            while [ $cnt -lt $# ]
            do
                    cp $1 $2
                    shift
                    shift
                    cnt=`expr $cnt + 2`
            done
    fi
2.  Write a script to list the files which have having read & execute permissions in the given directory?
3.  Write a shell program to find factorial of  given number using command line   ?
4.  Write a shell script to print the contents of a file only some range of lines. The starting and ending line numbers should be passing through command line arguments?
if [ -f $3 ]
then
if [ $1 -lt $2 ]
then
sed -n ' '$1','$2' 'p' ' $3
fi
fi
 
5   Write a shell script to take the backup of all C programs in your account on every Friday at 5 pm?
6.  Compress your home directory and copy to /tmp directory with different utilities? Then uncompress your home directory in /tmp by any one utility?
7. Write a shell script to reverse the digits of a given number.

if [ $# -ne 1 ]
then
echo "Usage: $0 number"
echo " I will find reverse of given number"
echo " For eg. $0 123, I will print 321"
exit 1
fi

n=$1
rev=0
sd=0

while [ $n -gt 0 ]
do
sd=`expr $n % 10`
rev=`expr $rev \* 10 + $sd`
n=`expr $n / 10`
done
echo "Reverse number is $rev"
8. Write a shell script to reverse the digits of a given number
9. Write a shell script to generate the factorial of a given number entered through keyboard.
10. Write a shell script to print the first even and odd numbers less than 30
11. Write a shell script to copy the source file to the target file.
12. Write a shell script which will accept different numbers and find sum of its digit.

if [ $# -ne 1 ]
then
echo "Usage: $0 number"
echo " I will find sum of all digit for given number"
echo " For eg. $0 123, I will print 6 as sum of all digit (1+2+3)"
exit 1
fi
n=$1
sum=0
sd=0
while [ $n -gt 0 ]
do
sd=`expr $n % 10`
sum=`expr $sum + $sd`
n=`expr $n / 10`
done
echo "Sum of digit for numner is $sum"


13. Write a shell script to find the mode of a file in a directory.
14. Write a menu driven program to display a menu of options and depending upon the user’s choice execute the associated command.
15. Write a shell script to display first ten positive numbers using until loop.
16. Write a shell script to Implement If-Else Ladder (Unix Program)
17.Write a shell script to link the files such that modification made by one file should be applicable to the linked file?
18.Write a script to determine whether given file is exists or not, filename is supplied as command line arguments and also display the file permissions if it exist.



19. Write a shell script for the following
     i) Redirecting the standard input
    ii) Redirecting the standard  output
    iii) Redirecting the standard error using switch case menu driven, & it should continue as long as user wants
20. Execute a command such that whenever we give NTTF <filename> it should create a directory and when ever we give REM <filename> it should delete the directory?
21. Write a shell script which displays the list of all files in the given directory
22. Write a shell script which counts the number of lines and words present in a given file.
23. Write a shell script to generate a multiplication table
24. Write a shell script that copies multiple files to a directory.
25. Write A shell script that takes a command –line argument and reports on whether it is directry ,a file,or something else
26. Write a shell script that computes the gross salary of a employee
27. Write a script to take backup at 10 am every day for selected file?
28. Execute any two commands at a time and store both the output in different files?
29. Write a program to display a message at 10:10am today and that should be sent to a mail?
30. How to make schedule for creating backup of user program for a particular user from root account?
31.  Write the shell script for the following operations using case
a.            Display all the running processes status in detail
b.            Start a process in the background for manual page for ls
c.             Display the current background process
d.            Terminate the background  process
32.  Write a shell script to add three float values using command line arguments
33. Write the shell script for List the filenames for which the 3rd character is not a digit?
34. Write a shell script to wish the user depending on his login time i.e to wish ‘good morning’, ‘good afternoon’, and ‘good evening’?

th=`date | cut –c12-13`
if [ $th –lt 12 ]
then
mesge=”good morning $LOGNAME have a nice day!”
fi
if [ $th –gt 12 –a $th –lt 16 ]
then
mesge=”good afternoon $LOGNAME”
fi
if [ $th –gt 16 –a $th –lt 20 ]
then
mesge=”good evening”
fi
echo –e “$mesg”
35. Write a shell script to show the file content in capitals for selected file by using command line arguments?
36. Write a shell script to find the given year is leap year or not?
37. write the shell script to find out the all ordinary files in your current working directory that are writable?
38. Write a script to find biggest among three entered numbers using command line arguments?

if [ $# -ne 3 ]
then
echo "$0: number1 number2 number3 are not given" >&2
exit 1
fi
n1=$1
n2=$2
n3=$3
if [ $n1 -gt $n2 ] && [ $n1 -gt $n3 ]
then
echo "$n1 is Bigest number"
elif [ $n2 -gt $n1 ] && [ $n2 -gt $n3 ]
then
echo "$n2 is Bigest number"

elif [ $n3 -gt $n1 ] && [ $n3 -gt $n2 ]
then
echo "$n3 is Bigest number"
elif [ $1 -eq $2 ] && [ $1 -eq $3 ] && [ $2 -eq $3 ]
then
echo "All the three numbers are equal"
else
echo "I can not figure out which number is biger"
fi

39. write a shell script to  Check whether the given character is small or capital?
40 Write a script to print entered no in descending order by using while loop
(eg : 5, 4, 3, 2, 1 ) using command line arguments?
41. Read a character from user if it is between A-D (print mesg: “entered character between A-D”) same way check for M-P and Q-V and display respective message?
42. Write a script for addition, subtraction, multiplication and division using command line arguments?
43. Write a script to see current date & time, username, home directory, default shell and current working directory using case statement & it should continue as long as user wants?

echo "Hello, $LOGNAME"
echo "Current date is `date`"
echo "User is `who i am`"
echo "Current direcotry `pwd`"
44. Write a shell program for making directory if that directory exists then print the mesg it’s already exists else create a directory by using command line arguments?
45. Write a shell script to check whether given name is a directory or file by using command line arguments?
46. Write a shell script to print sum of digits for entered no?
47. Write a shell script to accept date (dd,mm,yy) and increment day by 1 and check the condition and display the date (eg:20/12/2009)
48. Write a shell script to accept student information like name, class and 3 subject marks. Calculate the total and average. Result will be displayed based on average .if avg >=80 and avg <=90 (Distinction), avg >=60 and avg<=80 (First class), avg>=35 and avg<=59 (Second class), avg<35 (Fail)
49.   Write a shell script for the following using case statement
i)             Display the user who are all logged in system
ii)            Display the terminal type of the user
iii)           Compress the file,file name should get it from the user at runtime
iv)           Display the content of the compressed file
v)            Create the hardlink and softlink the filename should get it  from the user
vi)           Display the longlist of the hardling and softlink file
50.    Write a c program to find weather the given number is palindrome or not

Wednesday, December 21, 2011

Linux Mail Server Setup

Postfix SMTP Server Setup Howto for RHEL/CentOS 6

INSTALL POSTFIX AND DOVECOT 

 [root@ttc ~]# yum install -y postfix dovecot

Edit the file /etc/postfix/main.cf and uncommend the lines below.

inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
home_mailbox = Maildir/
In mydestination make the comment in other two lines
If Your are using ipv4 set ipv4 like in ipv6 also for both set all
inet_protocols = ipv4
 
Make sure that all mail_spool_directory lines are commented out. 
Otherwise, it will override the setting in the home_mailbox line above. 
 
Start the Service
# chkconfig postfix on
       # service postfix restart
       # service postfix status
 
Add a user like nan
Type in the command newaliases in a terminal window. 
This will rebuild the aliases database file. 
 
# newaliases
 
In the Terminal window, type in the highlighted commands below
[root@ttc ~]# telnet localhost smtp
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 ttc.hpserver.com ESMTP Postfix
ehlo localhost
250-ttc.hpserver.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<nan>
250 2.1.0 Ok
rcpt to:<nan>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Hi Nan  This is test mail 
Created on 22/12/2011
.
250 2.0.0 Ok: queued as DB7C213F6AC
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@ttc ~]# 
      
To check if the mail indeed exists

 [root@ttc ~]# cat /home/nan/Maildir/new/1324552225.V808I9f698M53702.ttc.hpserver.com
Return-Path: <nan@ttc.hpserver.com>
X-Original-To: nan
Delivered-To: nan@ttc.hpserver.com
Received: from localhost (localhost.localdomain [127.0.0.1])
    by ttc.hpserver.com (Postfix) with ESMTP id DB7C213F6AC
    for <nan>; Thu, 22 Dec 2011 16:39:18 +0530 (IST)
Message-Id: <20111222110948.DB7C213F6AC@ttc.hpserver.com>
Date: Thu, 22 Dec 2011 16:39:18 +0530 (IST)
From: nan@ttc.hpserver.com
To: undisclosed-recipients:;

Hi Nan  This is test mail
Created on 22/12/2011
[root@ttc ~]#

Dovecot POP3/IMAP Server Setup

Configure Dovecot

The settings for Dovecot are spread out across several files. Edit the files listed below and uncomment and updates its lines accordingly. 

/etc/dovecot/dovecot.conf
protocols = pop3 imap lmtp
/etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir
/etc/dovecot/conf.d/20-pop3.conf
pop3_uidl_format = %08Xu%08Xv
pop3_client_workarounds = outlook-no-nuls oe-ns-eoh

Start the Dovecot service

[root@ttc ~]# service dovecot restart
Stopping Dovecot Imap:                                     [FAILED]
Starting Dovecot Imap:                                     [  OK  ]
[root@ttc ~]# chkconfig dovecot on
In the Terminal window, type in the highlighted commands below.

[root@ttc ~]# telnet localhost pop3
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Dovecot ready.
user nan
+OK
pass nan
+OK Logged in.
list
+OK 2 messages:
1 471
2 479
.
retr 1
+OK 471 octets
Return-Path: <nan@ttc.hpserver.com>
X-Original-To: nan
Delivered-To: nan@ttc.hpserver.com
Received: from localhost (localhost.localdomain [127.0.0.1])
    by ttc.hpserver.com (Postfix) with ESMTP id CF3D313F6AC
    for <nan>; Thu, 22 Dec 2011 16:12:14 +0530 (IST)
Message-Id: <20111222104228.CF3D313F6AC@ttc.hpserver.com>
Date: Thu, 22 Dec 2011 16:12:14 +0530 (IST)
From: nan@ttc.hpserver.com
To: undisclosed-recipients:;

HI This is test mail to you on 22/12/2011
.
retr 2
+OK 479 octets
Return-Path: <nan@ttc.hpserver.com>
X-Original-To: nan
Delivered-To: nan@ttc.hpserver.com
Received: from localhost (localhost.localdomain [127.0.0.1])
    by ttc.hpserver.com (Postfix) with ESMTP id DB7C213F6AC
    for <nan>; Thu, 22 Dec 2011 16:39:18 +0530 (IST)
Message-Id: <20111222110948.DB7C213F6AC@ttc.hpserver.com>
Date: Thu, 22 Dec 2011 16:39:18 +0530 (IST)
From: nan@ttc.hpserver.com
To: undisclosed-recipients:;

Hi Nan  This is test mail
Created on 22/12/2011
.
quit







Friday, December 16, 2011

Setting up samba with Iptables and Selinux

  1. Install samba on the server
    • # yum install samba
  2. Create the group that all the samba users will be contained in, for example 'samba'
    • # groupadd samba
  3. Create samba users and add it to the above group, which is in this example is 'samba'. Below is the example to create a user named 'user1' and add it to group 'samba'. Set the password for user1
    • # useradd user1 -g samba
    • # passwd user1
  4. Create the directory to be shared. In this example, i will use /home/shared. Change the ownership to root and group ownership to the 'samba' group. Change permission so that only user and group can read write and execute
    • # mkdir /home/shared
    • # chown -R root.samba /home/shared
    • # chmod -R 775 /home/shared
    5.  Add the Port Numbers in the Ip tables
           [root@localhost ~]# iptables -I INPUT -p tcp -m tcp --dport 137 -j ACCEPT
           [root@localhost ~]# iptables -I INPUT -p tcp -m tcp --dport 138 -j ACCEPT
           [root@localhost ~]# iptables -I INPUT -p tcp -m tcp --dport 139 -j ACCEPT
           [root@localhost ~]# iptables -I INPUT -p tcp -m tcp --dport 445 -j ACCEPT
    6.  Save and Restart the Iptables
           [root@localhost ~]# service iptables save
           iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
           [root@localhost ~]# service iptables restart
    7. Add SELinux Settings
          # setsebool -P samba_export_all_rw on
    8.  Change the Setting in /etc/samba/smb.conf
         [Share]
         path = /var/share
         browseble = yes
         writable = yes
         valid users = nttf
      9.Add user/users to samba
        # smbpasswd -a user1
     10. Start smb service, restart if it has already been started
        [root@localhost ~]# service smb restart
        Shutting down SMB services:                                [  OK  ]
        Starting SMB services:                                     [  OK  ]
How to Open Samba Client in terminal
smbclient //<hostname>/<sharename> -U <username>
[root@localhost ~]# smbclient //192.168.0.212/share -U nttf
Enter nttf's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.5.4-68.el6]
smb: \> ls
  .                                   D        0  Fri Dec 16 14:00:21 2011
  ..                                  D        0  Fri Dec 16 12:00:26 2011

        53566 blocks of size 524288. 48561 blocks available
smb: \>

Wednesday, November 23, 2011

VNC Configuration

There are several ways to configure the vnc server. This HOWTO shows you how to configure VNC using the 'vncserver' service as supplied by CentOS.

1. Installing the required packages

The server package is called 'vnc-server'. Run the command rpm -q vnc-server.
The result will be either package vnc-server is not installed or something like vnc-server-4.0-11.el4.
If the server is not installed, install it with the command: yum install vnc-server.
The client program is 'vnc'. You can use the command yum install vnc to install the client if rpm -q vnc shows that it is not already installed.
Make sure to install a window manager in order to get a normal GUI desktop. You can use the command yum groupinstall "GNOME Desktop Environment" to install the Gnome Desktop and requirements, for example. Other popular desktop environments are "KDE" and "XFCE-4.4". XFCE is more light-weight than Gnome or KDE and available from the "extras" repository.
<!> If you are running CentOS 5, yum groupinstall "GNOME Desktop Environment" may complain about a missing libgaim.so.0. This is a known bug. Please see CentOS-5 FAQ for details.
<!> If you are running CentOS 6, the server is tigervnc-server not vnc-server.

2. Configuring un-encrypted VNC

We will be setting up VNC for 3 users. These will be 'larry', 'moe', and 'curly'.
You will perform the following steps to configure your VNC server:
  1. Create your VNC users.
  2. Set your users' VNC passwords.
  3. Edit the server configuration.
  4. Create and customize xstartup scripts.
  5. Start the VNC service.
  6. Test each VNC user.
  7. Setup the VNC service to start on reboot.
  8. Additional optional enhancements

2.1. Create your VNC users

As root:
$ su -
# useradd larry
# useradd moe
# useradd curly
# passwd larry
# passwd moe
# passwd curly

2.2. Set your users' VNC passwords

Login to each user, and run vncpasswd. This will create a .vnc directory.
[~]$ cd .vnc
[.vnc]$ ls
passwd

2.3. Edit the server configuration

Edit /etc/sysconfig/vncservers, and add the following to the end of the file.
VNCSERVERS="1:larry 2:moe 3:curly"
VNCSERVERARGS[1]="-geometry 640x480"
VNCSERVERARGS[2]="-geometry 640x480"
VNCSERVERARGS[3]="-geometry 800x600"
Larry will have a 640 by 480 screen, as will Moe. Curly will have an 800 by 600 screen.

2.4. Create xstartup scripts ( Skip this step for CentOS 6 )

We will create the xstartup scripts by starting and stopping the vncserver as root.
# /sbin/service vncserver start
# /sbin/service vncserver stop
Login to each user and edit the xstartup script. To use Larry as an example, first login as larry
[~]$ cd .vnc
[.vnc] ls
mymachine.localnet:1.log  passwd  xstartup
Edit xstartup. The original should look like:
#!/bin/sh
# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
Add the line indicated below to assure that an xterm is always present, and uncomment the two lines as directed if you wish to run the user's normal desktop window manager in the VNC. Note that in the likely reduced resolution and color depth of a VNC window the full desktop will be rather cramped and a look bit odd. If you do not uncomment the two lines you will get a gray speckled background to the VNC window.
#!/bin/sh
# Add the following line to ensure you always have an xterm available.
( while true ; do xterm ; done ) &
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &

2.5. Start the VNC server

Start the vncserver as root.
# /sbin/service vncserver start

2.6. Test each VNC user

2.6.1. Testing with a java enabled browser

Let us assume that mymachine has an IP address of 192.168.0.10. The URL to connect to each of the users will be:
Larry is http://192.168.0.10:5801
Moe   is http://192.168.0.10:5802
Curly is http://192.168.0.10:5803
Connect to http://192.168.0.10:5801. A java applet window will pop-up showing a connection to your machine at port 1. Click the [ok] button. Enter larry's VNC password, and a 640x480 window should open using the default window manager selected for larry . The above ports  5801, 5802 and 5803  must be open in the firewall {iptables) for the source IP addresses or subnets of a given client.

2.6.2. Testing with a vnc client

For Larry: vncviewer 192.168.0.10:1
For   Moe: vncviewer 192.168.0.10:2
For Curly: vncviewer 192.168.0.10:3
To test larry using vncviewer, vncviewer 192.168.0.10:1. Enter Larry's VNC password, and a 640x480 window should open using Larry's default window manager. The vncviewer client will connect to port 590X where X is an offset of 1,2,3 for Larry, Moe, and Curly respectively, so these ports must be open in the firewall for the IP addresses or subnets of the clients.

2.6.3. Starting vncserver at boot

To start vncserver at boot, enter the command /sbin/chkconfig vncserver on.
For basic VNC configuration the procedure is now complete. The following sections are optional refinements to enhance security and functionality.

3. VNC encrypted through an ssh tunnel

You will be connecting through an ssh tunnel. You will need to be able to ssh to a user on the machine. For this example, the user on the vncserver machine is Larry.
  1. Edit /etc/sysconfig/vncservers, and add the option -localhost.
    VNCSERVERS="1:larry 2:moe 3:curly"
    VNCSERVERARGS[1]="-geometry 640x480 -localhost"
    VNCSERVERARGS[2]="-geometry 640x480 -localhost"
    VNCSERVERARGS[1]="-geometry 800x600 -localhost"
    
  2. /sbin/service vncserver restart
  3. Go to another machine with vncserver and test the VNC.
    1. vncviewer -via larry@192.168.0.10 localhost:1
    2. vncviewer -via moe@192.168.0.10 localhost:2
    3. vncviewer -via curly@192.168.0.10 localhost:3
By default, many vncviewers will disable compression options for what it thinks is a "local" connection. Make sure to check with the vncviewer man page to enable/force compression. If not, performance may be very poor!

4. Recovery from a logout ( Not implemented for CentOS 6 )

If you logout of your desktop manager, it is gone!
  • We added a line to xstartup to give us an xterm where we can restart our window manager.
    • For gnome, enter gnome-session.
    • For kde, enter startkde.

5. Remote login with vnc-ltsp-config

To allow remote login access via a vnc-client to the Centos system, the RPM packages named vnc-ltsp-config and xinetd can be installed. When a vnc-client connects to one of the configured ports, the user will be given a login screen. The sessions will *not* be persistent. When a user logs out, the session is gone.
The rpm package vnc-ltsp-config is easily installed via the EPEL repository noted in Available Repositories
Note: There are no major dependencies for the package so the vnc-ltsp-config*.rpm could easily be downloaded and installed without the need for enabling the EPEL repository.
Install, as root via:
# yum install xinetd vnc-ltsp-config
# /sbin/chkconfig xinetd on
# /sbin/chkconfig vncts on
# /sbin/service xinetd restart
Next, as root edit the file "/etc/gdm/custom.conf".
  • To the next blank line below the "[security]" section add "DisallowTCP=false"
  • To the next blank line below the "[xdmcp]" section add "Enable=true"
  • Make sure you are in a position to either run "gdm-restart" for default Gnome installs or just reboot the CentOS box.
This will add the ability to get the following default vnc-client based session connections:
resolution
color-depth
port
1024x768
16
5900/tcp
800x600
16
5901/tcp
640x480
16
5902/tcp
1024x768
8
5903/tcp
800x600
8
5904/tcp
640x480
8
5905/tcp

Tuesday, October 11, 2011

DNS Server


Install the required packages:

[root@nan ~]# yum install -y bind bind-utils bind-libs


Ensure that the service is set to start on system boot:

[root@nan ~]# chkconfig named on


Otherwise start the service


[root@nan ~]# service named start


Use the iptables command to create your firewall rules:

[root@nan ~]# iptables -I INPUT  -p udp -m udp --dport 53 -j ACCEPT
[root@nan ~]# iptables -I INPUT  -p tcp -m tcp --dport 53 -j ACCEPT


Save the rules you just created:

[root@nan ~]# service iptables save


SELinux Boolean provides protection to the DNS service.
You need to adjust it for the DNS service to work properly.

Query for the Boolean value you need to change:

[root@nan ~]# getsebool -a | grep named_dis
named_disable_trans --> off

Disable the SELinux protection:

[root@nan ~]# setsebool -P named_disable_trans=1

Verify that the Boolean has changed:

[root@nan ~]# getsebool -a | grep named_dis
named_disable_trans --> on

Check the context type

[root@nan ~]# chcon -t named_conf_t /etc/named.conf

Verify with this command:

[root@nan ~]# ls -Z /etc | grep named.conf

Configuring a DNS Server

To begin configuring the DNS server, check out these key config files for a
BIND server:

/etc/named.conf                            Main config file
/etc/rndc.key                                 Key file
/etc/rndc.conf                               Key config file
/usr/share/doc/bind-9*/sample     Directory that holds sample files


Verify that the localhost is used for DNS queries on

[root@nan ~]# cat /etc/resolv.conf

# Generated by NetworkManager
domain localdomain
search localdomain server.com
nameserver 192.168.16.2
nameserver 192.168.25.111   // Add the name server IP address

Configure BIND  IP address [192.168.25.111/24], Domain name [nan.server.com]. However, Please use your own IPs and domain name when you set config on your server.

[root@nan ~]# cat /etc/named.conf

// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {
    # Add the ip address in listen-on port
    # If You want all port means make # line
    listen-on port 53 { 127.0.0.1; 192.168.25.111;};
    # listen-on-v6 port 53 { ::1; };
    directory     "/var/named";
    dump-file     "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
   # set any in allow-query 
    allow-query     { any; };
    #allow-query-cache    { any; };
    recursion yes;
 
    dnssec-enable yes;
    dnssec-validation yes;
    dnssec-lookaside auto;

    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
    type hint;
    file "named.ca";
};
#Our sample domain is server.com defined here

zone    "server.com" IN {
    type master;
    file "server.zone";
    allow-update{none;};
};
zone "example.com" IN {
    type master;
    file "example.zone";
    allow-update{none;};
};
zone "111.25.168.192.in-addr.arpa" IN {
    type master;
    file    "111.25.168.192.db";
    allow-update{none;};
};
include "/etc/named.rfc1912.zones";

Now that you have
an /etc/named.conf file, you need to create the zone  files.

Before going any further, you should also understand the different
types of resource records used with DNS and why each one is important.


A            Maps the hostname to an IP address
NS         Contains the IP address or CNAME of the nameserver
MX         Defines where mail for a particular domain goes
PTR       Maps the IP address to a hostname
SOA       Contains general administrative control for the domain
CNAME Used as an alias

In the /var/named directory, you can set up the following example.com.zone file:

[root@nan ~]# cat /var/named/server.zone
$TTL 3D
@    IN    SOA    nan.server.com.    root.nan.server.com. (
                    20111004123    ; serial
                    1D    ; refresh
                    1H    ; retry
                    1W    ; expire
                    3H )    ; minimum
@    IN    NS    nan.server.com.
nan    IN    A    192.168.25.111

Everything is now in place for you to begin using your DNS server. Before starting the service, however, make sure that the config files don’t have any syntax errors.

You can use the configtest option of the named command to accom-
plish this:

# service named configtest


Because no errors are displayed, you can start the service:


# service named start


For verification

[root@nan ~]# dig nan.server.com

; <<>> DiG 9.7.0-P2-RedHat-9.7.0-5.P2.el6_0.1 <<>> nan.server.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 35679
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;nan.server.com.            IN    A

;; Query time: 1 msec
;; SERVER: 192.168.25.111#53(192.168.25.111)
;; WHEN: Wed Oct 12 14:00:51 2011
;; MSG SIZE  rcvd: 32

Friday, August 12, 2011

DHCP Configuration

ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
ignore client-updates;
set vendorclass = option vendor-class-identifier;
subnet 192.168.20.0 netmask 255.255.255.0 {

# --- default gateway
    option routers            192.168.20.1;
    option subnet-mask        255.255.255.0;

    option domain-name-servers    192.168.20.1;
    option subnet-mask        255.255.255.0;
    range  192.168.20.128 192.168.20.254;
        filename     "/pxelinux.0";
    default-lease-time 21600;
    max-lease-time 43200;
    next-server    192.168.20.1;
}