Use the date and who commands to write a program called conntime that prints the number of hours and minutes that a user has been logged on to the system (assume that this is less than 24 hours).

What will be an ideal response?


login=$(who | grep "^$1 " | head -1)

lhour=$(echo $login | cut -d\ -f5 | cut -d: -f1)
lmin=$(echo $login | cut -d\ -f5 | cut -d: -f2)

hour=$(date +%H)
min=$(date +%m)

elapsed_hours=$(( $hour - $lhour ))
elapsed_mins=$(( $min - $lmin ))

if [ $elapsed_mins -lt 0 ] ; then
elapsed_mins=$(( $elapsed_mins + 60 ))
elapsed_hours=$(( $elapsed_hours - 1 ))
fi

echo "User $1 logged in at ${lhour}:$lmin, and it's currently ${hour}:$min"
echo "Elapsed login time is $elapsed_hours hours and $elapsed_mins minutes"

Computer Science & Information Technology

You might also like to view...

The smallest data element in an Access database is called a(n) ________

Fill in the blank(s) with correct word

Computer Science & Information Technology

According to your professor, the distinctive and recognizable orange and purple associated with Dunkin’ Donuts are a part of what?

a. visual research b. brand application c. brand d. vision

Computer Science & Information Technology

The only way to change the color of a SmartArt is to change the theme.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

__________ maps a single routable (that is, not private) IP address to a single machine, enabling you to access that machine from outside the network.

A. Dynamic NAT B. Source NAT C. Static NAT D. Destination NAT

Computer Science & Information Technology