#! /bin/sh # shell-usage --- summarize percentage of users using "valid" shells # Author: Noah Friedman # Public domain # $Id: shell-usage,v 1.2 1995/08/10 23:21:50 friedman Exp $ case $# in 0 ) set /etc/passwd ;; esac shells=${ETCSHELLS-/etc/shells} exec ${AWK-nawk} ' function listp (list, elt) { for (elt in list) { return 1; } return 0; } function get_valid_shells (valid_shells, shellfile) { shellfile = "'"$shells"'"; while ((getline < shellfile) > 0) if ( $1 !~ "^#.*" ) valid_shells[$1] = $1 ; close(shellfile); } BEGIN { FS = ":" total = 0 get_valid_shells(valid_shells); } { split($0, fields, ":") if (fields[7] == "") fields[7]="/bin/sh" if ((! listp(valid_shells)) || fields[7] in valid_shells) { num=split(fields[7], pathcomp, "/") shell=pathcomp[num] if (!(shell in shell_list)) shell_list[shell] = 0; shell_list[shell]++ total++ } } END { printf("Total: %d\n", total) printf("%-10s %-10s %-10s\n", "Shell", "Users", "Percent") printf("%-10s %-10s %-10s\n", "-----", "-----", "-------") for (sh in shell_list) { percentage = (100 * shell_list[sh]) / total printf("%-10s %-10d %-10d\n", sh, shell_list[sh], percentage); } }' ${1+"$@"} # eof