ディレクトリ内の3つのファイルをチェックし、それらの行の数を取得し、行が存在する場合はメールを送信するスクリプトを作成しています。これらのファイルのいずれかに数がある場合は1つのメールのみを送信する必要があり、最終的に3つのメールを送信します。
例の場合 私はこれらのファイルを持っています
process_date.txt
thread_date.txt
child_date.txt
Iamは次のようなことをしています
$1= process_date.txt
$2= thread_date.txt
$3= child_date.txt
if [ -f $1 ]
then
count1=`wc-l < $1`
if $count1 -ne 0 then mailx abc.com
fi
fi
if [ -f $2 ]
then
count2=`wc-l < $2`
if $count2 -ne 0 then mailx abc.com
fi
fi
if [ -f $3 ]
then
count3=`wc-l < $3`
if $count3 -ne 0 then mailx abc.com
fi
fi
次のように、スクリプトを関数でラップし、return
毎回コマンドを使用できますmailx
。
send_one_mail() {
if [ -f "$1" ]
then
count1=$(wc -l < "$1")
if [ $count1 -ne 0 ]
then
mailx abc.com
return
fi
fi
# etc. for other conditions
}
send_one_mail process_date.txt thread_date.txt child_date.txt
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加