Test your Shell Scripting Skills: – Program 6

scmuser created the topic: Test your Shell Scripting Skills: – Program 6
Display a process in the system every 30 seconds five times using a(i) while loop (ii) for loop. What is the unusual feature of the for loop?

rajeshkumar replied the topic: Re: Test your Shell Scripting Skills: – Program 6

This should work….

#!/bin/bash
counter=0

while [ $counter -lt 5 ]
do

echo "Displaying running System process"
ps
echo "Displaying System Process and Top CPU using processes"
top
echo "Displaying One line Summary of System Status"
uptime

sleep 30
done

for counter1 in 1 2 3 4 5
do
echo "Displaying running System process"
ps
echo "Displaying System Process and Top CPU using processes"
top
echo "Displaying One line Summary of System Status"
uptime

sleep 30

done

The unusual feature of for loop is – There is no three part structure as used in C, Awk and perl. Unlike while and until, for does not test a condition, but uses a list instead.

for example…

for varibale in list
do
commands
done
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn