如何向此脚本添加电子邮件

问题描述 投票:0回答:1

我需要找出如果成功传输文件如何添加电子邮件通知“转移成功”或者如果他们是一个问题“有一个问题”.......我做错了什么...这是传输文件后得到的消息

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

#!/usr/bin/expect<<EOD > output.log      
#
spawn sftp -o Port=22 [email protected]    
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"
"[email protected]"  
else                                                                            
  echo "Success" | mail -s "Transfer Successful"
"[email protected] "                                                                             
fi
linux scripting sftp expect
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.