パルスクリップ.pl

パルスクリップ.pl

次のコマンドで使用するために、他のスクリプトの中に小さなスクリプト(perl-script.pl)を配置したいと思いますfind

#Saving the previous permission information for a possible recovery.
case "$STAND" in
        n|N|nao|no"")
        find /backup/"$INSTANCE"/tsm/* -exec /path/to/perl-script.pl {} + >> /tmp/permissions.txt
        chmod u+x /tmp/permissions.txt
    ;;
        s|S|y|Y|sim|yes)
        [... below code is similar of above]
    ;;
esac

パルスクリップ.pl

!/usr/bin/env perl -w
use strict;
for (@ARGV) {
  my @s = stat;
  next unless @s; # silently fail on to the next file
  my $filename = $_;
  $filename =~ s/'/'\\''/g;
  printf "chown %s:%s '%s'\nchmod %04o '%s'\n", (getpwuid($s[4]))[0], (getgrgid($s[5]))[0], $filename, ($s[2] & 07777), $filename;
}

簡単に言えば、他のスクリプトからインポートする必要なくこの find コマンドを使用したいと思います。または、単一のコマンドでこれをどのように実行できますか?

ベストアンサー1

可能な回復のためにディレクトリの内容の所有権と特権属性を収集する完全に埋め込まれたスクリプトが必要な場合は、次のスクリプトを使用できます。

#!/usr/bin/env perl
use strict;
use warnings;
use File::Find;
sub wanted {
    my ( $mode, $uid, $gid ) = ( stat($_) )[ 2, 4, 5 ];
    printf "chown %s:%s '%s'\n", $uid, $gid, $File::Find::name;
    printf "chmod %04o '%s'\n", $mode & 07777, $File::Find::name;
    return;
}
my @dir = @ARGV ? @ARGV : '.'; # use current directory unless told
find( \&wanted, @dir );
1;

必要に応じてスクリプト名を指定します。実行するには、ディレクトリ(またはディレクトリ)をサンプルに渡します。引数を指定しないと、現在の作業ディレクトリが使用されます。

おすすめ記事