Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 05-17-2014, 04:34 PM   #1
LQ Newbie
Registered: Dec 2012
Posts: 7

Rep: Reputation: Disabled
lftp - perform task only if connect successful

I have an lftp script that runs from cron. But I only want mv of files to take place if the connect is successful. So did the mv within the lftp script but the mv takes place even if the login fails. How can I conditionally mv the files ? Here is my script:
lftp -u user,pw -e 'set xfer:clobber yes;
cd /uploads;
lcd /commerce/ediexport;
!mv *.* /commerce/ediftpoutwork;
lcd /commerce/ediftpoutwork;
mput *.*;
!mv *.* /commerce/edioutarchive;
quit;' ip_address

Thanks in advance for any help.
Old 05-18-2014, 04:21 PM   #2
LQ Newbie
Registered: Dec 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
I revised the script this seems to do what I wanted:
# An error exit function

function error_exit
echo "$1" 1>&2
exit 1

cd /commerce/ediexport
mv *.* /commerce/ediftpoutwork || error_exit "No files in ediexport"
lftp -u user,password -e 'set xfer:clobber yes;
cd /uploads;
lcd /commerce/ediftpoutwork;
mput *.* || exit 124;
!mv *.* /commerce/edioutarchive;
exit 120 ;'
echo $STATUS
if [ "$STATUS" = "124" ]; then
echo "files put back to export"
mv /commerce/ediftpoutwork/*.* /commerce/ediexport




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
Sending email after successful lftp mget or mirror chickenshit Linux - Software 1 10-03-2013 07:02 PM
[SOLVED] How to perform var++ task in shell script? antriksh Linux - Newbie 5 01-15-2013 01:51 AM
My ubuntu 10.04 restarts as i perform a certain task adam.athumani Linux - Newbie 1 08-24-2010 08:54 PM
script doesn't perform the same as task done by hand bradvan Linux - Server 2 03-31-2009 11:00 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:02 AM.

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