Mailing List Archive

variable suicide resend
|#!/usr/bin/perl -w
|
|#use strict;
|
|my (
| %count, # how many of each shell we have
| $input, # name of input file; maybe pipe
| %ok, # whether the shells are ok
| $shell, # which shell
| @notes, # complaints
|);
|
|format Shell_Header =
|Shell Report for @<<<<<<<<<<<<<<<<<<<<<<<<<<< Page @>>
| scalar localtime, $%
|
|@<<<<<<<<<<<<<<< @>>>>>> @*
|'Shell Name', 'Usage', 'Notes'
|-----------------------------------------------------------
|.
|
|format Shell_Info =
|@<<<<<<<<<<<<<<< @>>>>>> @*
|{
|$shell,
| $count{$shell},
| uc(join ", " => @notes)
|
|}
|.
|
|if (!open (SHELLS, "/etc/shells")) {
| warn "can't open /etc/shells: $!";
| warn "using <DATA>....";
| *SHELLS = *DATA; # how to copy/assign/pass filehandles
|} else {
| warn "opened /etc/shells....";
|}
|
|while ( <SHELLS> ) {
| chop;
| s/#.*//;
| next unless $_;
| $ok{$_}++;
|}
|close(SHELLS) || die "can't close shells: $!";
|
|# check for the yellow plague
|#if ( `domainname` =~ /\S/) {
| #$input = "ypcat passwd |";
|#} else {
| $input = "< /etc/passwd";
|#}
|
|open (INPUT, $input) || die "can't open $input: $!";
|open (OUTPUT, ">> shell_log") || die "can't open shell_log: $!";
|
|warn "opened input $input....";
|warn "opened output >> shell_log....";
|
|select OUTPUT;
|
|($^, $~) = qw(Shell_Header Shell_Info);
|
|while ( <INPUT> ) {
| m{
| : (?# last colon)
| ([^:]*) (?# capture all stuff not a colon, but maybe 0)
| \n (?# explicitly match the final newline)
|
| }x;
| $count{ $1 || '/bin/sh' } ++;
|}
|
|foreach $shell ( sort {
|
| $count{$::b} <=> $count{$::a}
| ||
| $::a cmp $::b
|
| } keys %count ) {
| @notes = ();
|
| push @notes, 'missing' unless -e $shell;
| push @notes, 'not executable' if -e $shell && !-x $shell;
| push @notes, 'unauthorized' unless $ok{$shell};
|
| write;
|}
|
|__END__
|# this default shell data
|/bin/sh
|/bin/csh
|/bin/tcsh # comments
|/bin/ksh
|/usr/local/bin/tcsh
|/usr/local/bin/bash
|/usr/local/gnu/bin/bash
|
|