Sponsored Content
Top Forums Shell Programming and Scripting [e-mailing] send login pwd to several users Post 302991481 by drysdalk on Saturday 11th of February 2017 05:33:24 AM
Old 02-11-2017
Hi,

One thing to think about here is whether e-mailing these logins in the clear is actually the best way to distribute usernames and passwords to your users. Depending on your setup, there are likely to be various points at which someone could potentially sniff these messages in clear text as they're passing by, and thusly obtain your users' credentials.

However, if you are set on doing things this way, here's a solution.

Firstly, I've made a slight change to the format of letter.txt, so that it now looks like this:

Code:
$ cat letter.txt
Hello,
Here is your login : _USERNAME_ and your password : _PASSWORD_
cordially
$

So I'm using _USERNAME_ and _PASSWORD_ as placeholders here for what will be the real login details, as we'll see in a bit.

As for your maillist.txt, that's basically the same:

Code:
$ cat maillist.txt
unixforum password-U unixforum@localhost
root password-R root@localhost
$

So the first field is the username to be e-mailed, the second is the password to be e-mailed, and the third is the e-mail address to which the details should be sent.

Lastly, here's the actual script itself:

Code:
$ cat my_script.sh
#!/bin/bash

cat maillist.txt | while read -r line
do
        username=`echo $line | awk '{print $1}'`
        password=`echo $line | awk '{print $2}'`
        email=`echo $line | awk '{print $3}'`

        cat letter.txt | sed -e s/_USERNAME_/$username/g -e s/_PASSWORD_/$password/g | mail -s "Your subject" $email
done
$

So the idea is that we read in each line of maillist.txt, break out the username, password and e-mail address, do a search-and-replace in letter.txt to swap out the underscore-bracketed placeholders for the real details, then we e-mail them to the address on file.

And here's a sample session of it being run:

Code:
$ whoami
unixforum
$ ./my_script.sh
$ mail
"/var/mail/unixforum": 1 message 1 new
>N   1 unixforum@localhost Sat Feb 11 10:28  17/719   Your subject
? 1
<e-mail headers appear here, redacted>

Hello,
Here is your login : unixforum and your password : password-U
cordially
? d 1
? q
Held 0 messages in /var/mail/unixforum
$

Hope this helps.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to send mail to multiple users ???

Hi All, How to send mails to multiple users using a single mailx command. Urgently require help Thanks in advance Rgds Arunava (3 Replies)
Discussion started by: arunava_maity
3 Replies

2. UNIX for Dummies Questions & Answers

send email to more users

Hi, If I want to send an email to serveral users, what is the correct way to do it? I know a little bit mail command. If I want to send email to John and Scott after UNIX shell scripts have completed the job. I type: mail -s 'Job has been completed successfully' john@yahoo.com < log.txt ... (4 Replies)
Discussion started by: duke0001
4 Replies

3. Linux

Users with login privileges

Hi. I need the name for one command which I cant remember. This command displays all users which can log in to the system, wether they are stored in /etc/passwd, NIS og LDAP. Does anyone remember what command this is? (2 Replies)
Discussion started by: sprellari
2 Replies

4. UNIX for Dummies Questions & Answers

to send email to multiple users

hi, i'm pretty new to this unix. i've been asked to create a shell script which will pick up the email id from a text file(stored in same machine, same directory) searches for that id in another file in which a product name( a one line text) is mentioned against it. then it should send a mail... (0 Replies)
Discussion started by: vishwas.shenoy
0 Replies

5. Shell Programming and Scripting

users login

Hello everyone I need to send to a file the last command from all users who log in and log out by week or month. My questions are I can do it with the command or I need to do a script ? If the answer is I need to do a script, someone can help me because Im complete new to make a... (3 Replies)
Discussion started by: lo-lp-kl
3 Replies

6. HP-UX

No users can login

Dear Forum, I had this case before, all of sudden all users including root can't login. What done is by connecting to console port and resetting root password, "pwunconv" command, reboot server. My question is, how this can happen??? thanks :confused: (3 Replies)
Discussion started by: irda
3 Replies

7. AIX

sync samba pwd with aix5.3 pwd

currently, my samba login works just fine. i want my clients to use aix5.3 account to login to samba so they don't have to change samba pwd and aix pwd. i googled, and vi /usr/lib/smb.conf per some of knowledge base, but i could not get to work. aix5.3 and samba 3.0.24.0 thanks in advace..... (2 Replies)
Discussion started by: tjmannonline
2 Replies

8. Shell Programming and Scripting

Challenging task : script for mailing process completion timing report to users.

Hi all, This is my first post. I am new to unix scripting. My requirement is as follows : We are using a financial backoffice application. Now at the end of day we have send users a status report stating all timings of EOD processes for all countries. I need timings for following... (0 Replies)
Discussion started by: ammbhhar
0 Replies

9. Shell Programming and Scripting

Send e-mail to users

Dear all, The perl script to send e-mail is working in my current script. #This part of the script will send the email notification my $to='mohamed.rahman@noridian.com'; my $from='xyz@hotmail.com'; my $subject='POS_CODES_38 DATA LOADED SUCCESSFULLY.'; my $message='The total no. of files... (2 Replies)
Discussion started by: msrahman
2 Replies

10. Shell Programming and Scripting

Send a mail to multiple users

I have a file 1.txt which has 3 mail ids as below: Maillist=abc@gmail.com def@gmail.com rcg@gmail.com Now I want to write a script which will read this file and send the mail to all the users present in this file. (6 Replies)
Discussion started by: Vivekit82
6 Replies
logins(1M)																logins(1M)

NAME
logins - display system and user login data SYNOPSIS
groups] logins] DESCRIPTION
displays data concerning system and user logins. The format and content of the output is controlled by command options and may include: system or user login, user ID number, comment field value (for example, user name, location), primary group name, primary group ID, supple- mentary group names, supplementary group IDs, home directory, login shell, user security level, user audit events, and password aging parameters. The default data is: login, user ID, primary group name, primary group ID, and comment field value. Output is sorted by user ID, with user logins following system logins. The default output consists of login, user ID, primary group, primary group ID and comment field formatted into columns. The following options are available to this command: Display two account expiration fields. The fields show how long the account can be unused (in days) before it becomes inactive and the date the account will expire. Display logins with duplicate UIDs. Show multiple group membership data. Display with alternate format of one line of colon separated fields. Display logins with no passwords Display all system logins Sort output by login rather than UID. Display all user logins. Display extended information about selected users. This extended information includes home directory, login shell and password aging data, each on its own line. Password information consists of pass- word status (PS for valid password, LK for locked and NP for no password) and, if a password is present, date of last change, required number of days between changes, and number of days allowed between changes. In the case of non-trusted systems, the date of last change will be the latest Thursday since the change. Display all users belonging to groups, sorted by login. A comma separated list specifies multiple groups. Display the requested logins. A comma separated list specifies multiple logins. Specify a switch used to classify NIS or local users. With the option, only users belonging to the specified repository are displayed. Multiple options may be used. Any login matching any of the criteria will be displayed. A login will be displayed only once, even if it meets multiple criteria. EXAMPLES
List all logins in default format. List all logins that have no password or have a duplicate UID in default format. List all system logins in the alternate format. List all local users of the system. List all the NIS users of the system. WARNINGS
HP-UX 11i Version 3 is the last release to support trusted systems functionality. FILES
HP-UX password file. HP-UX group file. SEE ALSO
listusers(1), passwd(1), group(4), passwd(4), prpwd(4), shadow(4). STANDARDS CONFORMANCE
logins(1M)
All times are GMT -4. The time now is 03:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy