Question

The first script you need to write is login.sh, a simple script that you might run...

The first script you need to write is login.sh, a simple script that you might run when you first log in to a machine. We'll expand this script later, but for now it should include your name, username, hostname, current directory, and the current time. Here is some sample output to help guide you. Note that the bolded lines that start with "[user@localhost ~]$" are the terminal prompts where you type in a command, not part of the script. Of course, your values will be different since you are a different user!

[user@localhost ~]$ login.sh

Welcome to localhost.localdomain, John Doe!

You are logged in as jdoe and your current directory is /home/jDoe/lab2.

The time is 11:47am. [user@localhost ~]$

There are a number of environment variables you will need to use that contain most of the information needed. Specifically, you should use the following variables: $HOSTNAME for the computer name (localhost.localdomain), $USERNAME for the log in username (sjung), and $PWD for the current directory (/home/sjung). To get the current time, use the date command. By default date prints out more than we want, but you can control the output using some funny looking syntax. Look at the help or man page for details, but you should run it like this to get the output we want:

1. The command is: date "+%l:%M%P"

2. Note that the %l is a percent sign followed by a lowercase l (ell), not a one, a pipe, or an upper or lowercase i (eye).

To get the full name of the user, you'll need to do some work. There is no environment variable that defines the full name for you, but it is available in the /etc/passwd file. You will need to use a combination of the $USERNAME environment variable and grep to get the one line from /etc/passwd for your user account, then use the cut command to get the full name from that line.

Shell Scripting As with any other program, test it to make sure it works. When it is working, TAKE A SCREENSHOT (1) of the output of the script. TAKE A SCREENSHOT (2– login.sh) your script. I can’t grade if your screenshot is not readable. Bigger font please! If you can’t control font size, please submit the file as text format.

Homework Answers

Answer #1

Please find the requested script below. Also including the screenshot of sample output and screenshot of code

Please provide your feedback
Thanks and Happy learning!

output:

program:

login.sh

#!/bin/bash
fullUserName=`cat /etc/passwd | grep $USERNAME | cut -d: -f5`
echo "Welcome to $HOSTNAME, $fullUserName!"
echo "You are logged in as $USERNAME and your current directory is $PWD."

echo "The time is `date +%l:%M%P`."
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
write a script named print_lines.sh that uses head and tail together to print out a specific...
write a script named print_lines.sh that uses head and tail together to print out a specific set of lines from a file. The script should take three arguments: the line number to start at, the line number to stop at, and the file to use. Here's an example run: [user@localhost ~]$ print_lines.sh 7 10 /etc/passwd shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin [user@localhost ~]$ In this example, the script prints line 7 through 10 (inclusive) of the /etc/passwd file. Your script must do...
Chapter 8: Searching, Extracting, and Archiving Data Exercise 8.a: Using grep, find, and regular expressions (Objective...
Chapter 8: Searching, Extracting, and Archiving Data Exercise 8.a: Using grep, find, and regular expressions (Objective 3.2) Linux Distribution: Fedora (non-root user & password needed) Desktop Environment: GNOME 3 1.   If you have not already done so, boot up your computer (or virtual machine) to start the Fedora Linux distribution. 2.   When the machine has booted up, access the tty2 virtual terminal by pressing Ctrl+Alt+F2. 3.   Log on to a regular user’s account by typing in the username at the...
PLEASE DO QUICK LINUX ASSIGNMENT PLEASE ILL THUMBS UP You need to paste the command and...
PLEASE DO QUICK LINUX ASSIGNMENT PLEASE ILL THUMBS UP You need to paste the command and the output in a word document and submit it. Part1: 1. Log in to Linux using your user account name and password. 2. If you logged in using a graphical login screen, open a terminal window by clicking on the icon in the lower left corner of the desktop to open the main menu, then selecting System Tools, then Terminal. A terminal window opens....
Finally, write a script named word_counts.sh that prints out how many words are on each line...
Finally, write a script named word_counts.sh that prints out how many words are on each line of standard input, as well as the total number of words at the end. The script should take no arguments. Instead, the script must work by reading every line of standard input (using a while loop) and counting the number of words on each line separately. The script is intended to work with standard input coming from a pipe, which will most often come...
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of...
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of userids on the command line 2. For each userid, display the userid, PID, CPU time, and current command for each process owned by that userid Your output should look similar to this example: practice-script-a doug.jones User: doug.jones PID: 8748 TIME: 00:00:00 COMMAND: /usr/lib/systemd/systemd --user User: doug.jones PID: 8749 TIME: 00:00:00 COMMAND: (sd-pam)    User: doug.jones PID: 8750 TIME: 00:00:00 COMMAND: sshd: doug.jones@pts/5 User: doug.jones...
Here is your chance to be creative. Craft your own shell script that has 6 different...
Here is your chance to be creative. Craft your own shell script that has 6 different actions. For example, listing the current directory would be one, displaying the date to STDOUT would be a second. You do not get to use those examples, so make up your own. Copy your script here and submit a screenshot of the executed script from a terminal window.
A. Create a PowerShell script named “restore.ps1” within the “Requirements2” folder. For the first line, create...
A. Create a PowerShell script named “restore.ps1” within the “Requirements2” folder. For the first line, create a comment and include your first and last name along with your student ID. Note: The remainder of this task shall be completed within the same script file, “restore.ps1.” B. Write a single script within the “restore.ps1” file that performs all of the following functions without user interaction: 1. Create an Active Directory organizational unit (OU) named “finance.” 2. Import the financePersonnel.csv file (found...
NOTE: I just need the answer for question 5 and 6. I already knew the question...
NOTE: I just need the answer for question 5 and 6. I already knew the question 1-4, and wrote down all the requirements for clarification. In this assignment, you are required to write a Bash script, call it assignment2.sh. Your Bash script has to accept at least four input arguments, and must: 1) Print to the user a set of instructions explaining how the PATH variable can be used in Bash. 2) Save the manual of the 'awk' command in...
You are asked to develop a React App as follow: 1) Create a new component, name...
You are asked to develop a React App as follow: 1) Create a new component, name it YournameComp to the program which extract the Weather info from Weather API (Open Weather Map), and display the current temperature. Upon calling the component, a webform appears which asks user to enter a city name and select the country code (from a drop-down list) and when the user hits the show temperature button, the data will be displayed. 2) Add a Route to...
Name the script for.sh.  This script will create a shopping list. Ask the user to enter items...
Name the script for.sh.  This script will create a shopping list. Ask the user to enter items separated by a space. Read the list. Use a for loop to write (use echo) the items to a file called shopping_list. You should use >> to append the output to the file, so each time the script is run the list should get longer. After the for loop finishes, display (use cat) the contents of the shopping list with 1 item per line....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT