0

I've writen a perl script that needs sudo rights, but it accepts parameters that are always different. eg

sudo /home/user/script.pl user

I guess adding this to visudo will not work. Is this possible? If not I was thinking about maybe using something like a pipe to solve this problemm like:

echo user | sudo /home/user/script.pl

Is there a way to pass variables this way to a perl script?

The only other option I see is writing the parameters to a file. Then I can still add the script to visudo.

TheChosenOne
  • 181
  • 1
  • 1
  • 8

1 Answers1

0

Why not use ARGV? content of tmp/script.pl

use strict;
use warnings;

print join(',', @ARGV);

exit;

and as result

$ sudo perl tmp/script.pl foo bar
> foo,bar

Or you can use Getopt::Long (extended processing of command line options)

T'East
  • 79
  • 1
  • 3