Output confirmation in a script

Output confirmation in a script

Post by Kevin R. Pac » Sun, 19 Jan 2003 21:46:55



Hey all,
Sorry about the xpost to comp.unix.misc, realized this was a better forum.

I've got a ksh script that sends email to a user informing them of
their new account info.  It runs either interactively, prompting for
the required info, or quietly when the appropriate options are given
from the command line.  It also generates a password for them.

I'm stumped on how to do two things cleanly.... display a
representation of the message to be sent on screen so the admin can
make sure everything looks ok before actually sending the message, and
second, send a copy of the message to the admin with the password
stripped.  The function goes something like this (from memory):

function send_mail
{
mailx -s "${subject} for ${user_id}" -e ${user_email) -c
${admin_email} << end
****** CONFIDENTIAL *******

Your account on ${server} has been assigned the username of
${username}
and the password ${password}.  You will be prompted to change this
password
the first time you log in.

If you need assistance, feel free to contact me.

Thank you,
${admin_name}
${admin_email}

end

Quote:} # end of send_mail

This works fine.  But, I would like to change the function somehow so
that it echos to the screen an approximation of what will be sent via
email so I can check for errors and offer me the opportunity to change
something.  Also, since the script generates the password for me, I
need to know what it is so I can set it.  Currently it CC's a copy to
me, but this is not good for security reasons, so I'd like it to strip
the password from the CC.  If I could figure out part1, part2 would be
easy.

I've got it working the way I want using three separate functions
called verify_mail send_user_mail and send_admin_mail, but it's really
ugly because it's pretty much 3 blocks of almost the same code.  I
can't seem to figure out a way to get the here doc ( << end ) to echo
to the screen, which is what I've been trying to do, but I think I'm
on the wrong path.  I'd also like to avoid using a tmp file if
possible.  Any idas?

Thx,
-krp

 
 
 

Output confirmation in a script

Post by those who know me have no need of my nam » Sun, 19 Jan 2003 22:57:26


in comp.unix.shell i read:

Quote:>Sorry about the xpost to comp.unix.misc, realized this was a better forum.

that's not what is meant by `cross-post'.  what you've done is multi-post.
hopefully you followed-up to your other post explaining why you'd rather
see answers in this group.  (it's too late though, people will respond in
the other group anyway.)

Quote:>I've got a ksh script that sends email to a user informing them of
>their new account info.  It runs either interactively, prompting for
>the required info, or quietly when the appropriate options are given
>from the command line.  It also generates a password for them.

you are e-mailing a password?  blah.  color me unimpressed.  the `you must
then change it' doesn't make it any better.  even e-mailing a token isn't
any better.  not in these days of ssl protected web sites.  (though ghu
knows that's not nearly as perfect as some seem to think.)

Quote:>I'm stumped on how to do two things cleanly.... display a
>representation of the message to be sent on screen so the admin can
>make sure everything looks ok before actually sending the message, and
>second, send a copy of the message to the admin with the password
>stripped.  The function goes something like this (from memory):

i prefer something like:

[warning: untested]

  messagefile=`mktemp /path/to/a/safe/place/to/contruct/the/messageXXXXXX` \
  || exit 1
  cat >>$messagefile <<eof
  message guts here
  eof
  if ( print "the following message will be sent to blah, blah, blah ...\n"
       cat $messagefile
     ) | ${PAGER:-more}
  then print "send ? \c"; read; [ "$REPLY" = Y -o "$REPLY" = y ]
  else
    # can't display the file give a shell
    print "cannot display content, find \"$messagefile\" and decide"
    print "truncate the bastard if it shouldn't be sent"
    ksh
    test -s $messagefile
  fi \
  && mailx ... <$messagefile
  rm -f $messagefile
  unset messagefile

(actually i would construct an rfc 2822 message so the to, from, etc.,
would all be explicit, then submit it directly to sendmail when approved.
ymmv)

--
bringing you boring signatures for 17 years

 
 
 

1. Cronjob output :You have no controlling terminal.Can't initialize readline for confirmations. ?

the cron daemon keep emailing this message to a user who has defined a
script to run every 15 minutes.
You have no controlling terminal.Can't initialize readline for
confirmations.
You have no controlling terminal.Can't initialize readline for
confirmations.

I'm really confused. As I know, cron gives this error only when the job
produces output to the screen, but there's no output at all for that
script.( the script itself doesn't generate any output, and I run it by
hand, there is no runtime error neither). The more strange thing is I got
this error since I reboot the machine 2 days ago, but with the same script,
I never got this message before. I've restarted cron but still doesn't work.
:-(

Any one has any idea will be appreciated..

2. How to migrate Cobol-AS/400 to Unix?

3. Perl script log file output has duplicate copies of output lines

4. remove sched.h from blkdev.h

5. Incomplete output from crontab email: running shell scripts from a perl script

6. Monitoring Hardware

7. Help !! capture script output from the script...

8. set-up for mac 2 linux serial-port terminal?

9. Shell script to run script to record output from a program

10. typeset -f gives funny output when executed from Korn shell script

11. script reading 'tail -f file' output

12. Output redirection in shell script

13. Need a Hayes modem buy confirmation