in reply to Problem with renaming files in directory

If I don't use the -T switch on my shebang line, the script renames files without that error. Do you really need -T (perlsec)?

Also, I get quotes in the file names. To avoid that, you should change:

$new_name =~ s/.*/"sniffer$value\.log"/;
to:
$new_name = "sniffer$value.log";
Also, readdir may not return the order you expect if you have double digits.

Replies are listed 'Best First'.
Re^2: Problem with renaming files in directory
by ice_ice_ice (Initiate) on Jan 03, 2012 at 16:30 UTC
    ok, thanks for replies guys :) Right now my code is:
    foreach my $filename (reverse((grep /^sniffer/, <*>))) { my $new_name = $filename; if($new_name =~ m/(\d+)/) { my $value = $1 +1; $new_name = "sniffer$value.log"; } else { $new_name = "sniffer1.log"; } rename($filename, $new_name) unless $filename eq $new_name; }

    I didn't run with -T switch and I have all the time the error. Do you have any other hints ? :)

      Using diagnostics reveals this info:
      Insecure dependency in rename while running with -T switch at (F) You tried to do something that the tainting mechanism didn't l +ike. The tainting mechanism is turned on when you're running setuid or setgid, or when you specify -T to turn it on explicitly. The tainting mechanism labels all data that's derived directly or indi +rectly from the user, who is considered to be unworthy of your trust. If + any such data is used in a "dangerous" operation, you get this error. + See perlsec for more information. Uncaught exception from user code: Insecure dependency in rename while running with -T switch at
      Since you are not explicitly using -T, look into setuid or setgid.

      By the way, changing readdir to glob will not solve the double-digit filename issue.

        So what should I do solve this double-digit filename issue ?:)

        I run this script as a root and I found that perl create those files with user id 200. I don't have user with this id. So for me is this strange. The group id for this file is the root, so everything is ok. If anyone know why I have user id 200 instead of 0 ?