Lab 1-2 Shell Script Assignment and Solution

Lab 1-2 Shell Script Requirement

Lab1-2

Lab 1-2 Shell Script Solution

#!/bin/bash
# Script started on Tue Apr 23 00:12:09 2013
# [testuser@abc ~]$ ls -l cis18cLabLink
# lrwxrwxrwx 1 testuser unixStudent 34 Apr 23 00:12 cis18cLabLink -> /home/distribution/cnguyen/cis18c/
# [testuser@abc ~]$ echo Found $(grep 'testuser' /etc/passwd | cut -f5 -d':') among $(wc -l /etc/passwd | cut -f1 -d' ') entries of /etc/passwd
# Found Test User among 1624 entries of /etc/passwd
# [testuser@abc ~]$ whereis -b tcsh | cut -f2 -d':'
#  /bin/tcsh
# [testuser@abc ~]$ ls -a | grep '^\.[^.]' | wc -l
# 8
# [testuser@abc ~]$ cp cis18cLabLink/clean.sed .
# [testuser@abc ~]$ echo 's/^/# /' >> clean.sed
# [testuser@abc ~]$ exit
# exit
# 
# Script done on Tue Apr 23 00:12:59 2013
echo There are $(finger | cut -f1 -d' ' | uniq | tail -n +2 | wc -l) uniq users currently logged in
# Prompt the user and read in a number, which will be used as the number of minutes in the script
echo -n "Enter the number of idle minutes (0-60): "
read idleMinutes
echo These users are in idle for more than $idleMinutes minutes
# Print to screen the user id and the idle time of users who have been idle for more than the given minutes.
finger | tail -n +2 | awk -F ' ' '($(NF-4)) ~ "^[^p]" {if($(NF-4) > '$idleMinutes') print $1F " " $(NF-4); else if(substr(($(NF-4)), 2,1) == ":")print $1F " " $(NF-4); else if(substr(($(NF-4)), 3,1) == ":") print $1F " " $(NF-4)}'