Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Switch user during script execution --help--

Reply
Thread Tools

Switch user during script execution --help--

 
 
Oliver
Guest
Posts: n/a
 
      02-11-2004
I've been looking for information regarding this and all i can gather
is posters informing posties to use $< and $>. However, i can't seem
to find an example on how to apply that.

Information regarding my script
Basically, this script runs as root, parses thru the shadow file to
calculate if any accounts are about to expire, than parses the passwd
file to get the user(s) names, and outputs the matching userids and
names to a text file. I now need this script to switch to another user
and send an email to an external email address with the contents of
that text file as the body of the email.
help....
 
Reply With Quote
 
 
 
 
boyd
Guest
Posts: n/a
 
      02-11-2004
Oliver wrote:
> I've been looking for information regarding this and all i can gather
> is posters informing posties to use $< and $>. However, i can't seem
> to find an example on how to apply that.
>
> Information regarding my script
> Basically, this script runs as root, parses thru the shadow file to
> calculate if any accounts are about to expire, than parses the passwd
> file to get the user(s) names, and outputs the matching userids and
> names to a text file. I now need this script to switch to another user
> and send an email to an external email address with the contents of
> that text file as the body of the email.
> help....

One way is just do a system call something like:
system("su - otheruser -c 'echo hi | mail ' ");

This works on my system. But I haven't found how to do a whole file
without writing the text file to disk and then tell it to send the mail
as that disk file as input. This works, for example:
system("su - otheruser -c 'mail < /etc/hosts'");

Boyd


 
Reply With Quote
 
 
 
 
Oliver
Guest
Posts: n/a
 
      02-12-2004
boyd <> wrote in message news:<>...
> Oliver wrote:
> > I've been looking for information regarding this and all i can gather
> > is posters informing posties to use $< and $>. However, i can't seem
> > to find an example on how to apply that.
> >
> > Information regarding my script
> > Basically, this script runs as root, parses thru the shadow file to
> > calculate if any accounts are about to expire, than parses the passwd
> > file to get the user(s) names, and outputs the matching userids and
> > names to a text file. I now need this script to switch to another user
> > and send an email to an external email address with the contents of
> > that text file as the body of the email.
> > help....

> One way is just do a system call something like:
> system("su - otheruser -c 'echo hi | mail ' ");
>
> This works on my system. But I haven't found how to do a whole file
> without writing the text file to disk and then tell it to send the mail
> as that disk file as input. This works, for example:
> system("su - otheruser -c 'mail < /etc/hosts'");
>
> Boyd



Thanks Boyd!
I tried what you suggested..had to make some changes but it finally
worked..
what i ended doing was

system(`su - user2 -c "mail someuser\@somedomain.com -s 'SCP Account
Password Change Notification' < /tmp/notification.txt"`);

that did the trick!

thanks again
Oliver
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Block execution of script while same script is already running MrBanabas@googlemail.com Ruby 2 12-17-2008 06:03 PM
Get cgi script to begin execution of another script... sophie_newbie Python 1 03-13-2008 02:52 PM
private data stashed in local/global execution context of PyEval_EvalCode disappears down the execution stack sndive@gmail.com Python 9 11-14-2007 10:31 PM
Interrupting a script during execution for user help file daveyand Perl Misc 5 01-05-2006 11:46 AM
How to display progress bar in windows form during execution of DTS package? owais ASP .Net 1 10-05-2004 09:11 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57