This script shows you how to automate FTPing to remote server.
First of all create a text file, lets name it as automate.ftp
put the following commands into it.
#############################################
open hostname
user username password
cd desireddirectory
lcd localdirectory
bin
put sourcefile destinationfile
quit
#############################################
Text in bold are variables (It can be changed according your requirements)
use the command below to automatically send the files you put in the above automate.ftp
ftp -i -n < /automate.ftp
You can schedule this in cron if you need it regularly. You can also write a script to generate the above file if your file names changes. A typical expample is below.
Contents of sendftp.ksh which can be scheduled in the cron for executing regularly.
#############################################
DATE=`date +"%Y%m%d.%H%M%S"`
echo "open hostname" > /automate.ftp
echo "user username password" >> /automate.ftp
echo "cd destinationdirectory" >> /automate.ftp
echo "lcd localdirectory" >> /automate.ftp
echo "bin" >> /automate.ftp
echo "put "report.txt `hostname`.$DATE.report.txt >> /automate.ftp
echo "quit" >> /automate.ftp
ftp -i -n < /automate.ftp ############################################# Note: Here report.txt is the source file and destination file would be named as hostname with current date prefixed with report.txt
Showing posts with label ksh. Show all posts
Showing posts with label ksh. Show all posts
Wednesday, February 06, 2008
Simple ksh script to sent a mail using SMTP server.
This script can send mail using SMTP server. However limitation is that, SMTP server should be open for all. i.e NO authentication support.
You can change the data fields as you like, but not the order of execution. (This is strict as the script is supplying arguements for the SMTP protocol which is not very flexible. If you add space in the Keywords, it may not work.) In other words, you can only change the fields marked bold italic
#!/usr/bin/ksh
MAILADDR=user@recipient.com
TEMPFILE=/your/data/file
(sleep 5
echo EHLO
sleep 5
echo MAIL FROM: user@yourdomain.com
sleep 5
echo RCPT TO: $MAILADDR
sleep 5
echo DATA
sleep 5
echo From: user@yourdomain.com
echo To: $MAILADDR
echo subject: Daily report
echo
echo “”
cat $TEMPFILE
echo “”
echo
sleep 5
echo .
sleep 5
echo QUIT
sleep 5) | telnet www.mailserver.com 25
You may be interested to take a look at unix related links
You can change the data fields as you like, but not the order of execution. (This is strict as the script is supplying arguements for the SMTP protocol which is not very flexible. If you add space in the Keywords, it may not work.) In other words, you can only change the fields marked bold italic
#!/usr/bin/ksh
MAILADDR=user@recipient.com
TEMPFILE=/your/data/file
(sleep 5
echo EHLO
sleep 5
echo MAIL FROM: user@yourdomain.com
sleep 5
echo RCPT TO: $MAILADDR
sleep 5
echo DATA
sleep 5
echo From: user@yourdomain.com
echo To: $MAILADDR
echo subject: Daily report
echo
echo “”
cat $TEMPFILE
echo “”
echo
sleep 5
echo .
sleep 5
echo QUIT
sleep 5) | telnet www.mailserver.com 25
You may be interested to take a look at unix related links
Labels:
ksh,
mail script,
SMTP,
telnet,
Unix