Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help with a KornShell script

Status
Not open for further replies.

ckrieger1

Programmer
Feb 13, 2004
6
US
I need a KornShell script that will, among all the users currently logged on to the system, find a slot of one hour that contains the most number of users. I know how to list all the users currently logged on but how do I do anything with the times that are listed? Please help, thanks.
 
Hmmmmm..
Depends what you want
You could run something from the cron every 10 mins or so
0,10,20,30,40,50 **** date;w|wc -l >>/tmp/file

which would give you :
Fri Feb 13 15:21:08 GMT 2004
13

that is - that time and number of users logged on
HTH

Dickie Bird (:)-)))
 
Here's something to start with. The idea is to get all the logged in users with their respective 'login@' time. As you will need to manupulate the login times, it would be easier to convert all the time into one numberic format and do the math with numerics. I prefer conerting to Julian dates.

I don't provide the whole solution, but it should give you enough base to start on.

#!/bin/ksh

thisYear="$(date +%Y)"
monthList='JanFebMarAprMayJunJulAugSepOctNovDec'

#-----------------------------------------------------------------------------
# Date manipulation routines - convering to Julian and back
#
# Julian Day Number from calendar date
date2julian() # year month day
{
typeset year=$1; typeset month=$2; typeset day=$3
tmpmonth=$((12 * year + month - 3))
tmpyear=$((tmpmonth / 12))
print $(( (734 * tmpmonth + 15) / 24 - 2 * tmpyear + tmpyear/4 - tmpyear/100 + tmpyear/400 + day + 1721119 ))
}

# Calendar date from Julian Day Number
julian2date() # julianday
{
#set -x
typeset tmpday=$(($1 - 1721119))
typeset centuries=$(( (4 * tmpday - 1) / 146097))
tmpday=$((tmpday + centuries - centuries/4))
typeset year=$(( (4 * tmpday - 1) / 1461))
tmpday=$((tmpday - (1461 * year) / 4))
typeset month=$(( (10 * tmpday - 5) / 306))
day=$((tmpday - (306 * month + 5) / 10))
month=$((month + 2))
year=$((year + month/12))
month=$((month % 12 + 1))
printf "%s %02d %02d" $year $month $day
}

# Day of week, Monday=1...Sunday=7
dow() # year month day
{
print $(( $(date2julian $1 $2 $3) % 7 + 1))
}

#----------------------------------------------------------------------------
month2number() # $1 = month
{
typeset monthName="${1}"
typeset idx;
idx=${monthList%%${monthName}*}
print $(( (${#idx} + 3 ) / 3 ))
}
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------

who | while read user junk mon date time junk
do
hour="${time%%:*}"
julian="$(date2julian ${thisYear} $(month2number ${mon}) ${date})"
julian2hours="$(( julian * 24 + hour ))"
echo "user->[${user}] time->[${mon}_${date}_${time}] Julian->[${julian}] Julian2hours->[${julian2hours}]"
done;



vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top