Script for mailing /etc/passwd information

Kurian Thayil kurianmthayil at gmail.com
Mon Jun 1 13:52:33 UTC 2009


Hi,

The code given below will fetch the all the users and its corresponding
shell info and copies in a file. Then sends this file to the desired mailing
address.

#!/bin/bash
filename=/tmp/passwdinfo.txt
while read line
do
 username=`echo $line | cut -d":" -f1`
 shellname=`echo $line | cut -d":" -f7`
 echo "User: $username" >>$filename
 echo -e "Shell: $shellname\n" >>$filename
done</etc/passwd
echo "Mailing information"
cat $filename | mail -s "SUBJECT" mail at mail.com
# For sending file as attachment, uncomment the below line and comment the
above.
mutt -a $filename -s "SUBJECT" mail at mail.com
[ $? = 0 ] && echo "mail sent successfully."; rm -vf $filename || echo
"Error while sending mail."

Hope this helps.

Regards,

Kurian Thayil.

On Mon, Jun 1, 2009 at 7:03 PM, Hike <mh1272 at gmail.com> wrote:

> This a good time to learn.
> (Apart from the security nightmare you may be creating.)
>
> awk, cut, are to use inside a scripy
> perl would be good, too
>
>
> On Jun 1, 2009, at 9:10 AM, a bv <vbavbalist at gmail.com> wrote:
>
> Hi list,
>>
>> I need a script which will get the users and their shell from
>> /etc/passwd file and mail it to the company mail account which i use
>> on Lotus Notes. Im not yet a scripting guy so i wanted to ask to you.
>>
>> Regards
>>
>> --
>> redhat-list mailing list
>> unsubscribe mailto:redhat-list-request at redhat.com?subject=unsubscribe
>> https://www.redhat.com/mailman/listinfo/redhat-list
>>
>
> --
> redhat-list mailing list
> unsubscribe mailto:redhat-list-request at redhat.com?subject=unsubscribe
> https://www.redhat.com/mailman/listinfo/redhat-list
>



More information about the redhat-list mailing list