Question

You will create a shell script that prints out the following information about the system it is run on: • The system’s n...

You will create a shell script that prints out the following information about the system it is run on:

• The system’s name and IP address

• How much memory the system is currently using, and how much total memory it has

• The number of CPUs of the machine

• The number of unique users on the system at that moment

When your script is run, each of these values should be clearly labeled in the output, such as Number of active users: 10 Exactly how you choose to format the information you print is up to you, so long as it is easy to interpret and the labels for each value are clear. (Adding any additional visual touches, such as a title or horizontal dividers, is permitted.) Your script should not create any intermediate files when run, and should not add anything to or remove anything from the filesystem. You may wish to query 1 the information above using commands and then store the results in variables before printing them. Much of the information above can be found and formatted using commands already introduced in this course, especially related to handling rows and columns of information. You can use the help commands discussed in class, such as man -k or apropos to help you search for useful commands if you are not sure where to begin. Once you are satisfied your script is working, you submit the script, as well as a log of you running it on at least two different lab machines, whether physical lab machines or on tuxworld. Note that you can connect to different tuxworld machines from a lab environment or from a shell in tuxworld by running the command ssh tuxn where ”n” is a single integer, such as 6 or 8. If you have developed the script on your own machine, you can transfer it to tuxworld using the scp command for testing.

1.3 Files needed for this question •

q1_sysinfo.sh: the shell script you created which prints out system information.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# to print hostname and IP address

HOSTNAME=$(hostname)

IP_ADDRESS=$(hostname -I)

echo -e "system's name is: $HOSTNAME"

echo -e "IP address is: $IP_ADDRESS"

# this is one way to find out memory is use and total memory

# TOTAL_MEM = free -mht | awk '{print $1"\t"$2}' | grep 'Total:'

# MEM_IN_USE = free -mht | awk '{print $1"\t"$3}' | grep 'Total:'

# another approach to find out the memory in use and total memory is

# free command gives the memory details column-wise.

#-b gives memory in bytes, -t gives a row called Total at the end

# we select the 2nd and 3rd columns to get our required information

TOTAL_MEM=$(free -bt | awk '{print $2}' | tail -n1)

MEM_IN_USE=$(free -bt | awk '{print $3}' | tail -n1)

echo -e "Total memory is: $TOTAL_MEM Bytes"

echo -e "Currently in use is: $MEM_IN_USE Bytes"

# to get the number of CPUs the computer has

NO_OF_CPUS=$(grep -c ^processor /proc/cpuinfo)

# cpuinfo contains information about every CPU or core starting from 0,1,2,3,...

# so we have to count the number of lines starting with the word "processor" using ^processor

echo -e "Number of CPUs are: $NO_OF_CPUS"

# to get the number of users currently logged in

NO_OF_USERS=$(who | grep -c .)

# who returns a list of users grep -c counts the number of lines in output

# to avoid blanks we used . (dot)

echo -e "Number of users currently logged in: $NO_OF_USERS"


Add a comment
Know the answer?
Add Answer to:
You will create a shell script that prints out the following information about the system it is run on: • The system’s n...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need this done ASAP. Please write a bash shell script that does the following: Prints...

    I need this done ASAP. Please write a bash shell script that does the following: Prints out how many users are logged on. This can be accomplished using who and wc. Prints out a list of currently logged on users. This can be accomplished using who, grep, regular expressions, and echo. Prints out how many processes you have running from past days, and a list of those jobs. Use `whoami` to get your username. Run ps -ef and see how...

  • Write a script using the bash shell to add new users to the system. The script...

    Write a script using the bash shell to add new users to the system. The script should read user information from a comma-delimited file (each field should be separated by a comma). The filename should be passed to the script as a command-line argument. Be sure the script contains a usage clause. The input file should contain the user information with one user per line. As the system administrator, you should determine the information necessary for each user to properly...

  • Hello, please help with the following, you're tasked with writing a shell script named “rpsm.sh”....

    Hello, please help with the following, you're tasked with writing a shell script named “rpsm.sh”. The script reports and prints (to stdout) selected storage management information. Think of it as “RePort Storage Management”. The easy way to describe what the script needs to do is to look at what it should display in the case where you provide incorrect parameters, or in the case where you provide “-h” for help: Usage: ./rpsm.sh <options>< directory> Reports selected information about specified directory...

  • Exercise 1: Write a shell script that loops through the /etc/passwd file one line at a...

    Exercise 1: Write a shell script that loops through the /etc/passwd file one line at a time. Prepend each line with a line number followed by a colon and then a space. Example output: 1: root:x:0:0:root:/root:/bin/bash 2: daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin 3: bin:x:2:2:bin:/bin:/usr/sbin/nologin 4: sys:x:3:3:sys:/dev:/usr/sbin/nologin Exercise 2: Write a shell script that asks the user for the number of lines they would like to display from the /etc/passwd file and display those lines. Example output: How many lines of /etc/passwd would you like...

  • In this exercise, you will create a script called file_ops.sh that uses the various file operators...

    In this exercise, you will create a script called file_ops.sh that uses the various file operators The file_ops.sh script will Use one command line argument Use four IF THEN statement to compare the first command line argument Determine which file operators to use that produces the following output when the script run with the arguments shown WARNING: In the IF THEN statements, to avoid syntax error messages, there must be a space before and after each bracket and also between...

  • In some cases, people who are not strong in Linux may need to run specific Linux...

    In some cases, people who are not strong in Linux may need to run specific Linux commands. To make this easier, you can create a menu-driven program that runs these Linux commands. Such a program allows users to execute the commands without having to actually know about how to execute them. For this scenario, create a menu-driven program that has the following options: 1. List users who are logged in (using the who command) 2. List system information (using the...

  • INFO 1211

    Lab 0: Essential UNIX OperationsObjectivesAt the end of this of lab, you should be able to:securely      log in to a remote computer running a UNIX-like operating systemread the      manual page for any commanduse the      UNIX file systemedit a      text fileNotes:·         In order to get familiar with UNIX, do all your work on UNIX.·         A command line interface may be harder to learn, but can be more powerful for scripting and automating tasks.·        ...

  • Using Linux Create a custom banner that displays the following information when you log into your...

    Using Linux Create a custom banner that displays the following information when you log into your normal user’s shell (hint: edit ~/.bashrc): “Hello USER” – (make use of the USER environment variable to get the username) “Welome to HOSTNAME” (make use of the HOSTNAME environment variable) System uptime System’s private IP addresses (not full blown ifconfig output, but just a line for each interface that says “The IP address for ETHX is: XXX.XXX.XXX.XXX” – hint: use the grep and awk...

  • Question III This question carries 20% of the marks for this assignment. Given the following mix...

    Question III This question carries 20% of the marks for this assignment. Given the following mix of tasks, task lengths and arrival times, compute the completion [5 marks and response time time from the arrival to the finish time) (5 marks for each task, along with the average response time for the FIFO. RR and SJF algorithms. Assume a time slice of 10 milliseconds and that all times are in milliseconds. You are kindly asked to provide the Gantt Chart...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT