This little snippet shows how to parse /var/adm/wtmpx in Solaris (tested on Solars 7 only). I did this as an excercise in using the "unpack" function, and why not share in with the rest of the world. Maybe someone can use it.
# # Instead of @data, one could assign separate variables # like this: # # ($user,$id,$line,$pid,$type,$exit_1,$exit_2,$tv_1, # $tv_2,$session,$pad_1,$pad_2,$pad_3,$pad_4,$pad_5, # $syslen,$host) = unpack(...); # open(FD,"</var/adm/wtmpx") or die; my $wtmpx; my @data; while(read(FD,$wtmpx,372)) { @data = unpack('A32 A4 A32 l s ss xx ll l lllll s A257', $wtmpx); # Do things! } close(FD);

Replies are listed 'Best First'.
Re: Parsing wtmpx in Solaris
by greenFox (Vicar) on Jan 06, 2004 at 07:43 UTC
    Since it was hard won here is the same thing for HP-UX:
    $template = "A8 A4 A12 l s s s s l A16 l"; # determine the size of a record $recordsize = length(pack($template,( ))); while (read(WTMP,$record,$recordsize)) { ($ut_user, $ut_id, $ut_line, $ut_pid, $ut_type, $ut_e_termination, $ +ut_e_exit, $ut_reserved1, $ut_time, $ut_host, $ut_addr) = unpack($tem +plate,$record); }

    Of course the portable way to do this is with one of User::Utmp or Sys::Utmp :)

    --
    Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho