![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeV-V1PUrZ-PbdXTQd-pvdgWsKhqnjhAy0M95zMPo0dlK0p-hRr4Ca4hyphenhyphenbiTB0PJcY9C5AlDLLGH-RaVmallCpvt8ZjDjwnnBf6AamIlojSvJsth4CBweGrMVEMabScwlvTmX_QMRQpDmT/s200/penguin-23159_960_720.png)
Q:- Write a shell script to display the name of the operating system, the login name and the host name using BASH scripting.
Code
#!/bin/bash
echo "shell script to display operating system name,login name and host name"
while true
do
echo "Enter your choice"
echo "1.Display name of OS 2.Display Login name 3.Display host name 4.exit"
read choice
case $choice in
1)
echo "name of operating system: `uname -o`"
echo "Kernel name : `uname -s`"
echo "Kernel version:`uname -v`"
;;
2)
echo "login name:`logname`"
;;
3)
echo "host name:`hostname`"
;;
4)
echo "terminating script"
break
;;
*)
echo "invalid choice, please enter values between 1 and 4 only"
;;
esac
done
Output
[student@localhost ]$ sh asgn4.sh
shell
script to display operating system name,login name and host name
Enter your
choice
1.Display
name of OS 2.Display Login name 3.Display host name 4.exit
1
name of
operating system: GNU/Linux
Kernel
name : Linux
Kernel
version:#1 SMP Mon May 7 17:29:34 UTC 2012
Enter your
choice
1.Display
name of OS 2.Display Login name 3.Display host name 4.exit
2
login
name:student
Enter your
choice
1.Display
name of OS 2.Display Login name 3.Display host name 4.exit
3
host
name:localhost.localdomain
Enter your
choice
1.Display
name of OS 2.Display Login name 3.Display host name 4.exit
4
terminating
script
Related Bash Scripts
No comments:
Post a Comment