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 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.

use Time::Local;
$current = time();
print "$current\n";

(exec /export/home/reports/;last –a) |awk '(NR==1){n=$1;next}/still /{u=$1;printf("/usr/ucb/echo -n %s-;exec /export/home/reports/ "%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.

Avatar of ozo
Flag of United States of America image

Link to home
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


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/ 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.
Oh baby thats good!!!!!