坐等高手写shell脚本
发布网友
发布时间:2023-05-19 01:26
我来回答
共2个回答
热心网友
时间:2023-10-13 06:50
#!perl -w
use strict;
my @files = sort{-s $a<=> -s $b}glob"*.tar";
print "No such file" if @files==0;
&check_size(\@files);
&check_date(\@files);
sub check_size{
my $ref = shift ;
my @sizes =map{-s}@$ref;
for my $i(1..$#sizes){
print "file size not suitable" if $sizes[0]/$i !=1.8;
}
}
sub check_date{
my $ref = shift;
my @ctimes =map{(stat $_)[10]}@$ref;
my $cur_time=localtime;
for (@ctimes){
print "Time not suitable!" if $_ != $cur_time;
}
}
热心网友
时间:2023-10-13 06:50
dt=`date | awk '{print $2" "$3}'`
rsh aaaa1 ls -l /home/posftp/price/*.tar | awk 'BEGIN{
err=0
derr=0
ferr=0
}
{
if($0~/No such file/)err=1
if($6" "$7!="'"$dt"'")derr=1
a[NR]=$5
if(NR>1&&$5*1.8>a[1])ferr=1
}
END{
if(err>0)print "文件不存在"
if(derr>0)print "日期不对"
if(ferr>0)print "打包大小不对"
}'