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
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...
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.
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...
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....
Save your select statements as a script. Place the semicolon at the end of each SQL...
Save your select statements as a script. Place the semicolon at the end of each SQL statement. Please number your select statements from 1 to 8 in your script and comment out each number. Include your name and student number as a comment at the top of your script. The name of the script has to be Assignment1_JohnSmith. Instead of JohnSmith use your First Name and Last Name. Upload your script trough Blackboard. Use SQL Developer to create the My...
1. Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5 and log in to the terminal...
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...
Project 10-3 In this hands-on project, you view the configuration of the System Log Daemon and...
Project 10-3 In this hands-on project, you view the configuration of the System Log Daemon and the logrotate utility on Ubuntu Server Linux. 1. Boot your Ubuntu Server Linux virtual machine. After your Linux system has been loaded, log into tty1 using the user name of root and the password of LNXrocks!. 2. At the command prompt, type ls –l /dev/log and press Enter. What is the file type? Which daemon on Ubuntu Server Linux uses this file and what...
1. By convention, how are configuration files separated from regular files? (NOTE: A practical effect of...
1. By convention, how are configuration files separated from regular files? (NOTE: A practical effect of the separation is that they are not displayed by the default version of the ls command)                         a. the prefix "rc" (rc.filename)               c. the extension .cfig                         b. a dot (.) at the beginning                    d. by having the SUID bit set 2. The IP address which is reserved for local loopback (equivalent to "localhost") is:                         a. 255.255.255.0                                   c. 192.168.70.1...
Write a MATLAB function and test bench script code to solve the above simple RL/RC circuits...
Write a MATLAB function and test bench script code to solve the above simple RL/RC circuits by following the instructions noted below. The input signal and impulse response generation should be done in the function. The test bench script should be used only to call the function and for signal plotting purposes. No plotting should be done inside the function itself. Name your function L2_C Instructions: Input voltage ,x(t), can be AC or DC. Consider a variable ‘w1’ which can...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT