Martin G. McCormick wrote:
>       I have a perl script that I run as root which needs to
> move a file from where it is to another directory.
>
>       I keep getting the "Usage"  help message and a
> permission denied. If I su to root and manually make the move,
> it works.
>
>       The perl script is not trying to run suid to root. I am
> root when I call it. The line in question reads:
>
> system(
> "mv $directories$filename \"$directories\"deleted_keys/"
> );
>
> $directories and $filename are correctly set at the time. The
> output from the script is:
>
> usage: mv [-f | -i | -n] [-v] source target
>        mv [-f | -i | -n] [-v] source ... directory
> /var/named/etc/namedb/dynamic/okstate.edu/deleted_keys/: Permission denied
>

As has already been mentioned, part of the problem is your quoting.

What is the value of $directories and more specifically, does it end with
a forward slash?  Personally, I prefer to leave off the trailing dir
separator because IMO it makes it more clear later when the $filename is
added.

Why are you using a system call instead of the more portable move() of
mv() function from File::Copy, which is a core module?

use File::Copy qw(cp mv);

...
...

mv("$directories/$filename", "$directories/deleted_keys")
  or warn qq(Failed to move "$directories/$filename" to
"$directories/deleted_keys" <$!>);


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to