LAB-15,ET506
docx
keyboard_arrow_up
School
CUNY Queensborough Community College *
*We aren’t endorsed by this school
Course
506
Subject
English
Date
Dec 6, 2023
Type
docx
Pages
3
Uploaded by CaptainSardineMaster892
Queensborough Community College
Engineering Technology Department
Linux
ET-506
Prof.
John
Ducroiset
Exercise Lecture: 15
Shell Scripting 2
1.
#!/bin/bash
# A simple shell script to display system information
echo "System Information"
echo "--------------------"
echo "Hostname: $(hostname)" echo
"Kernel Version: $(uname -r)" echo
"Uptime: $(uptime -p)" echo "Logged-
in Users: $(who | wc -l)" echo
"--------------------"
exit 0
2.
#!/bin/bash
# Function to display general system information
system_info() { echo "System Information"
echo "--------------------"
echo "Hostname: $(hostname)"
echo "Kernel Version: $(uname -r)" echo
"--------------------"
}
# Function to display system uptime
show_uptime() { echo "System
Uptime"
echo "--------------------" uptime
echo "--------------------"
}
# Function to display available drive space
drive_space() { echo
"Drive Space"
echo "--------------------" df
-h
echo "--------------------"
}
# Function to display home directory space
home_space() { echo "Home
Directory Space"
echo "--------------------"
du -sh $HOME
echo "--------------------"
}
# Call the functions
system_info show_uptime
drive_space
home_space
exit 0
3.
#!/bin/bash
if [ -f "sysinfo_name_9.sh" ]; then
echo "You have sysinfo_name_9. You did question 2." else
echo "You do not have sysinfo_name_9. You did not do question 2." fi
exit 0
4.
#!/bin/bash
# Example script - Test file existence
# Check if the file exists
if [ -f "$1" ]; then echo
"The file $1 exists." else
echo "The file $1 does not exist." fi
exit 0
5.
#!/bin/bash
# Evaluating a string with a personalized variable name
yournameANSWER="Mahbubur"
# Construct the variable name
variable_name="yourname${ANSWER}"
# Evaluate the variable
eval value=\$$variable_name
# Print the value
echo "The value of \$$variable_name is: $value"
exit 0
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help