-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWrite a script to print system information using commands
108 lines (103 loc) · 3.46 KB
/
Write a script to print system information using commands
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
<<doc
Name: Adarsh Rai
date: 18-09-2023
Description: Write a script to print system information using commands
Sample Input: ./system_info.sh
Sample Output:
1. Currently logged users
2. Your shell directory
3. Home directory
4. OS name & version
5. Current working directory
6. Number of users logged in
7. Show all available shells in your system
8. Hard disk information
9. CPU information.
10. Memory Informations
11. File system information.
12. Currently running process.
Enter the choice : 2
Your shell directory is /bin/bash
Do you want to continue (y/n) ? y
1. Currently logged users
2. Your shell directory
3. Home directory
4. OS name & version
5. Current working directory
6. Number of users logged in
7. Show all available shells in your system
8. Hard disk information
9. CPU information.
10. Memory Informations
11. File system information.
12. Currently running process.
Enter the choice : 13
Error : Invalid option, please enter valid
doc
while true # Start an infinite loop to allow the user to choose options multiple times.
do
# Display the menu of options.
echo "
1. Currently logged users
2. Your shell directory
3. Home directory
4. OS name & version
5. Current working directory
6. Number of users logged in
7. Show all available shells in your system
8. Hard disk information
9. CPU information.
10. Memory Informations
11. File system information.
12. Currently running process."
read -p "Enter the choice :" num # Prompt the user to enter their choice.
case $num in # Use a case statement to execute the chosen option.
1)
echo "Your shell directory is `whoami`" # Display currently logged user
;;
2)
echo "Your shell directory is `$SHELL`" # Display the user's shell directory.
;;
3)
echo "Your shell directory is `echo ~`" # Display the user's home directory.
;;
4)
echo "Your shell directory is `uname -sv`" # Display the OS name and version.
;;
5)
pwd
echo "Your shell directory is `pwd`" # Display the current working directory
;;
6)
echo "Your shell directory is `who -q`" # Display the number of users logged in
;;
7)
echo "Your shell directory is `cat /etc/shells`" # Show all available shells in the system
;;
8)
echo "Your shell directory is `lsblk`" # Display hard disk information
;;
9)
echo "Your shell directory is `cat /proc/cpuinfo`" # Display CPU information
;;
10)
echo "Your shell directory is `cat /proc/meminfo`" # Display memory information
;;
11)
echo "Your shell directory is `df`" # Display file system information
;;
12)
echo "Your shell directory is `ps`" # Display currently running processes
;;
*)
echo "Error : Invalid option, please enter valid option" # Handle invalid input.
;;
esac
echo -n "Do you want to continue (y/n)? " # Prompt the user if they want to continue.
read val
if [ "$val" != "y" -a "$val" != "Y" ] # If the user enters anything other than 'y' or 'Y', exit the loop.
then
break
fi
done