This is for my linux class Write a script called activity422

This is for my linux class.

Write a script called activity4.2-2 that determines if someone if logged on. The script will be executed with an argument, which is a username. An example is shown below. Purpose: Determine if someone is logged on bash-3.2$ ./activity4.2-2 kuitche kuitche is logged on Include a rst line that calls the bash shell as the interpreter Add a comment to state the purpose of the script and other comments to make the script easier to read

Solution

#!/bin/bash

# Purpose: Determine if someone is logged on

# check if argument is passed
if [ $# -eq 1 ]
then
who | grep $1 >/dev/null 2>&1
# check if command ran with non exit status to dtermine if user is logegd on
if [ $? -eq 0 ]; then
echo $1\" logged on\"
else
echo $1\" not logged on\"
fi
else
echo \"Usage: ./activity4.2-2 <username>\"
fi

This is for my linux class. Write a script called activity4.2-2 that determines if someone if logged on. The script will be executed with an argument, which is

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site