Switch user during script execution --help--

O

Oliver

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....
 
B

boyd

Oliver said:
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 (e-mail address removed)' ");

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 (e-mail address removed) < /etc/hosts'");

Boyd
 
O

Oliver

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

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 (e-mail address removed) < /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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top