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.

`su - user1 /home/myshellprogram &`;

I am willing to accept answer in anyforms:
exec, system, or backticks
Who is Participating?
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:
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.
rgbcofAuthor Commented:
It was syntactically incorrect, but after fixing it. It worked.
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.