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
- Use of runtime variables to save into another variable using register in Ansible - September 6, 2018
- Ansible & Ansible Tower Variable Precedence Hierarchy - September 6, 2018
- How to use template in Ansible? - September 6, 2018