How to check the status of sftp connection is successful or not in Linux?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check the status of sftp connection is successful or not in Linux?
# 1  
Old 02-23-2016
How to check the status of sftp connection is successful or not in Linux?

Hi All,

We are working on linux with putty terminal for file transferring using SFTP server...
here we want to know /We have Urgent Requirement
If SFTP connection is successfull then we should get .txt log file in target locaton as "Success/Failure"


Please provide batch script for above requirement...
'it's very urgent..

Thanks,
Sravan

---------- Post updated at 01:46 AM ---------- Previous update was at 12:31 AM ----------

Please provide script for above requirement..

It's very urgent for us

Thanks,
Sravan
# 2  
Old 02-23-2016
There are specific threads for urgent matters.
We're not a place to do your work, so you get the salary.

As it is urgent, and according to the forum rules, let me ask this first - as you had 11 hrs time:
  1. What have you tried so far?
  2. Where are you stuck, and why?
  3. Is it homework (class/course)?

Thank you
# 3  
Old 02-23-2016
We have code as per my requirement of algorithm ....

Once SFTP server connection successful ...

then after few days i want to know the status of SFTP server connection success/failure...

In my google search
I found Below script...

Code:
STATUS=`ftp -nv $HOST <<EOF
<...ftp commands...>
EOF

if [ "$(echo $STATUS | grep -c 226)" -ge 1 ]; then echo "Success"; fi

My question regarding above script...

is it working or not..?
how can we know the status of SFTP connection ..

we are don't want try with unnecessary code...if the code working well we need to implement...

because we are in production side...in my project level...

we need accurate output script..


Thnaks,
Sravan

Last edited by Don Cragun; 02-23-2016 at 05:05 AM.. Reason: Add CODE tags.
# 4  
Old 02-23-2016
Please use code tags as required by the forums rules you have agreed to.
Again, what have YOU tried?

But ok, according to the information you share:
That should work, why shouldnt it?

For any further information,
please wait until my magic ball is back from repair,
or provide the required information, you know the data of your project required for the script, dont you?

Try:
Code:
echo $STATUS

Probably you will need to parse that output for better details.

hth
# 5  
Old 02-23-2016
It is pretty safe to say that a shell script with mismatched backquotes will not work.

If you had matched backquotes, without knowing what ftp commands you're running on the server named by the expansion of $HOST, we have absolutely no way to guess at whether or not one or more occurrences of the string 226 will appear in the output of your unspecified ftp commands.

You talk about SFTP and you call ftp in your script. We assume that you know that there is no SFTP command, that sftp and ftp are similar but different, and that copying a script from a Google search without knowing that you are trying to do EXACTLY the same thing described in that search means that you should be prepared to adapt that script to match your environment and requirements.

Since you haven't told us what constitutes successful completion of your stfp commands, we have absolutely no way to guess whether or not the unspecified ftp commands in your script have succeeded or not. In many cases you could check the exit status of an ftp or sftp command to determine whether or not it succeeded, but again we do not know what you're trying to do.

A very good way to determine whether or not some code will work is to run that code and see if it works. Run it with tracing turned on and learn more about what each step is doing. Check the exit status of every command you're running and learn more about what each command is doing. You make it sound as though you haven't tried running any code. We can tell you that unless you try running code in your environment, we will never be able to reliably predict whether or not any code will work on a network of machines about which we know nothing.
# 6  
Old 02-23-2016
Don Cragun,

Please let me, actually i want to know how to check the status of sftp connection is successful or not in Linux?...

i don't the how to check status...
please let me shell script....

Thanks,
Sravan
# 7  
Old 02-23-2016
Try this:
Code:
<any valid command>
echo $?
[ condition ]
echo $?

There is your 'successfull' (0) or not (1), in case of bash that is.

hth
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script verify connection to Oracle if not successful

i have a script that connects to the oracle database and executes the query statements. it works fine and i would like to add some message to check if the connection to oracle is not successful. basically this is the code snippet: #!/bin/sh ... ... ... sqlplus -s username/password@dbName... (2 Replies)
Discussion started by: wtolentino
2 Replies

2. UNIX for Beginners Questions & Answers

Sftp connection not establishing from Linux to DataPower

Hi Everyone, I am trying to send files from Linux to DataPower server using public key based authentication but it's not working as expected and every-time password expecting for sftp transfer. Can someone please help on this? Steps I fallowed: Created keys pair at source server... (4 Replies)
Discussion started by: renukeswar
4 Replies

3. UNIX for Beginners Questions & Answers

Automation script for email alert when a job get complete with status successful.

Guyz, Please let me know about script which is to be sending an automatic email to particular mail id's when a monotoring job get complete with status successful. (1 Reply)
Discussion started by: Rehan Ahmad
1 Replies

4. UNIX for Dummies Questions & Answers

Exit Status 255, Connection closed in SFTP

I'm trying to connect from Server A to Server B to transfer files from A to B. I'm using NUID A1 in Server A and NUID A2 in Server B. I have done the following the steps to setup password-less login. 1. Add the public key of A1 in A to the Authorized keys of A2 in B. 2. Add the public key of... (4 Replies)
Discussion started by: sanchid312
4 Replies

5. Shell Programming and Scripting

How to check whether the sftp script is successful??

hi, how can i check whether the sftp connectivity is successful or not?? i am using expect script to connect to sftp.. sftp_script spawn /usr/bin/sftp abc@ftp.xyz.com expect "abc@ftp.xyz.com's password:" send "password\r" expect "sftp>" send "mput *.txt\r" expect "sftp>" send "bye\r"... (8 Replies)
Discussion started by: Little
8 Replies

6. Shell Programming and Scripting

Check the file status in Linux.

Hi All, I have a simple problem . I am pulling the file from a remote server througha simple file transfer protocal (ftp ). But I wanted to check before pulling the file ,whether the file is being written or in use by some other process and if so i dont want to pull the file and wait for... (1 Reply)
Discussion started by: ptappeta
1 Replies

7. Shell Programming and Scripting

FTP Status check(whether it is successful or not)

Hi Friends I need to check the status of FTP connection i.e. Whether it is successful or not I have tried this by assigning the FTP connection script to a variable and after that using this variable I tried to check the status. In the below code snippet I am trying to assign the FTP... (1 Reply)
Discussion started by: Kannannair
1 Replies

8. Shell Programming and Scripting

How to check sftp connection

Hi All, in our system , the sftp server is continuously up. but suddenly it is brought down. how can i find out the reason behind of these , is their any log files or how can i check the connectvity with sftp. please help me to solve this issue (1 Reply)
Discussion started by: aish11
1 Replies

9. UNIX for Advanced & Expert Users

Connection closing immediatly after successful login

When ssh'ing into certain Unix boxes I'm seeing two errors that appear immediately after entering the password I've never seen. After the error message is displayed the connection closes immediately. The first is “/bin/ksh: Not owner” after which the connection is closed. And, “Read from remote... (2 Replies)
Discussion started by: twk
2 Replies

10. HP-UX

sftp status check

Hi All, I am having shell scripts that make use of ftp to fetch data from one hp-ux box to another. Currently we are migrating these scripts to sftp. Is it a straight forward one? Also, please clarify my following doubts: 1) In ftp we check the success of ftp by verifying the status codes... (4 Replies)
Discussion started by: fisa
4 Replies
Login or Register to Ask a Question