Mailing Script

Hi,

I am totally New to This Scripting Area.We have developed some reports in Bo and User need those reports to be sent through Unix Server (SFTP).

Can any one provide me script for transfering File from one location to other with the requirement like if that file fails to reach destination then we should receive mail like "file not reached" and if successfully reached we shud get mail like "file reached successfully".

Thanks And Regards
Sashath

I guess you are not looking for SFTP , and not SMTP [for mailing].

Here is a sample SFTP program

 
sftp username/password@server_name  <<EOF
lcd local_directory
cd remote_directory
put file_name
bye
EOF
echo $?  # Will be zero on a successful transfer

If you are using a passwordless authentication, you can do something like

 
sftp -oIdentityFile=private_key -oPort=port_num user@server_name <<EOF
lcd local_directory
cd remote_directory
put file_name
bye
EOF
echo $?  # Will be zero on a successful transfer

Also, you can use scp for the same purpose

1 Like

Thanks A Lot for your reply..

But I also need like Mail shud be sent regarding File transfer status...

Many Thanks
Sashath

---------- Post updated at 05:46 AM ---------- Previous update was at 04:11 AM ----------

Can any one help you How to Receive mails if file has recahed successfully ...

Add this at the end of dennis.jacob's proposed code.

 
[ $? -eq 0 ] && mail -s "File Transfer is OK" abc@gmail.com
1 Like

This is just to give you a clear understanding of how ftp will do in failed cases ....

ftp copy will not give you an error status of "1" even when it is failed , because the last command that is executed will be 'bye' , so "$?" will always return a "0"( i.e status 'success') .

By which means irrespective of the file transfer you will get the return status as success always which may mislead you .

1 Like