#!/bin/bash -u # $0 [gcos_grep_string] # e.g $0 CST8207-15F-011 # Select online users using the grep string on the passwd file. # (Allows lab periods to only show students in that lab.) # Argument not used unless you use the student version of MyUsers() below. # -Ian! D. Allen - idallen@idallen.ca - www.idallen.com # Not used unless doing a student lab; see below. # grepstr=${1-} msg=( "Ask Me" "Questions!" ) clear COLTIME=5 # time to go across entire screen once betweensleep=2 # sleep between sections ss=( $(stty size) ) || exit $? rows=${ss[0]} cols=${ss[1]} # divide the sleep time by the number of columns to find colsleep colsleep=$( dc -e "2 k $COLTIME $cols / p" ) sc=$( tput sc ) || exit $? rc=$( tput rc ) || exit $? ed=$( tput ed ) || exit $? # clear to end of screen el=$( tput el ) || exit $? bold=$( tput bold ) || exit $? blink=$( tput blink ) || exit $? sgr0=$( tput sgr0 ) || exit $? colours=( $( seq 1 6 | sort -R ) ) colour=0 # This is one more than the max that $RANDOM returns BIG=32768 echo -n "$sgr0" i=0 ur=0 # Use this version when in a lab and you only want to display # the names of non-idle students in the current lab section: #MyUsers () { # # Use this awk expression to select only student accounts with small # # idle times (less than 10 minutes) # local noidle=$( # w | awk ' # $1 ~ /^[a-z][a-z][a-z0-9][a-z0-9][0-9][0-9][0-9][0-9]$/ \ # && \ # $5 !~ /[[:digit:]]:[[:digit:]][[:digit:]]m$/ \ # && \ # $5 !~ /^[[:digit:]][[:digit:]]:[[:digit:]][[:digit:]]$/ {print $1} ' \ # | sort -u -R # ) # # # only users that match this grep string e.g. CST8207-15F-011: # users=( $( # for u in $noidle ; do # grep "^$u:" /etc/passwd | awk -F: "/$grepstr/"' {print $1}' # done # ) # ) #} # Use this version to show all logged-in users on the current machine MyUsers () { local u=$( users ) if [ "$u" = "" ] ; then u="NoUsersFound" fi users=( $u ) } # Pass it the name you want to display. DoStuff () { local IFS='' local sp= local i # The name to display, and a string of blanks of the same length: local name=$1 local blank=${name//?/ } # bash only substitution tput sc || exit $? colour=$(( colour + 1 )) if [ $colour -ge ${#colours[*]} ] ; then colour=0 fi # this fails if terminal doesn't do colour; let it pass tc2=$( tput setaf ${colours[$colour]} ) # || exit $? FLYWIDTH=41 # maxumum width of the fly.txt image flysleep=$( dc -e "2 k $COLTIME $cols $FLYWIDTH - / p" ) for (( i=0 ; i < ((cols-FLYWIDTH) - 1) ; i++ )) ; do colour=$(( colour + 1 )) if [ $colour -ge ${#colours[*]} ] ; then colour=0 fi # this fails if terminal doesn't do colour; let it pass tc=$( tput setaf ${colours[$colour]} ) # || exit $? # tr ' ' '.'