bash script - sftpbatchfile - stop on failure


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script - sftpbatchfile - stop on failure
# 22  
Old 04-05-2012
Quote:
Originally Posted by Corona688
scp should also be available, if that helps.

i know, but our login is only allowed through sftp, all other protocols are blocked. :-)

(if this many experts don't know the answer, i'm feeling better already about not knowing it myself Smilie )

*** edit ***
my bad, it is not the protocol which was blocked. It is the user we got to log on is restricted to have only sftp acces :-)

Last edited by Kerberos; 04-05-2012 at 11:42 AM..
# 23  
Old 04-05-2012
Okay, possibly an outlandish punt, but could you get all the files you want to send into a single compressed tar file, delete those from local disk and when you are happy that is complete, binary SFTP the compressed tar file? Of course the other end would have to know that's what you are doing and be ready to uncompress and extract.

Just trying to think of alternatives. Sorry if it's no use. Smilie




Robin
Liverpool/Blackburn
UK
# 24  
Old 04-05-2012
He has no ssh access, hence no way to extract it on the far end.
# 25  
Old 04-05-2012
Quote:
Originally Posted by Kerberos
i know, but our login is only allowed through sftp, all other protocols are blocked. :-)
They are the same protocol, literally. They use the same port and same authentication system, and do identical things -- transfer files -- in an identical way.

It's simple enough to block shell logins, but blocking scp without blocking sftp? Strange and unlikely. If anything, they're more likely to have scp than sftp, sftp being kind of optional.

Last edited by Corona688; 04-05-2012 at 11:26 AM..
# 26  
Old 04-05-2012
I know that there is a no SSH to drive it himself, however the other end is moving the files off as they arrive, so perhaps that can be altered to expect a compressed tar file, was my thought.

It depends what the receiving company is prepared to do after they "fixed" a working system that allowed Kerberos to send single files and therefore delete single files in a controlled way. Unfortunately now you want to open a single connection and move all of the files.


Another alternate would be to fire in something like into the sftp batch file:-
Code:
put localfile1 remotefile1
!rm localfile1 || kill `ps -f|grep sft[p]|cut -f3 -d " "`
put localfile2 remotefile2
!rm localfile2 || kill `ps -f|grep sft[p]|cut -f3 -d " "`
put localfile3 remotefile3
!rm localfile3 || kill `ps -f|grep sft[p]|cut -f3 -d " "`

This will cause sftp to get a kill -15 and exit with $?=1 You can then pick that up with your shell script.


Does that help?



Robin
Liverpool/Blackburn
UK
This User Gave Thanks to rbatte1 For This Post:
# 27  
Old 04-05-2012
Quote:
Originally Posted by rbatte1
I know that there is a no SSH to drive it himself, however the other end is moving the files off as they arrive, so perhaps that can be altered to expect a compressed tar file, was my thought.

It depends what the receiving company is prepared to do after they "fixed" a working system that allowed Kerberos to send single files and therefore delete single files in a controlled way. Unfortunately now you want to open a single connection and move all of the files.


Another alternate would be to fire in something like into the sftp batch file:-
Code:
put localfile1 remotefile1
!rm localfile1 || kill `ps -f|grep sft[p]|cut -f3 -d " "`
put localfile2 remotefile2
!rm localfile2 || kill `ps -f|grep sft[p]|cut -f3 -d " "`
put localfile3 remotefile3
!rm localfile3 || kill `ps -f|grep sft[p]|cut -f3 -d " "`

This will cause sftp to get a kill -15 and exit with $?=1 You can then pick that up with your shell script.
i will try this one.

at the moment i had this

Code:
echo "Start of actual procedure"
echo "========================="
echo "Searching files other then ."$filetype" in "$tbtsftp" and move them to /tmp/invalid_filetype"
mkdir -p /tmp/invalid_filetype
find $tbtsftp -type f -not -name "*."$filetype -exec mv {} /tmp/invalid_filetype/ \;
echo
echo
echo "Deleting old commandlist if exists"
echo > $commandlist
echo
echo "Deleting old checkfile"
echo > $SFTPCHECK_PUT_RM
echo
echo "Creating commandlist"
echo
for FILE in `ls -tr $tbtsftp`; do
        echo "put "$FILE
        echo "cd "$remotepath_VAN >> $commandlist
        echo "put "$FILE >> $commandlist
        echo "!rm -f "$FILE
        echo "!rm -f "$FILE" | echo $? >> "$SFTPCHECK_PUT_RM  >> $commandlist
        
done

but appearantly he wont display echo $? (how it should) in my commandlist but echo 0 :s
# 28  
Old 04-05-2012
What is the purpose of the pipe there? echo reads nothing from standard input.

Did you perhaps mean || ? remove the file and, on failure, print the error code?
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