Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

perl, How spawn inside a backtick or system

Posted on 2011-10-17
4
Medium Priority
?
269 Views
Last Modified: 2012-05-12
I am "root" and I am running perlscript (so running as root), and I want to switch user (su) to another user, and spawn a shell program.

My best attempt is, but it is not spawning my myshellprogram, but it is sending & as a parameter into the myshellprogram instead.

#!/usr/bin/perl
`su - user1 /home/myshellprogram &`;

I am willing to accept answer in anyforms:
exec, system, or backticks
0
Comment
Question by:rgbcof
4 Comments
 
LVL 28

Expert Comment

by:FishMonger
ID: 36983298
0
 
LVL 2

Assisted Solution

by:wiredpea
wiredpea earned 300 total points
ID: 36984174
you should first su and then run the command like this:
su user1;  /home/myshellprogram &`;

Open in new window


Or you could could modify the file right to suid user1
chown user1  /home/myshellprogram
chmod 4755  /home/myshellprogram

Open in new window

and then you dont need to do the su ever again.
0
 
LVL 9

Accepted Solution

by:
parparov earned 1200 total points
ID: 36994718
In a way like this, you would be better off with:
system('su - user1 "/home/myshellprogram &")

Open in new window

or even
exec('su - user1 "/home/myshellprogram &")

Open in new window

- especially if you fork.
Also, you may want to read here:
http://perldoc.perl.org/perlfaq8.html#How-do-I-start-a-process-in-the-background?
0
 

Author Closing Comment

by:rgbcof
ID: 37016089
It was syntactically incorrect, but after fixing it. It worked.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question