I'm new to scripting, so far I've created this:#!/bin/sh(echo List of users in PRD echo $(date)cat /etc/passwd | awk -F: '{print $1,$3,$5}' | sort | \while read username uid gecosdoecho ${username}:${uid}:${gecos}done) > `hostname`_userlogins.txtmailx -s file xxxxxx@unix.com < `hostname`_userlogins.txtThis gives a list of all users. I have another file (called ignore.txt) which has list of users to be excluded before sending the email out. How do I link the list with ignore.txt to filter?
assistance with scripting list of users
linux;shell script;aix
You can use grep to filter out usernames:grep -wvf ignore.txt /etc/passwd | awk ...grep is used to search for patterns usually, but with -v can be used to negate the search, and thus for filtering. The matches can be a bit broad (for example, joe will filter out joe and joey), so use -w to restrict its effect to whole-word matches.Other suggestions:awk can be told to print with colons, saving you the trouble of the loop:grep -wvf ignore.txt /etc/passwd | awk -F: -v OFS=: '{print $1, $2, $3}'echo $(date) is pointless. Just use date.Use tee to write to a file and again to the pipe:) | tee $(hostname)_userlogins.txt | mail ...Overall, the script can be simplified to:#!/bin/sh(echo List of users in PRD dategrep -wvf ignore.txt /etc/passwd | awk -F: -v OFS=: '{print $1,$3,$5}' | sort ) | tee $(hostname)_userlogins.txt |mailx -s file xxxxxx@unix.com