Bash Script Write a script called nosy that will do the following: a. Ask the us
ID: 3774557 • Letter: B
Question
Bash Script
Write a script called nosy that will do the following:
a. Ask the user's full name--first, last, and middle name.
b. Greet the user by his or her first name.
c. Ask the user's login name and print his or her user ID (from /etc/passwd)
d. Tell the user his or her home directory (the user entered via step c, not currently logged in).
e. Show the user the processes he or she is running (the user entered via step c, not currently logged in user)
g. Tell the user the day of the week, and the current time in non-military time. The output should resemble:
"The day of the week is Tuesday and the current time is 04:07:38 PM."
Explanation / Answer
Save the below file with nosy.sh and run from terminal:
#!/bin/bash
clear
echo Enter your First name
read name
echo Enter your Middle name
read mid
echo Enter your Last number
read last
echo
echo Hello $name
echo
echo what is your login name
read login
x=$(getent passwd $login | cut -d ':' -f 3)
echo $x
echo
echo your home directory is
h=$(getent passwd $login | cut -d ':' -f 6)
echo $h
echo
echo All processes $login is running
echo
echo $(ps -u $login)
echo
dow=$(date +'%A')
now=$(date +"%r")
echo The day of the week is $dow and the current time is $now.