perl, How spawn inside a backtick or system

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
rgbcofAsked:
Who is Participating?
 
parparovCommented:
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
 
FishMongerCommented:
0
 
wiredpeaCommented:
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
 
rgbcofAuthor Commented:
It was syntactically incorrect, but after fixing it. It worked.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.