我有一个shell脚本makecsv.sh
,它可以单独运行,但在Perl中调用时会失败。
这是我从Perl脚本运行makecsv.sh
时给出的消息:
fr call
Source file does not exist
Usage: fr -s <source_file> -o <output_file>
-s <source_file> - Input file which has Counter Information
-o <output_file> - Comma separated output file
third move
mv: cannot access /home/ateam/.../SAM5_01-05- 2016_11:07:29.csv
/home/ateam/.../SAM5_01-05-2016_11:07:29.xcm: No such file or directory
cp: cannot access /home/ateam/.../SAMlog/ /home/ateam/.../SAM5_01-05-2016_11:07:29.csv
md5sum: /home/ateam/.../SAM5_01-05-2016_11:07:29.csv: No such file or directory
/home/ateam/.../SAM5_01-05-2016_11:07:29.csv: No such file or directory
这是包含fr
节点
drwxrwxr-x 4 ateam ateam 4096 May 1 11:12 ./
drwxr-xr-x 3 ateam ateam 4096 Mar 17 11:18 ../
lrwxrwxrwx 1 ateam ateam 7 Mar 12 19:13 c -> counter*
-rwxrwxr-x 1 ateam ateam 1974 Mar 12 19:04 counter*
-rwxrwxr-x 1 ateam ateam 134 Mar 21 11:22 e*
-rw-rw-r-- 1 ateam ateam 25152020 Mar 21 11:22 enb
-rw-rw-r-- 1 ateam ateam 1880872 Mar 21 11:21 enb283.xml
-rwxrwxr-x 1 ateam ateam 811 Mar 28 11:59 expftp*
lrwxrwxrwx 1 ateam ateam 7 Mar 17 11:23 fr -> fruinfo*
-rw-rw-r-- 1 ateam ateam 75753 Mar 22 13:07 fru_0322.xls
-rwxrwxr-x 1 ateam ateam 2878 Apr 21 22:16 fruinfo*
drwxrwxr-x 2 ateam ateam 4096 May 1 11:12 md5sum/
...
我不明白这个目录项是什么
lrwxrwxrwx 1 ateam ateam 7 Mar 17 11:23 fr -> fruinfo*
更多信息。
在shell脚本中,对fr
的调用如下所示
fr -s "$newfile" -o "$frufile"
和shebang线是这个
#!/bin/bash
在Perl文件中,shell脚本就像这样调用
my $cmd = qq(bash makecsv.sh $initdir$sam.xcm $csvdest);
print $cmd, "\n";
#system 'bash makecsv.sh ${initdir}${sam}.xcm $csvdest';
system($cmd);
如果有帮助的话,上面的变量都会加倍引用。
答案 0 :(得分:0)
从此致电系统&#39;在Perl脚本中,我不必要地添加了$ initdir变量。
my $cmd = qq(bash makecsv.sh $initdir$sam.xcm $csvdest);
print $cmd, "\n";
system($cmd);
我将初始化$ cmd的行更改为this并且它有效:
my $cmd = qq(bash makecsv.sh $sam.xcm $csvdest);
现在,对于makecsv.sh来说,程序看起来像这样。我故意缩短了目录。
#!/bin/bash
#/bin/env sh
# makecsv.sh /path/to/source/ /path/to/destination/
SRC=$1
DST=$2
# separate filename from ext
filename="${SRC%.*}"
extension="${SRC##*.}"
NOW="$(date +'%d-%m-%Y_%T')"
newfile="${filename}_${NOW}.$extension"
mv -f "$SRC" "$newfile"
mv -f "$newfile" "$DST"
#mv -f "${filename}_${NOW}.$extension" "$DST"
cd $DST
# rename file with .csv ext (without the .xcm)
noExt="${newfile%.*}"
frufile="${noExt}.csv"
fr -s "$newfile" -o "$frufile"
mv "$frufile" "/home/.../SAMlog"
rm "$newfile"
# remove files older than 90 days
find /home/..../SAMlog -type f -mtime +90 -exec rm {} \;
# create a md5sum stored in a file for frufile
cp /home/.../SAMlog/"$frufile" "${DST}/md5sum"
cd "${DST}/md5sum"
# create a fingerprint for the new frufile
md5file="${noExt}.md5"
touch "$md5file"
md5sum "$frufile" > "$md5file"
rm "$frufile"
# check for md5sum files older than 1 day and delete them
# only ever need to keep the sums of the current day and the previous one for cmp
find /home/.../md5sum -type f -mtime +1 -exec rm {} \;
这段代码永远不应该接受一个完整的路径,虽然我在顶部写道它应该。所以,我会改变它以接受完整的路径。