Wednesday, September 24, 2008

Funky Command Line

I'll take 'Command Lines that should have been shell scripts for $100, Alex'

And the answer is:

"How do I see which users have logged into my FTP server this year, how many times, and when was their last login?"

And the question:


for FILE in `tail -n 12092 xferlog | awk '{print $14}' | sort | uniq -c | sort -g | awk '{print $2}' ` ; do echo -n "$FILE: " ; echo -ne "\t\t`grep $FILE xferlog | wc -l` times. \tLast login: " ; grep $FILE xferlog | tail -n 1 | awk '{print $1 " " $2 " " $3}' ; done


Of course, this supposes that you have neglected to add xferlog to your logrotate config, AND you have exactly as many lines in your file as me. YMMV ;-)