Description: Write a shell script (bash or sh) that prints out the following lin
ID: 3684361 • Letter: D
Question
Description:
Write a shell script (bash or sh) that prints out the following lines/information:
Name: "Your name"
Hostname: "The computer's hostname"
Host IP: "The computer's IP number"
Default Gateway: "The computer's default gateway"
OS Version: "Whatever information on the OS version you can get programmatically"
Memory: "The amount of physical memory (not disk) the system has"
CPU Speed: "The CPU speed (in Hz not MIPS) the system thinks it has"
Disk space: "The amount of aggregate physical disk the system has"
A blank line (or two)
The shell script itself
Only your name may be hard coded, the rest must be obtained programmatically within the shell script. Make sure you test it before turning it in. Only the requested information should be output and only one line per item including label.
Explanation / Answer
These below list of commands are helpful to print the bash shell
echo "My host name is $HOSTNAME."
echo "HostIP" hostname -I
DEFAULT_ROUTE=$(ip route show default | awk '/default/ {print $3}')
ping -c 1 $DEFAULT_ROUTE
echo "$DEFAULT_ROUTE"
echo uname -a
echo grep MemTotal /proc/meminfo | awk '{print $2}'
echo CPU: `top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'`
FREE_DATA=`free -m | grep Mem`
CURRENT=`echo $FREE_DATA | cut -f3 -d' '`
TOTAL=`echo $FREE_DATA | cut -f2 -d' '`
echo RAM: $(echo "scale = 2; $CURRENT/$TOTAL*100" | bc)
echo HDD: `df -lh | awk '{if ($6 == "/") { print $5 }}' | head -1 | cut -d'%' -f1`