Test if Remote server is up and running before SFTP'ing files (in batch mode)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Test if Remote server is up and running before SFTP'ing files (in batch mode)
# 1  
Old 04-25-2016
Display Test if Remote server is up and running before SFTP'ing files (in batch mode)

Hello,

In our Data Warehouse environment, before our batch SFTP jobs kick off to pull the files from remote servers, I would like to setup a pre-sftp job that would test if all the remote servers from where the files are being pulled, are up and running. If any one of the remote serer is down, then an error needs to be raised.

I was thinking if I can use one of the below commands, but do not know what would be the return code I need to check in case of a successful connection and unsuccessful connection for these commands.
Please advise me of the appropriate commands that I could use in a shell script to handle this. Thank you

Commands:
  • sftp <host> OR sftp <username>@<host>
  • ping <host>
  • telnet <host> <port:22>
  • <any other command>?

Regards,
Dippu
# 2  
Old 04-25-2016
How about
Code:
ping -c2 <host>
if [ $? = 0 ]
  then echo "It worked!"
else
  echo "Cant ping at <host>"
fi

This User Gave Thanks to wbport For This Post:
# 3  
Old 04-28-2016
The bash internal /dev/tcp could also be used something like this:

Code:
if timeout 3 bash -c '> /dev/tcp/<host>/22' 2>/dev/null
then
    echo "ssh running on <host>"
else
   echo "Timeout connecting to port  ssh(22) on <host>"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename (move) multiple files on remote server using sftp

I want to rename (move) multiple files on remote server. I tried the following command to move all TXT files from my_dir directory to /new_dir. But it does not work. Any help? #!/bin/ksh sftp -dev3 << ABC cd my_dir $(for i in TXT; do echo "ls *.$i" ; rename $x /new_dir/$x;... (1 Reply)
Discussion started by: Soham
1 Replies

2. Shell Programming and Scripting

Help with moving files on remote server using sftp

I need to sftp a file ABC_sysdate.csv (File name with system date and timestamp) to a temporary directory on the remote server and once the file is copied I've to move the file from temporary directory to the main directory with the same name. I have to generate a new file every hour and repeat... (6 Replies)
Discussion started by: srinup
6 Replies

3. Solaris

FTP-ing files from Windows server to UNIX server

I need to transfer files from a Windows server to the Unix server and have to run some shell script on it to get the required output. Is it possible to transfer files from Windows server to unix server through any shell script? If so can you please help me with the details. Thanks in... (8 Replies)
Discussion started by: ssk250
8 Replies

4. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

5. Red Hat

Chroot sftp users, remote sftp login shows wrong timestamp on files

Hello, I have a weird issue, I have RHEL 5.7 running with openssh5.2 where sftpgroup OS group is chroot. I see the difference difference in timestamp on files, when I login via ssh and SFTP, I see four hour difference, is something missing in my configuration. #pwd... (8 Replies)
Discussion started by: bobby320
8 Replies

6. Shell Programming and Scripting

ftp'ing multiple files to the remote server

unix shell script (2 Replies)
Discussion started by: giridhar276
2 Replies

7. Ubuntu

I want to upload file on remote machine in noninteractive mode through SFTP

Hi All, I want to upload file through SFTP in non interactive mode on remote server. please tell me what will have to do in oreder to do SFTP . (1 Reply)
Discussion started by: kulbhushan
1 Replies

8. Programming

SFTP from one remote server to another remote server from desktop

Hi, I have 1. lappy 2. server A 3. server B Now, what i need is to run a command from lappy that will sftp a file from server A to server B. Please guide me to achieve this. -akash (1 Reply)
Discussion started by: akash.mahakode
1 Replies

9. UNIX for Advanced & Expert Users

Sftp in Batch Mode

Hi, I am trying to do sftp a file from one server to another solaris server. Both are sftp enabled. I have generated the rsa key in local server and did a ftped the public key to the remote server and added that in the authorization keys file. Then i try to run the below command using a... (2 Replies)
Discussion started by: sivaemn
2 Replies
Login or Register to Ask a Question