Shell脚本使用电子邮件ID向用户发送通知,以从数据库中获取通知

时间:2019-02-21 11:23:01

标签: shell

有人可以用shell脚本帮我吗-在某种情况下从oracle数据库上的用户表中获取cntct_email并向所有这些用户发送电子邮件通知。

user_list1=$(echo -ne "set heading OFF\n select cntct_email from user where 
xprtn_dt = SYSDATE - 60;" | sqlplus -s ${ORA_UID_PSWD})
printf "Hi,\nFYI Your password is expired 60 days ago. Please login and get it 
reset..\n\nThanks,\n Team" |mailx -s "Password expired" $user_list1

我尝试使用上面的代码,但是没有用

1 个答案:

答案 0 :(得分:0)

您可以尝试以下操作:

query=$(sqlplus -s ${ORA_UID_PSWD} << 'EOF'
set heading OFF
select cntct_email from user where xprtn_dt = SYSDATE - 60;
EOF
)
user_list1=$(echo "$query" | tr '\n' ',')
echo -e "Hi,\nFYI Your password is expired 60 days ago. Please login and get it reset..\n\nThanks,\n Team" |mailx -s "Password expired" $user_list1