0% found this document useful (0 votes)
2 views5 pages

Shell

Uploaded by

BANUPRIYA P G
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Shell

Uploaded by

BANUPRIYA P G
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Ex No: 1 Shell Programming: Write shell script to show various system configuration like

 Currently logged user and his log name


 Your current shell
 Your home directory
 Your operating system type
 Your current path setting
 Your current working directory
 Show Currently logged number of users
Aim
To write a shell script that displays various system configuration details such as:
 Currently logged-in user and login name
 Current shell
 Home directory
 Operating system type
 Current PATH setting
 Current working directory
 Number of users currently logged in
Algorithm / Procedure
1. Start the shell script.
2. Display the currently logged-in user using the whoami command.
3. Display the login name using the logname command.
4. Display the current shell using the $SHELL environment variable.
5. Display the home directory using the $HOME environment variable.
6. Display the operating system type using the uname command.
7. Display the current PATH setting using the $PATH environment variable.
8. Display the current working directory using the pwd command.
9. Display the number of currently logged-in users using the who command and count them using wc -
l.
10. Stop the script.
Program
#!/bin/bash

echo "===== SYSTEM CONFIGURATION ====="

echo "Currently Logged User : $(whoami)"


echo "Login Name : $(logname)"
echo "Current Shell : $SHELL"
echo "Home Directory : $HOME"
echo "Operating System Type : $(uname -s)"
echo "Current PATH Setting : $PATH"
echo "Current Working Dir : $(pwd)"
echo "No. of Logged Users : $(who | wc -l)"

echo "==============================="
1. Create a file:
vi [Link]
2. Save the script and give execute permission:
chmod +x [Link]
3. Run the script:
./[Link]

Sample Output
===== SYSTEM CONFIGURATION =====

Currently Logged User: student


Login Name : student
Current Shell : /bin/bash
Home Directory : /home/student
Operating System Type : Linux
Current PATH Setting : /usr/local/bin:/usr/bin:/bin
Current Working Dir : /home/student/Documents
No. of Logged Users : 3

Result
The shell script was successfully executed and displayed the required system configuration
information including user details, shell, home directory, operating system type, PATH settings, current
working directory, and the number of logged-in users.

Ex 2: Write shell script to show various system configuration like


 About your OS and version, release number, kernel version
 Show all available shells
 Show mouse settings
 Show computer CPU information like processor type, speed etc
 Show memory information
 Show hard disk information like size of hard-disk, cache memory, model
etc
Aim
To write a shell script that displays detailed system configuration information including:
 Operating System name, version, release number, and kernel version
 Available shells in the system
 Mouse settings
 CPU information (processor type, speed, etc.)
 Memory information
 Hard disk information (size, model, cache, etc.)
Algorithm / Procedure
1. Start the shell script.
2. Display OS information using uname and /etc/os-release.
3. Display the list of available shells from /etc/shells.
4. Display mouse settings using xinput (GUI systems).
5. Display CPU information using lscpu.
6. Display memory information using free -h.
7. Display hard disk information using lsblk and hdparm.
8. End the script.
Program
#!/bin/bash

echo "========================================="
echo " SYSTEM CONFIGURATION REPORT"
echo "========================================="

echo
echo "1. Operating System Information"
echo "--------------------------------"
cat /etc/os-release
echo
echo "Kernel Version : $(uname -r)"
echo "Release Number : $(uname -v)"

echo
echo "2. Available Shells"
echo "--------------------------------"
cat /etc/shells

echo
echo "3. Mouse Settings"
echo "--------------------------------"
xinput --list 2>/dev/null || echo "Mouse information not available"

echo
echo "4. CPU Information"
echo "--------------------------------"
lscpu

echo
echo "5. Memory Information"
echo "--------------------------------"
free -h

echo
echo "6. Hard Disk Information"
echo "--------------------------------"
lsblk

echo
echo "Disk Model and Cache Information"
sudo hdparm -I /dev/sda 2>/dev/null | grep -E "Model Number|device size|cache"

echo
echo "========================================="
echo " END OF REPORT"
echo "========================================="
Execution Steps
Step 1: Create the script file
vi [Link]
Step 2: Give execute permission
chmod +x [Link]
Step 3: Execute the script
./[Link]
Sample Output
SYSTEM CONFIGURATION REPORT
1. Operating System Information
--------------------------------
NAME="Ubuntu"
VERSION="22.04 LTS"

Kernel Version : 5.15.0-89-generic


Release Number : #99-Ubuntu SMP

2. Available Shells
--------------------------------
/bin/sh
/bin/bash
/bin/rbash
/bin/dash

3. Mouse Settings
--------------------------------
Virtual core pointer
USB Optical Mouse

4. CPU Information
--------------------------------
Architecture: x86_64
CPU(s): 8
Model name: Intel(R) Core(TM) i5-1135G7
CPU MHz: 2400.00

5. Memory Information
--------------------------------
total used free
Mem: 8Gi 3Gi 4Gi

6. Hard Disk Information


--------------------------------
NAME SIZE TYPE
sda 512G disk

Disk Model and Cache Information


Model Number: Samsung SSD 970 EVO
device size : 512 GB
cache/buffer size : 1024 KB

You might also like