+ Reply to Thread
Results 1 to 2 of 2

Thread: Perl system is called when running as another user

  1. #1
    Junior Member
    Join Date
    Feb 2012

    Perl system is called when running as another user

    I have developed a perl script which provides a menu driven functionality to allow users to carry out some simple tasks.

    I need the users to be able to carry out tasks such as copying files (keeping the current date and permissions), running other programs (such as less or vi) as a different user. The script uses alot of use of the system() function.
    I want the users to start the menu by calling:
    sudo -u perluser /usr/bin/perl /data/perlscripts/scripta.pl
    This should start the script as perl user, which it does, and then carry out different tasks depending on what the user selects. The problem is that whenever I use a system call such as
    I get the following error
    Can't exec "clear": Permission denied at /data/perlscripts/scripta.pl line 3
    If I run the script by logging in as perluser then it all runs succesfully.

    Is there any way to get this working? I do not want users to be able to log in as perluser as I need to control what they are able to run. I also do not want to run a command like
    system("sudo -u perluser clear");
    as I would then require a different team to set up all the sudo commands I wanted to run (which they will probably refuse to do) and this would not be scalable if I have to add extra commands at somepoint.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    I think you probably need to add the -i option ("simulate initial login") to sudo:
    sudo -i -u perluser /usr/bin/perl /data/perlscripts/scripta.pl
    That will ensure that .profile or .login or whatnot is run properly, and therefore that $PATH is set up properly and so on. It will really be, in almost all respects, as if perluser were actually logging in and running
    /usr/bin/perl /data/perlscripts/scripta.pl
    at the shell.

+ Reply to Thread

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts