我想运行linux命令(ps aux --sort -rss | head -n 10)并在邮件中以表格格式显示结果。 有人可以建议。 这是我的剧本。
#!/usr/bin/ksh
current_dir=$(pwd)
script_dir=$(dirname $0)
if [ $script_dir = '.' ]; then
script_dir="$current_dir"
fi
source_dir=$PWD
cd $script_dir
FWK_TIMESTAMP=`date +%Y%m%d_%H:%M:%S`
REPORT_TS=`date -d '1 day ago' +'%m/%d/%Y'`
TILL_DATE=`date +%m/%d/%Y`
#javac -classpath mail1.4.4.jar:activation.jar SendEmail.java
if [ $? -ne 0 ];then
echo javac failed $?
exit 1
fi
outfile=test.txt
rm test.txt
echo "<h1> Top 10 Memory Consumed Processes from $REPORT_TS to $TILL_DATE</h1>" >> $outfile
ps aux --sort -rss | head -n 10 >> $outfile
to='abc@abc.com'
mail_server='-mail.smtp.host abc.com'
param="-to $to $mail_server -from abc@abc.com"
#-mail.debug
java -cp mail1.4.4.jar:activation.jar:. SendEmail $param -subject "Top Memory Consumed Processes" -file test.txt