473,382 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Switch user during script execution --help--

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....
Jul 19 '05 #1
2 7658
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 nu***@some.com' ");

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 nu***@some.com < /etc/hosts'");

Boyd
Jul 19 '05 #2
boyd <He***********@yahoo.com> wrote in message news:<40**************@yahoo.com>...
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 nu***@some.com' ");

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 nu***@some.com < /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
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: SimonC | last post by:
A couple of questions: (1) I have some PHP code that may take a while to execute - say 30-45 seconds or more - and I'm concerned that a browser may give up, and report an error because a page is...
10
by: Doug | last post by:
I have a script that does a huge database update, which takes a long time. However, the host I am running on (and I suspect most hosts) are running in "safe mode." This means I cannot change the...
5
by: Markus Stehle | last post by:
Hi all! I have asp.net web application that uses static impersonation. Is it possible to change the impersonated user during runtime? Within some parts of my application I would like to...
3
by: iam980 | last post by:
Hello All. We have tested following SQL script from query analyzer: -- Script begin DECLARE @I int; SET @I = 1; WHILE @I < 10000000 BEGIN SET @I = @I + 1; END -- Script end
0
by: nj | last post by:
How do you resolve: An error occurred during the execution of the SQL file 'InstallCommon.sql'. The SQL error number is 1802 and the SqlException message is: CREATE DATABASE failed. Some file...
1
by: s99999999s2003 | last post by:
hi due to certain constraints, i will running a python script as root inside this script, also due to some constraints, i need to switch user to user1 to run the rest of the script...is there a...
0
by: =?Utf-8?B?Zmxhc2hlczE=?= | last post by:
Have been using XP for years. Now find that when switch user is used, just get a black screen with the mouse. Have to reboot. Can not have 2 users logged on together. Switch user is enabled....
2
by: BlackjadeLin | last post by:
I'm new to python I want to write a simple script to switch user,for example,from user_A to user_B. This my codes: #!/usr/bin/python import pexpect import os passwd="user_B" child =...
1
by: questionit | last post by:
Hi On one of my XP machines, "switch user" shows but not on the other. How to bring up "Switch User" button when click on Log Off button. Qi
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.