0% found this document useful (0 votes)
44 views

It-853: Linux Administration and Programming Lab List of Practicals

This document lists 15 practical programming exercises for a Linux administration and programming lab course. It provides shell script code snippets for tasks like reversing a number, waiting for user login, sending signals to processes, making bash scripts executable, finding the largest number, and printing a number pattern. The scripts accept user input, use conditional logic, loops, arithmetic operations, and system commands like grep, kill, chmod, and echo.

Uploaded by

Piyush Mathur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

It-853: Linux Administration and Programming Lab List of Practicals

This document lists 15 practical programming exercises for a Linux administration and programming lab course. It provides shell script code snippets for tasks like reversing a number, waiting for user login, sending signals to processes, making bash scripts executable, finding the largest number, and printing a number pattern. The scripts accept user input, use conditional logic, loops, arithmetic operations, and system commands like grep, kill, chmod, and echo.

Uploaded by

Piyush Mathur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

IT-853: LINUX ADMINISTRATION AND PROGRAMMING LAB

LIST OF PRACTICALS
1.

Write a shell script that reads a number and prints it in reverse order.

#!/bin/bash
read num
rev=0
while [ $num -gt 0 ]
do
rev=`expr $rev \* 10`
tmp=`expr $num % 10`
rev=`expr $rev + $tmp`
num=`expr $num / 10`
done
echo $rev

4. Write a shell script that waits for a user to log into the system.
#!/bin/bash
echo "Lines containg $1"
grep $1 $2
echo "Lines not contaning $1"
grep -v $1 $2
wc -l $2
echo "lines are there in $2"

6. Write a shell script that accepts a signal number and process id as its arguments, and sends

that signal to the given process using signal name.


#!/bin/bash/
read sig
read pid
kill -$sig $pid

7. Write a shell script that makes bash script files in the currently working directory
executable, if they are not.
#!/bin/bash/
for file in *
do
ext="${file##*.}"
if [ -f $file -a $ext=="bash" -a ! -x $file ]
then
chmod +x $file
ls -l $file
fi
done

8. Write a shell script that finds the biggest of all the positive numbers supplied by the user.

#!/bin/bash/
max=-99999
read -a arr
for i in ${arr[@]}
do
if [ $max -lt $i ]
then
max=$i
fi
done
echo $max

15. Write a shell script that prints the output in following pattern:

1
12
123
1234
12345
Take the number of lines as input.
#!/bin/bash/
i=1
echo "Enter number of lines"
read lines
while [ $i -le $lines ]
do
j=1
while [ $j -le $i ]
do
echo -n $j " "

j=`expr $j + 1`
done
i=`expr $i + 1`
echo ""
done

You might also like