LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-13-2009, 05:06 PM   #1
windstory
Member
 
Registered: Nov 2008
Posts: 486

Rep: Reputation: 36
if failed ncftpput, skip next command


I have this backup script.
Code:
#!/bin/bash

ncftpput -u my-id -p my-pass my-server /_backup/backup /backup/_work/*
rm -rf /backup/_work/*
This script has a problem.
If failed sending files, it deletes all files.

Please make this script if failed sending files, skip next command.
 
Old 09-13-2009, 05:19 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Assuming ncftpput sets a non-zero exit status on failure
Code:
ncftpput -u my-id -p my-pass my-server /_backup/backup /backup/_work/* && rm -rf /backup/_work/*
 
Old 09-17-2009, 01:55 AM   #3
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by catkin View Post
Assuming ncftpput sets a non-zero exit status on failure
Code:
ncftpput -u my-id -p my-pass my-server /_backup/backup /backup/_work/* && rm -rf /backup/_work/*
catkin/Is this code for "failed and stop"?
I mean "if failed ncftpput, skip next command or stop".
 
Old 09-17-2009, 08:15 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,294

Rep: Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358
'&&' is logical 'and' : http://www.arachnoid.com/linux/shell_programming.html
 
Old 09-18-2009, 04:47 AM   #5
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by chrism01 View Post
chrism01/ Thank you for your kind information.
 
Old 09-18-2009, 05:19 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by windstory View Post
catkin/Is this code for "failed and stop"?
I mean "if failed ncftpput, skip next command or stop".
No -- it just skips the next command (the rm) as you requested. If you want to be more sophisticated
Code:
if ncftpput -u my-id -p my-pass my-server /_backup/backup /backup/_work/* ; then
    rm -rf /backup/_work/*
    <whatever you like>
else
    <whatever you like>
fi
 
Old 09-18-2009, 05:24 AM   #7
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by windstory View Post
I have this backup script.
Code:
#!/bin/bash

ncftpput -u my-id -p my-pass my-server /_backup/backup /backup/_work/*
rm -rf /backup/_work/*
This script has a problem.
If failed sending files, it deletes all files.

Please make this script if failed sending files, skip next command.
Code:
if ncftpput -u my-id -p my-pass my-server /_backup/backup /backup/_work/*
then
   rm -rf /backup/_work/*
fi
This logic depends on ncftpput providing a false result on failure -- not all programs set set up to do this.

By the way -- you should be using scp or sftp for better reliability and security in this network transaction. ncftpput is no more secure than ftp is.
 
Old 09-19-2009, 02:38 AM   #8
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by lutusp View Post
Code:
if ncftpput -u my-id -p my-pass my-server /_backup/backup /backup/_work/*
then
   rm -rf /backup/_work/*
fi
This logic depends on ncftpput providing a false result on failure -- not all programs set set up to do this.

By the way -- you should be using scp or sftp for better reliability and security in this network transaction. ncftpput is no more secure than ftp is.
lutusp/ Thanks a lot for your kind advise.

I heard scp or sftp, but it's difficult.
At this time I'll study it.

Nowadays, linux is getting harder and harder.
 
  


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
Bind9: NDC command failed : rndc: connect failed: connection refused Boudewijn Linux - Networking 19 01-02-2014 07:19 AM
Command failed: device-mapper: reload ioctl failed: Invalid argument azza Programming 2 01-10-2011 03:16 AM
command to skip enter current password ssy68 Linux - Newbie 6 02-15-2008 12:52 AM
Command to copy files/folders but skip bad/corrupt files?? leemoreau Linux - Newbie 2 04-02-2007 02:27 PM
ncftpput and bookmarks slimjim Linux - Software 1 05-23-2004 01:03 PM


All times are GMT -5. The time now is 03:14 AM.

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