パルスクリップ.pl

パルスクリップ.pl

Linuxでは、次のコマンドを使用してこの出力を表示します。

 find /backup/$INSTANCE/tsm/* -exec echo '"{}" ' \; | xargs stat --printf "chown %U:%G '%n'\nchmod %a '%n'\n" >> /tmp/permissions.txt

このコマンドは、次の出力を返します。

[filipe@filipe ~]$ cat /tmp/permissions.txt  
chown filipe:filipe '/backup/filipe/tsm/1347123200748.jpg' 
chmod 766 '/backup/filipe/tsm/1347123200748.jpg'

AIXでistatコマンドを使用して同じ出力を生成するにはどうすればよいですか?

簡単に言うと、istatから読み取ったファイルにはchmodコマンドとchownコマンドを含む再帰出力が必要です。

ベストアンサー1

を使用しますfindが、必要なコマンドを出力するPerlスクリプトにファイル名を直接渡します。

find /backup/"$INSTANCE"/tsm/* -exec /path/to/perl-script.pl {} +

一重引用符を含むファイル名に注意してください。一重引用符を含むように印刷されたファイル名を修正しました。

パルスクリップ.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", $s[4], $s[5], $filename, ($s[2] & 07777), $filename;
}

uidとgidの代わりにテキストユーザーとグループ名を好む場合は、get *ルックアップ機能を使用してください。

...
  printf "chown %s:%s '%s'\nchmod %04o '%s'\n", (getpwuid($s[4]))[0], (getgrgid($s[5]))[0], $filename, ($s[2] & 07777), $filename;
...

出力例:

chown 1000:1001 '/backup/myinstance/tsm/everyone-file'
chmod 0666 '/backup/myinstance/tsm/everyone-file'
chown 1000:1001 '/backup/myinstance/tsm/file'\''withquote'
chmod 0644 '/backup/myinstance/tsm/file'\''withquote'
chown 1000:1001 '/backup/myinstance/tsm/perl-script.pl'
chmod 0755 '/backup/myinstance/tsm/perl-script.pl'
chown 1000:1001 '/backup/myinstance/tsm/secure-file'
chmod 0600 '/backup/myinstance/tsm/secure-file'
chown 1000:1001 '/backup/myinstance/tsm/setuid-file'
chmod 4755 '/backup/myinstance/tsm/setuid-file'
chown 1000:1001 '/backup/myinstance/tsm/some-dir'
chmod 0755 '/backup/myinstance/tsm/some-dir'

おすすめ記事