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
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"
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"
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”
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
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`"
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
No comments:
Post a Comment