元質問者の佐々木です。
太田様、日下部様、松田様、さっそくのreply
有難う御座います。
xargsを使わない方法については、僕も本MLで見ていたので、xargsをもちいたのですが。
matsuda> 元のメールに記されていた perl スクリプト内には、原因となるような
matsuda> 怪しげなコードは無いと思います。
matsuda> 他の、メールに示されていない部分の perl スクリプトのどこかに、原
matsuda> 因はないでしょうか。
ぼくも、echo,cat、lsで確認してから行いました。
太田様の御示唆された方法で実験してみました。
結果は以下の通りです。
2点困っているのですが。
(1)PATHが通っているのにコマンドがみつからないといってきます。
(2)引数が、FULL PATHのリスト構造でかえってくることを期待したのですが、すべて連結されています。
ーーーーーsearch.sh---------------------------------------
#!/bin/bash
find /home/ftpuser \( -type f -o -type l \) -name "*" -print \
-exec /usr/local/bin/dbstore.pl {}\;
---------------------------------------------------------------
-------実行結果ーーーーーーーーーーーーーーーーーーーーー
スクリプトは Sun Mar 24 15:29:39 2002
に開始しました[root _at_ localhost /root]# sh /usr/local/bin/search.sh
find: paths must precede expression
Usage: find [path...] [expression]
#
スクリプトは Sun Mar 24 15:31:31 2002
に終了しました
----------------------------------------------------------------
Perlのコードも添付します。
(Oracleにファイルから格納しているだけで、DBI,DBD::Oracle最新版を用いています。
/usr/local/binにインストール前に コマンドらいんから、手でいくつかのファイルを
空白で区切って渡してうまくいったのでインストールしたのですが)
Perlで -dを使ってデバッグしている時に、find出力が連結された文字列になっていたので
あせったのですが。
ーーーーーdbstore.pl---------------------------------------------------
#! /usr/bin/perl -w
use DBI;
$ENV{'ORACLE_HOME'} ='/opt/oracle/product/9.0.1';
$ENV{'NLS_LANG'} ='japanese_japan.ja16euc';
$ENV{'LD_LIBRARY_PATH'} ='/opt/oracle/product/9.0.1/lib';
DBI->trace(3);
$dbh = DBI -> connect('dbi:Oracle:orcl.rms','naokoy','naokoy',
{printError => 0,AutoCommit => 0}) || die("Connect Error");
while ($ARGV = shift(@ARGV)){
$fullpath = $ARGV;
@filenames = split(/\//,$fullpath);
$filename = @filenames[@filenames-1];
$mm = substr($filename,-4,2);
$dd = substr($filename,-2,2);
$date_field = "2002-$mm-$dd";
$work = substr($filename,0,length($filename)-4);
if(substr($work,-3,3) eq "CPU"){ $switch = "CPU"; $machine = substr($work,0,length($work)-3);}
if(substr($work,-5,5) eq "DISKD"){ $switch = "DISKD"; $machine = substr($work,0,length($work)-5);}
if(substr($work,-5,5) eq "DISKW"){ $switch = "DISKW"; $machine = substr($work,0,length($work)-5);}
if(substr($work,-5,5) eq "DISKR"){ $switch = "DISKR"; $machine = substr($work,0,length($work)-5);}
if(substr($work,-5,5) eq "DISKG"){ $switch = "DISKG"; $machine = substr($work,0,length($work)-5);}
if(substr($work,-5,5) eq "DISKK"){ $switch = "DISKK"; $machine = substr($work,0,length($work)-5);}
if(substr($work,-4,4) eq "LANI"){ $switch = "LANI"; $machine = substr($work,0,length($work)-4);}
if ($switch eq "CPU") {
open(FILE,"<$fullpath") || die "Unable to open $ARGV :$!";
$sth = $dbh -> prepare("
insert into CPUTBL (machine,date_field,times,sys,usr,wio,idle) values (?,?,?,?,?,?,?) ");
while (defined($line = <FILE>)) {
@fields = split(/\s+/,$line);
if (($fields[0] ne "SunOS") && ($fields[0] ne "") &&
($fields[0] ne "00:00:00") && ($fields[1] ne "unix") &&
($fields[0] ne "Average")){
$times = $fields[0];
$usr = $fields[1];
$sys = $fields[2];
$wio = $fields[3];
$idle = $fields[4];
$sth -> execute($machine,$date_field,$times,$sys,$usr,
$wio,$idle);
}
}
close FILE;
$dbh -> commit;
unlink($ARGV);
} elsif ($switch eq "DISKD")
{
$sampletime = 0;
open(FILE,"<$fullpath") || die "Unable to open $ARGV :$!";
$sth = $dbh -> prepare("
insert into DISKIOTBL (machine,date_field,times,dev,busy,avque,rw,blks,avwait,avserv) values (?,?,?,?,?,?,?,?,?,?) ");
while (defined($line = <FILE>)) {
@fields = split(" ",$line);
$size = @fields;
if(($fields[0] ne "SunOS") && ($fields[0] ne "")
&& ($fields[1] ne "unix" ) &&($fields[0] ne "00:00:00")
&& ($fields[1] ne "<<State")) {
if(($size == 8) && ($sampletime ne "Average")) {
if ($fields[0] eq "Average" ) {
$sampletime = "Average";
}
$times = $fields[0];
$sampletime = $fields[0];
$dev = $fields[1];
$busy = $fields[2];
$avque =$fields[3];
$rw = $fields[4];
$blks = $fields[5];
$avwait = $fields[6];
$avserv = $fields[7];
$sth -> execute($machine,$date_field,$times,$dev,$busy,
$avque,$rw,$blks,$avwait,$avserv);
}
elsif(($size ==7) && ($sampletime ne "Average")) {
$times = $sampletime;
$dev = $fields[0];
$busy = $fields[1];
$avque = $fields[2];
$rw = $fields[3];
$blks = $fields[4];
$avwait = $fields[5];
$avserv = $fields[6];
$sth -> execute($machine,$date_field,$times,$dev,$busy,
$avque,$rw,$blks,$avwait,$avserv);
}
else {
$sampletime = "Average";
}
}
}
close FILE;
$dbh -> commit;
unlink($ARGV);
} elsif ($switch eq "DISKW"){
open(FILE,"<$fullpath") || die "Unable to open $ARGV :$!";
$sth = $dbh -> prepare("
insert into SWAPTBL (machine,date_field,times,swpin,bswin,swpot,bswot,pswch)
values (?,?,?,?,?,?,?,?) ");
while (defined($line = <FILE>)) {
@fields = split(/\s+/,$line);
if(($fields[0] ne "SunOS") && ($fields[0] ne "")
&& ($fields[1] ne "swpin/s")
&& ($fields[1] ne "unix" ) &&($fields[0] ne "00:00:00")
&& ($fields[1] ne "<<State") &&($fields[0] ne "Average"))
{
$times =$fields[0];
$swpin = $fields[1];
$bswin = $fields[2];
$swpot = $fields[3];
$bswot = $fields[4];
$pswch = $fields[5];
$sth -> execute($machine,$date_field,$times,$swpin,
$bswin,$swpot,$bswot,$pswch);
}
}
close FILE;
$dbh -> commit;
unlink($ARGV);
} elsif ($switch eq "DISKR") {
open(FILE,"<$fullpath") || die "Unable to open $ARGV :$!";
$sth = $dbh -> prepare("
insert into FRSWTBL (machine,date_field,times,swapallocated,freemen,freeswap) values (?,?,?,?,?,?) ");
while (defined($line = <FILE>)) {
@fields = split(/\s+/,$line);
if ($fields[0] eq "total:") {
substr( $fields[1], -1) = "";
$swapsize = $fields[1];
} else { if (($fields[0] ne "SunOS") && ($fields[1] ne "unix") && ($fields[1] ne "freemem") && ($fields[0] ne "Average")) {
$swapallocated = $swapsize;
$times = $fields[0];
$freemen = $fields[1];
$freeswap = $fields[2];
$sth -> execute($machine,$date_field,$times,
$swapallocated,$freemen,$freeswap);
}
}
}
close FILE;
$dbh -> commit;
unlink($ARGV);
} elsif ($switch eq "DISKG") {
open(FILE,"<$fullpath") || die "Unable to open $ARGV :$!";
$sth = $dbh -> prepare("
insert into PGOUTBL (machine,date_field,times,pgout,ppgout,pgfree,pgscan,ufsipf) values (?,?,?,?,?,?,?,?) ");
while (defined($line = <FILE>)) {
@fields = split(/\s+/,$line);
if(($fields[0] ne "SunOS") && ($fields[0] ne "")
&& ($fields[1] ne "pgout/s")
&& ($fields[1] ne "unix" ) &&($fields[0] ne "00:00:00")
&& ($fields[1] ne "<<State") &&($fields[0] ne "Average"))
{
$times =$fields[0];
$pgout = $fields[1];
$ppgout = $fields[2];
$pgfree = $fields[3];
$pgscan = $fields[4];
$ufsipf = $fields[5];
$sth -> execute($machine,$date_field,$times,$pgout,$ppgout,
$pgfree,$pgscan,$ufsipf);
}
}
close FILE;
$dbh -> commit;
unlink($ARGV);
} elsif ($switch eq "DISKK") {
open(FILE,"<$fullpath") || die "Unable to open $ARGV :$!";
$sth = $dbh -> prepare("
insert into DISKTBL (machine,date_field,filesys,capacity,used,avail,usagepercent,mounted_on) values (?,?,?,?,?,?,?,?)
");
while (defined($line = <FILE>)) {
@fields = split(/\s+/,$line);
if (($fields[0] ne "Filesystem") &&($fields[0] ne "/proc") &&
($fields[0] ne "fd") && ($fields[0] ne "swap" )){
$filesys = $fields[0];
$capacity = $fields[1];
$used = $fields[2];
$avail = $fields[3];
substr( $fields[4], -1) = "";
$usagepercent = $fields[4];
$mounted_on = $fields[5];
$sth -> execute($machine,$date_field,$filesys,$capacity,$used,$avail,$usagepercent,$mounted_on);
}
}
close FILE;
$dbh -> commit;
unlink($ARGV);
} else {
open(FILE,"<$fullpath") || die "Unable to open $ARGV :$!";
$sth = $dbh -> prepare("
insert into NETTBL (machine,date_field,Nam,Mtu,NetDest,Addr,
Ipkts,Ierrs,Opkts,Oerrs,Collis,Que)
values (?,?,?,?,?,?,?,?,?,?,?,?) ");
while (defined($line = <FILE>)) {
@fields = split(/\s+/,$line);
if ($fields[0] ne "Name") {
$Nam = $fields[0];
$Mtu = $fields[1];
if ($fields[2] eq "loopback") {
$NetDest = "127.0.0.1";
} else {
$NetDest = $fields[2];
}
$Addr = $fields[3];
$Ipkts = $fields[4];
$Ierrs = $fields[5];
$Opkts = $fields[6];
$Oerrs = $fields[7];
$Collis = $fields[8];
$Que = $fields[9];
$sth -> execute($machine,$date_field,$Nam,$Mtu,
$NetDest,$Addr, $Ipkts,$Ierrs,$Opkts,$Oerrs,$Collis,$Que);
}
}
close FILE;
$dbh -> commit;
unlink($ARGV);
}
}
$dbh -> disconnect;
References:
- [linux-users:92001] Re: [linux-users:92000] Re: shellscriptからPerl scriptへの引数の渡しについて?太田 敏文
- [linux-users:92002] Re: shellscriptからPerl scriptへの引数の渡しについて?KUSAKABE -bourbon!- Toshiaki
- [linux-users:92005] Re: shellscriptからPerl scriptへの引数の渡しについて?MATSUDA Yoh-ichi / 松田陽一
- Prev by Subject: [linux-users:92005] Re: shellscriptからPerl scriptへの引数の渡しについて?
- Next by Subject: [linux-users:92007] Re3: ログインが出来なくなった時
- Previous by thread: [linux-users:92005] Re: shellscriptからPerl scriptへの引数の渡しについて?
- Next by thread: [linux-users:92009] 本多エレクトロン AH-G10 動作報告
- Indexes:[Main][Thread]