% Remember to use the lgrind style

\Head{}
\File{root\-bad\-logins.sh}{2003}{Apr}{16}{18:46}{1098}
\L{\LB{\C{}\#!_\1bin\1sh}}
\CE{}\L{\LB{}}
\L{\LB{\C{}\#_Question_3,_shell_programming_assignment,_2003.}}
\CE{}\L{\LB{\C{}\#_method_using_lastb:}}
\CE{}\L{\LB{}}
\L{\LB{\V{prog}={`}\V{basename}_\N{\$0}{`}}}
\L{\LB{\V{usage}()_\{}}
\L{\LB{___\V{echo}_\S{}\3Usage:_\$prog_[\-f]_[\-d]_[\-u_user]\3\SE{}}}
\L{\LB{___\V{echo}_\S{}\3Show_bad_login_attempts.\3\SE{}}}
\L{\LB{___\V{echo}_\-\-_\S{}\3\-f_sort_output_by_days_of_most_frequent_bad_attempts_first\3\SE{}}}
\L{\LB{___\V{echo}_\-\-_\S{}\3\-d_sort_output_by_date_(default)\3\SE{}}}
\L{\LB{___\V{echo}_\-\-_\S{}\3\-u_user_get_output_for_user_instead_of_root\3\SE{}}}
\L{\LB{___\K{exit}_\N{1}}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\V{USER}=\V{root}}}
\L{\LB{\V{SORTBY}=\V{date}}}
\L{\LB{}}
\L{\LB{\K{while}_\V{getopts}_\S{}\3:fdu:\3\SE{}_\V{opt}}}
\L{\LB{\K{do}}}
\L{\LB{____\K{case}_\N{\$opt}_\K{in}}}
\L{\LB{________\V{f})_\V{SORTBY}=\V{frequency}_;;}}
\L{\LB{________\V{d})_\V{SORTBY}=\V{date}__;;}}
\L{\LB{________\V{u})_\V{USER}=\N{\$OPTARG}_;;}}
\L{\LB{________\*)_\V{usage}________;;}}
\L{\LB{____\K{esac}}}
\L{\LB{\K{done}}}
\L{\LB{\K{shift}_\N{\$}((\V{OPTIND}_\-_\N{1}))}}
\L{\LB{}}
\L{\LB{\V{TMPFILE}={`}\V{mktemp}_\1\V{tmp}\1\N{\$}\{\V{prog}\}.\V{XXXXXX}{`}_\|\,\|_\K{exit}_\N{1}}}
\L{\LB{\K{trap}_\S{}\3rm_\$TMPFILE\3\SE{}_\V{HUP}_\V{INT}_\V{QUIT}_\V{PIPE}_\V{ALRM}_\V{TERM}_\V{EXIT}}}
\L{\LB{\V{lastb}_\N{\$USER}_\>_\S{}\3\$TMPFILE\3\SE{}}}
\L{\LB{}}
\L{\LB{\K{if}_[_\S{}\3\$SORTBY\3\SE{}_=_\S{}\3date\3\SE{}_]}}
\L{\LB{\K{then}}}
\L{\LB{____\V{cat}_\S{}\3\$TMPFILE\3\SE{}}}
\L{\LB{____\K{exit}_\N{0}}}
\L{\LB{\K{elif}_[_\S{}\3\$SORTBY\3\SE{}_=_\S{}\3frequency\3\SE{}_]}}
\L{\LB{\K{then}}}
\L{\LB{____\V{lastb}_\-\V{R}_\N{\$USER}_\2}}
\L{\LB{____\|_\V{egrep}_\-\V{v}_\S{}\4\5\2s\*\$\|\5btmp_begins\4\SE{}_\2}}
\L{\LB{____\|_\V{awk}_\S{}\4\{\$1=\3\3;\$2=\3\3;print\}\4\SE{}_\2}}
\L{\LB{____\|_\V{cut}_\-\V{b}_\N{3}\-\N{12}_\2}}
\L{\LB{____\|_\V{uniq}_\-\V{c}_\2}}
\L{\LB{____\|_\V{sort}_\-\V{bnr}_\2}}
\L{\LB{____\|_\V{awk}_\S{}\4\{\$1=\3\3;printf_\3\%s_\%s_\%2d\2n\3,_\$2,_\$3,_\$4\}\4\SE{}_\2}}
\L{\LB{____\|_\K{while}_\K{read}_\V{date}}}
\L{\LB{____\K{do}}}
\L{\LB{________\V{fgrep}_\S{}\3\$date\3\SE{}_\S{}\3\$TMPFILE\3\SE{}}}
\L{\LB{____\K{done}}}
\L{\LB{\K{fi}}}
