Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/sh
- #Shell script program that takes user input and displays information about the system.
- #Prints choices to the console for the user to select.
- echo "Choose and option from below:"
- echo "1: Display information about the CPU"
- echo "2: Display the interrupts on the system"
- echo "3: Display the names of the output devices and the number of megabits read."
- echo "4: Display the PID of a process that is running on the server and its status."
- echo "-1: Exit"
- echo
- #Takes user input from the user.
- read userInput
- #While statement executes
- while [ $userInput != "-1" ]
- do
- echo "Choose an option from below:"
- echo "1: Display information about the CPU."
- echo "2: Display the interrupts on the system."
- echo "3: Display the names of the output devices and the number of megabits read."
- echo "4: Display the PID of a process that is running on the server and its status."
- echo "-1: Exit"
- read userInput #Takes input from the user.
- if [ $userInput = "1" ]
- then
- echo
- echo "***CPU Information***"
- cat /proc/cpuinfo
- elif [ $userInput = "2" ]
- then
- echo
- echo "***Interrupts Info***"
- cat /proc/interrupts
- elif [ $userInput = "3" ]
- then
- echo
- echo "***Names of output devices and number of megabits read***"
- cat /proc/diskstats
- elif [ $userInput = "4" ]
- then
- echo
- ps > info.txt #information about current proccesses running is redirected to the info.txt file.
- pidVar=`grep "bash" info.txt | awk 'NR==2{ print $1}' info.txt` #Looks into the txt file for the line that contains the process called 'bash' and stores its process id into the pidVar to be used as a variable in the proc directory when searcing for information about the process.Furthermore the awk command combined with the 'NR==2' argument selects the first word in the second line of the document which is the process id of 'bash'.
- echo
- pidString="PID:"
- echo $pidString #Prints out PID string
- echo $pidVar #Prints out the process PID
- cat /proc/$pidVar/status | grep 'Name\|State' #Prints out lines that contain the words 'Name' and 'State'.
- echo
- elif [ $userInput = "-1" ] #Terminates the while loop.
- then
- echo "You have successfully exited the loop!"
- break
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement