LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-30-2010, 02:12 PM   #1
josephf
LQ Newbie
 
Registered: Mar 2008
Posts: 4

Rep: Reputation: 0
FTP script help


need help to write a script to ftp a file and get an email confirmation or failure sent out.
 
Old 07-30-2010, 02:17 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

What have you tried and which problems did you encounter? Any details?

We are willing to help, but I don't think you can expect us to deliver a script/program from scratch
 
Old 07-30-2010, 02:27 PM   #3
josephf
LQ Newbie
 
Registered: Mar 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Have the ftp working need to know how to send an email to let me know if it succeeded or not. Here is the script so far:
#!/bin/ksh
HOST='xxx.xxx.xxx.xxx'
USER='username'
PASSWD='passwd'
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd /directory

prompt
mput file.txt

quit
END_SCRIPT
exit 0
 
Old 07-30-2010, 02:28 PM   #4
josephf
LQ Newbie
 
Registered: Mar 2008
Posts: 4

Original Poster
Rep: Reputation: 0
I would like to send email using mutt as well, if possible.
 
Old 07-30-2010, 03:25 PM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

I don't use mutt, but this will give you an idea (I hope):
Code:
#!/bin/bash

HOST='127.0.0.1'
USER='username'
PASSWD='password'
FILE='filename'
TARGDIR='targetdirectory'
STATUSFILE="/tmp/ftpStatus.out"
MAILUSER="joe.doe@home.nl"

/usr/bin/ftp -in $HOST 1>/dev/null 2>$STATUSFILE <<END_SCRIPT
user $USER $PASSWD
cd $TARGDIR
put $FILE
bye
END_SCRIPT

if [[ -s $STATUSFILE ]]
then
  # ftp has failed
  echo "fail code goes here"
#  cat $STATUSFILE | mailx -s "ftp transfer has failed!" $MAILUSER
else
  # ftp succeeded
  echo "succeed code goes here"
#  mailx -s "ftp transfer has succeeded!" $MAILUSER
fi

rm $STATUSFILE
Both mailx commands are commented out, if you have mailx on your system it should work and you can remove the hash.

Hope this helps.
 
Old 07-30-2010, 03:29 PM   #6
josephf
LQ Newbie
 
Registered: Mar 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks, I'll test it out and let you know how it goes.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script problem with ftp session exiting the script early edomingox Programming 5 02-23-2010 06:39 AM
FTP script quest4net Linux - Newbie 4 04-08-2008 02:34 PM
Urgent Help: Perl FTP Script Using NET::FTP xboxter Programming 8 05-16-2005 07:57 PM
Ftp script scialom Linux - Software 2 05-04-2004 04:03 PM
ftp script dlm4444 Linux - Networking 5 02-11-2004 12:41 AM


All times are GMT -5. The time now is 03:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration