#!/bin/sh ## ## NAUTILUS ## SCRIPT: 00_anyfil_SHO_GROUP-MEMBERSHIPS_ofEachUSER_etc-passwd-cut-sort-groups.sh ## ## PURPOSE: Show the groupids for each user known to this host. ## ## METHOD: Uses the '/etc/passwd' file to get the userids. ## Uses 'sort' to sort the userids. ## Uses the 'groups' command on each userid to get the group ## memberships. ## ## This list is put in a text file and the text file is shown ## in a textfile-viewer of the user's choice. ## ## HOW TO USE: In Nautilus, select ANY file in ANY directory. ## Then right-click and choose this script to run (name above). ## ##################################################################################### ## Created: 2011may02 ## Changed: 2011may11 Get 'nautilus-scripts' directory via an include script. ## Changed: 2012may12 Changed script name in comments above and touched up ## the comments. Changed some indenting below. ####################################################################### ## FOR TESTING: (show statements as they execute) # set -x ############################################################### ## Prep a temporary filename, to hold the list. ## We put the output file in /tmp, in case the user ## does not have write-permission in the current directory. ############################################################### OUTFILE="/tmp/${USER}_groupids_4ALLusers_thisHost.lis" if test -f "$OUTFILE" then rm -f "$OUTFILE" fi ################################### ## Get the userids from /etc/passwd. ################################### USERIDS=`cut -d: -f1 /etc/passwd | sort` ############################# ## PREPARE REPORT HEADING. ############################# THISHOST=`hostname` echo "\ ***************************** `date '+%Y %b %d %a %T%p %Z'` ***************** Groups in which users are a member --- for each userid on host: $THISHOST Userid : Groups ------ ----------------------------------------------------------------------- " > "$OUTFILE" ############################## ## PREP REPORT CONTENTS ## via a loop on userids. ############################## for USERID in $USERIDS do echo "`groups $USERID`" >> "$OUTFILE" done ############################### ## ADD A TRAILER TO THE REPORT. ############################### SCRIPT_BASENAME=`basename $0` SCRIPT_DIRNAME=`dirname $0` echo " ---------------- `date '+%Y %b %d %a %T%p %Z'` -------------------- The list above was generated by script $SCRIPT_BASENAME in directory $SCRIPT_DIRNAME Command used: groups --- on each userid in /etc/passwd ----------------------------------------------------------------------------- " >> "$OUTFILE" ############################ ## SHOW REPORT FILE. ############################ ## . $HOME/.gnome2/nautilus-scripts/.set_VIEWERvars.shi . $HOME/.freedomenv/feNautilusScripts/set_DIR_NautilusScripts.shi . $DIR_NautilusScripts/.set_VIEWERvars.shi $TXTVIEWER "$OUTFILE" &