experiences with awk and uniq - Copyright © 1995 - 2001 John Meister
last | awk '{print $1}' | grep -v root | uniq -d | wc -lI get 12... with 10 of those being duplicates, and another 2, one of those being a duplicate. THEN, if I do:last | awk '{print $1}' | grep -v root | grep -v reboot | uniq -d | wc -land didn't get the same answer!!! so much for a "uniq" afternoon.... :) It's close enough for what I'm looking for though... wait... I'll try using it with sort...last | awk '{print $1}' | grep -v root | grep -v reboot | sort | uniq -dAHA!, it works, while the other "uniq" without "sort" doesn't, see: >--> last | awk '{print $1}' | grep -v root | grep -v reboot | uniq -d jxxxxxx jxxxxxx ----------------------------------------------------- root@wxxxxxxx [/root] >--> last | awk '{print $1}' | grep -v root | grep -v reboot | sort | uniq -d cxxxxxxx jxxxxxxx so, now I can take this string and run it through my for loop and remotely check each workstation for user id so I can update my password file with only those users that have accessed my systems. :) #!/bin/sh # # 99dec17 - get user names from last # echo " executing script to determine users on all HP engineering workstations " for x in `cat /raid/02d/sa/rem/hostseng` do echo $x >> /raid/02d/sa/rem/log.`/usr/bin/date +%y%b%d`.users echo " ================== " >> /raid/02d/sa/rem/log.`/usr/bin/date +%y%b%d`.users echo $x remsh $x last | awk '{print $1}' | grep -v root | grep -v reboot | sort | uniq -d \ | tee -a /raid/02d/sa/rem/log.`/usr/bin/date +%y%b%d`.users echo " ================== " echo " ================== " >> /raid/02d/sa/rem/log.`/usr/bin/date +%y%b%d`.users done echo " completed list, results found in /raid/02d/sa/rem/log.`/usr/bin/date +%y%b%d`.users " |
The Art of Linux System Administration published by O'Reilly Media Study Guide for the LPIC-2 Certification Exams |
Wagoneers FULL SIZE JEEPS JeepMeister "Jeep is America's -Enzo Ferrari MeisterTech Diesels + |
One Page Overview of Linux Commands click for an image of the 5 essential Linux commands An Intro to Linux |
at Midway Auto on SR9 in Snohomish, or at Northland Diesel in Bellingham, WA |