bash script - sftpbatchfile - stop on failure


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script - sftpbatchfile - stop on failure
# 15  
Old 04-04-2012
Quote:
Originally Posted by CarloM
Just to clarify, sftp -b isn't aborting on a failed put either?
thats the weird thing, it is failing on a put. But not on any local command (preceeded by !)
# 16  
Old 04-04-2012
I think that's expected behaviour - the built-ins abort, but shell can do whatever.

Your issue then is just that you don't know what (local) unlinks failed? Couldn't you create a list of the files transferred and just check which ones still exist?
# 17  
Old 04-04-2012
Quote:
Originally Posted by CarloM
I think that's expected behaviour - the built-ins abort, but shell can do whatever.

Your issue then is just that you don't know what (local) unlinks failed? Couldn't you create a list of the files transferred and just check which ones still exist?
Yes that was also my thought :-)
but my boss shot the idea for following reason.
how will you know when the echo file > smth has worked or not :s
answer is, you won't

he's kind of a nitpicker :-)
# 18  
Old 04-04-2012
Quote:
Originally Posted by Kerberos
how will you know when the echo file > smth has worked or not :s
Do you need to?

You already know which files you're attempting to transfer (ls -tr $tbtsftp > listoffiles.txt). Can you check which files actually transferred via increasing sftp's log level and saving the output somewhere? (I'm not sure how much it actually outputs in batch mode)
# 19  
Old 04-04-2012
Quote:
Originally Posted by CarloM
Do you need to?

You already know which files you're attempting to transfer (ls -tr $tbtsftp > listoffiles.txt). Can you check which files actually transferred via increasing sftp's log level and saving the output somewhere? (I'm not sure how much it actually outputs in batch mode)

Yes i know that, and i know i could be able to write a list directly after the transfer as follows
Code:
sftp> put $file
sftp> echo $file >> somecheckfile

but my boss won't allow me to do it like that since your suggestion is 2 much manual work when you have a list of 10000+ files
and my example is not 100% failsave (this is farfetched but if the echo ... fails in my example, you are going to send this file again next run (since it wont be in the list for files 2 be deleted)

for today i am quitting, time to get home.
i'll be back here tomorrow.
Any suggestions are welcome
# 20  
Old 04-04-2012
I think you missed my point. I was suggesting something like:

Code:
ls -tr $tbtsftp > listoffiles.txt

for FILE in `cat listoffiles.txt`; do
    echo "cd "$remotepath_VAN >> $commandlist
    echo "put "$FILE >> $commandlist
done

echo
echo "Executing commandlist over sftp"
echo    
sftp -vvv $sftplogon@$sftpserver -b $commandlist 2>&1 > somelogfile.txt

And then compare listoffiles.txt (or $commandlist, for that matter) to somelogfile.txt using an awk script or whatever. No "!echo"s in the batchfile, or manually - somelogfile.txt is just SFTP's own "Uploading /tmp/x.sh to /tmp/nosuchdir/y.sh", "Couldn't get handle: No such file or directory", etc.

BUT - I'm not sure exactly what SFTP itself logs in batchmode, and I don't have any keyed machines to check with atm. So it might not be feasible.

Last edited by CarloM; 04-04-2012 at 12:37 PM..
# 21  
Old 04-04-2012
scp should also be available, if that helps.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Bash variable assignment failure/unary operator expected

I have a little code block (executing on AIX 7.1) that I cannot understand why the NOTFREE=0 does not appear to be assigned even though it goes through that block. This causes a unary operator issue. #!/bin/bash PLATFORM="AIX" NEEDSPC=3000 set -x if ; then lsvg | grep -v rootvg | while... (6 Replies)
Discussion started by: port43
6 Replies

3. Debian

Bash script to STOP installation 'if' a file exists...

Hey all, Here's my dilemma: 1. I'm a newbie at scripting! 2. I need to create a script that checks: If a file size is equal to zero, then stop the installation. Is there a way to do this or am I wasting my time??? Thanx in advance! :b: (2 Replies)
Discussion started by: thazsar
2 Replies

4. UNIX for Dummies Questions & Answers

boot up failure unix sco after power failure

hi power went out. next day unix sco wont boot up error code 303. any help appreciated as we are clueless. (11 Replies)
Discussion started by: fredthayer
11 Replies

5. Shell Programming and Scripting

Stop child script by stoping parent script

Hi everyone, I have this problem with a script I'm writting. I want to execute a code running in the background several times through a script. I am writting it like that parent_script for a in 1 2 3 4 5 do exec test -n $a done What I want to do is when parent_script is killed,... (0 Replies)
Discussion started by: geovas
0 Replies

6. Shell Programming and Scripting

How to stop a script running in remote server from local script

Hi, I have googled for quite some time and couldn't able to get what exactly I am looking for.. My query is "how to stop a shell script which is running inside a remote server, using a script"??? can any one give some suggestions to sort this out. (1 Reply)
Discussion started by: mannepalli
1 Replies

7. UNIX for Dummies Questions & Answers

Anyone know?: How the 'for'-loop could stop working in interactive bash shell?!

It is happening with my sessions already second time: a 'for'-loop for some reason stop to work as expected. That means or it is looping without exitting, or it is not loop even once. Here example of my try when it is not processing even one loop. You can see, I start new subshell and... (14 Replies)
Discussion started by: alex_5161
14 Replies

8. Shell Programming and Scripting

script don't stop

Hello everybody! I am new to this and I am trying to change a script in an open source program that plots some offset vectors and then calls a postscript viewer. I have commented away the call for the postscript viewer but somehow the script doesn't return to the shell prompt. I cant figure out... (3 Replies)
Discussion started by: larne
3 Replies

9. UNIX for Dummies Questions & Answers

Stop a shell script

Hi, I am writing a bash shell script. How can I tell it to stop. For example, I would like to have something similar to the following: mike=1 if ; then STOP THE SCRIPT fi (3 Replies)
Discussion started by: msb65
3 Replies

10. Shell Programming and Scripting

Script does not stop when doing a read

Hi Folks, I have been trying to create a script wherein after it reads a certain number of data, it will pause and ask the user if he wants to continue or not. However, it seems that when it is supposed to read the user's answer, the script will go into a loop. What is wrong with my script here?... (7 Replies)
Discussion started by: rooseter
7 Replies
Login or Register to Ask a Question