perl, How spawn inside a backtick or system

Posted on 2011-10-17
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.

`su - user1 /home/myshellprogram &`;

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

    Expert Comment

    LVL 2

    Assisted Solution

    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.
    LVL 9

    Accepted Solution

    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:

    Author Closing Comment

    It was syntactically incorrect, but after fixing it. It worked.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    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…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now