【发布时间】:2015-06-11 15:17:12
【问题描述】:
我有以下 shell 脚本,它运行一个 SQL 查询和一个将输出作为电子邮件发送的命令。问题是我只能发送 SQL 输出。不是 for 循环的输出。我试图在 for 循环之后给出“EOF”,但随后它给出了语法错误。请让我知道如何通过电子邮件发送这两个输出。
感谢和问候, 阿基尔
#!/bin/bash
source $HOME/.bash_profile
cd /home/cron
wfVAR="red blue green"
echo " " > /home/cron/output.lst
sqlplus -s user/test@DB <<EOF
set linesize 55 pages 500
spool output_temp.lst;
set head off;
select sysdate from dual;
set head on;
spool off;
EOF
for name in ${wfVAR}; do
pmcmd getworkflowdetails -sv REPOSITORY ${name} | grep -e "Workflow:" -e "Workflow run status:" -e "End time:"
done
sed -e 's/ *$//' output_temp.lst > output.lst
cat /home/cron/output.lst | mail -s "Output - `date '+%d-%m-%y'`" akhil@gmail.com
rm output_temp.lst
【问题讨论】:
-
顺便说一句,很少需要
cd进入目录,并且使脚本依赖于调用用户的.bash_profile通常根本不是一个好主意。和以往一样,cat file | mail更好地表达mail <file。 -
您没有创建
output_temp.lst,也没有捕获来自sqlplus或pmcmd的输出。