1. Switch to a command-line terminal (tty5) by pressing
Ctrl+Alt+F5 and log in to the
terminal using the user name of root and the password of
LINUXrocks!.
2. At the command prompt, type vi diskconfig.sh and press Enter to
open a new file
for editing called diskconfig.sh in your home directory. Why is it
good form to use a .sh
extension for shell scripts?
3. Enter the following text into the diskconfig.sh file. As you are
typing the contents,
ensure that you understand the purpose of each line (reviewing the
chapter contents
and appropriate man pages as necessary). When finished, save and
quit the vi editor.#!/bin/bash
#This script creates a report of our disk configuration
FILENAME=‘hostname‘
echo "Disk report saved to $FILENAME.report"
echo -e "\n LVM Configuration: \n\n" >>$FILENAME.report
lvscan >>$FILENAME.report
echo -e "\n\n Partition Configuration: \n\n"
>>$FILENAME.report
fdisk -l | head -17 >>$FILENAME.report
echo -e "\n\n Mounted Filesystems: \n\n"
>>$FILENAME.report
df -hT | grep -v tmp >>$FILENAME.report
4. At the command prompt, type chmod u+x diskconfig.sh and press
Enter. Next,
type ./diskconfig.sh at the command prompt and press Enter. Note
the filename
that your report was saved to.
5. At the command prompt, type less filename where filename is the
filename you
noted in the previous step, and press Enter. View the contents.
Would this shell script
work well to record storage configuration from different systems?
Why?
1.Why is it good form to use a .sh extension for shell scripts?
answer - Because Linux system understand the .sh extension files as executable when we change the file permission.
2.Would this shell scriptwork well to record storage configuration from different systems?
answer - This script will run on most of the linux system. It will not run on windows system.
we need BASH install to run shell script . System equipped with bash will be able to run shell scripts.
Get Answers For Free
Most questions answered within 1 hours.