Link to home
Start Free TrialLog in
Avatar of atom_jelly
atom_jellyFlag for United States of America

asked on

perl solaris logged in script

okay I found this perl script then I name is epoch.pl I want to use this script to tell me how long someone has been logged in. Look at my example below. I need help. Thanks.

#!/usr/bin/perl
#
use Time::Local;
#
$sec=59;
$min=59;
$hours=23;
$day=31;
$month=11;
$year=109;
#
$current = time();
print "$current\n";

(exec /export/home/reports/epoch.pl;last –a) |awk '(NR==1){n=$1;next}/still /{u=$1;printf("/usr/ucb/echo -n %s-;exec /export/home/reports/epoch.pl "%s %s %s %s\" +%s-%%s\n",%u,$3,$4,$5,$6,n) ; }'|sh| awk -F"-" ' {printf("env TZ=GMT printf " user %s  logged in for %d days, %d hours, %d minutes and %d seconds\n", $1, $2-$3)}’|sh


I want to see

user gumby has been logged in for HOURS Minutest and Seconds.


Thanks.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of atom_jelly

ASKER

Hi ozo,

I meant to leave out the /usr/local/bin/date not supposed to use that. But my output  is supposed to look like this with a perl script.

User gumby is logged in for 00 hours 00 minutes and 00 seconds.




bash-3.00# last  -a | perl -MDate::Parse -lane '/still /&&printf"user %s has been logged in for %d hours, %d minutes and %d seconds\n",$F[0],($s=time-(str2time "@F[3,4,5]"))/3600,$s%3600/60,$s%60'
Can't locate Date/Parse.pm in @INC (@INC contains: /usr/perl5/5.8.4/lib/sun4-solaris-64int /usr/perl5/5.8.4/lib /usr/perl5/site_perl/5.8.4/sun4-solaris-64int /usr/perl5/site_perl/5.8.4 /usr/perl5/site_pe
rl /usr/perl5/vendor_perl/5.8.4/sun4-solaris-64int /usr/perl5/vendor_perl/5.8.4 /usr/perl5/vendor_perl .).
BEGIN failed--compilation aborted.
bash-3.00#
Oh baby thats good!!!!!