summaryrefslogtreecommitdiff
path: root/macusers
blob: ac930d26ee5bb669e58ed6de0fe530da126dc096 (plain)
  1. #!/usr/bin/perl
  2. # Written for linux; may have to be modified for your brand of Unix.
  3. $MAC_PROCESS="afpd";
  4. $PS_STR="-ef";
  5. $ASIP_PORT="afpovertcp";
  6. # Change to 0 if you don't have lsof
  7. $LSOF=1;
  8. if ($LSOF == 1 )
  9. {
  10. open(LSOF,"lsof -i | grep $ASIP_PORT |");
  11. while(<LSOF>)
  12. {
  13. if ($_ !~ /$ASIP_PORT/)
  14. {
  15. next;
  16. }
  17. $_=~/\w+\s+(\d+).*->([\w-]+).*/;
  18. $pid=$1; $host=$2;
  19. $mac{$pid}=$host;
  20. }
  21. close(LSOF);
  22. print "PID UID Usercode Name Logintime Mac\n";
  23. }
  24. else
  25. {
  26. print "PID UID Usercode Name Logintime\n";
  27. }
  28. open(PS," ps $PS_STR |") || die "cannot do ps";
  29. while(<PS>)
  30. {
  31. if ($_ !~ /$MAC_PROCESS/ )
  32. {
  33. next;
  34. }
  35. $_=~ /\s*(\w+)\s+(\d+)\s+(\d+)\s+\d+\s+([\d\w:]+)/;
  36. $user=$1; $pid=$2; $ppid=$3; $time=$4;
  37. if ($ppid != 1)
  38. {
  39. ($t,$t,$uid,$t,$t,$t,$name,$t,$t)=getpwnam($user);
  40. printf "%-8d %-8d %-8s %-20s %-9s %s\n",$pid,$uid,$user,$name,$time,$mac{$pid};
  41. }
  42. }
  43. close(PS);