如何将电子邮件添加到此脚本

时间:2019-04-04 20:24:13

标签: linux scripting sftp expect

如果文件已成功传输“传输成功”,或者如果它们存在问题“存在问题”,我需要找出如何添加电子邮件通知的方式。 。这是文件传输后收到的消息

sftp> invalid command name "EOD"  
while executing               
"EOD"                             

#!/usr/bin/expect<<EOD > output.log      
#
spawn sftp -o Port=22 HOSTDNS@HOSTDNS.com    
expect "assword:"                        
send "password\r"                         
expect "sftp>"                           
send "lcd /usr/lib/basic/TEMP/TRANS\r"   
expect "sftp>"                           
send "cd /home/denni/STORAGE\r"          
expect "sftp>"                           
send "mput *\r"                          
expect "sftp>"                           
send "bye\r"                             
EOD                                                                             
RC=$?                                                                           
if [[ ${RC} -ne 0 ]]; then                                                      
  cat output.log | mail -s "Errors Received"
"username@somewhere.com"  
else                                                                            
  echo "Success" | mail -s "Transfer Successful"
"username@somewhere.com "                                                                             
fi

1 个答案:

答案 0 :(得分:0)

确保脚本顶部有bash,并且EOD后面没有空格。这对我有用。请注意,我删除了#!从期望的二进制开始。

#!/bin/bash

/usr/bin/expect <<EOD > output.log
spawn sftp username@hostname
expect "assword:"
send "password\r"
expect "sftp>"
send "ls\r"
expect "sftp>"
send "bye\r"
EOD