Switch user during script execution --help--

Discussion in 'Perl' started by Oliver, Feb 11, 2004.

  1. Oliver

    Oliver Guest

    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....
     
    Oliver, Feb 11, 2004
    #1
    1. Advertising

  2. Oliver

    boyd Guest

    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
     
    boyd, Feb 11, 2004
    #2
    1. Advertising

  3. Oliver

    Oliver Guest

    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
     
    Oliver, Feb 12, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. owais
    Replies:
    1
    Views:
    1,062
    Azhagan
    Oct 5, 2004
  2. Nicole Calinoiu
    Replies:
    0
    Views:
    445
    Nicole Calinoiu
    Apr 13, 2004
  3. daveyand
    Replies:
    5
    Views:
    96
    Dr.Ruud
    Jan 5, 2006
  4. yong
    Replies:
    8
    Views:
    2,771
    Anno Siegel
    Jan 20, 2006
  5. Switch Within A Switch

    , Apr 22, 2006, in forum: Javascript
    Replies:
    7
    Views:
    109
    Lasse Reichstein Nielsen
    Apr 22, 2006
Loading...

Share This Page