Ssh in the background | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Ssh in the background

Shell Programming and Scripting


Tags
ssh login background

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-21-2013
vital_parsley vital_parsley is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 6 October 2013, 2:47 PM EDT
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
Ssh in the background

Hi,

I am trying to execute an ssh command in my script.
ssh abcd@server_name
After this command it actually logs in to the server asking for password prompt and then actually logs in to the server.

I want all this to be happening in the background and show noithing in the output of my script.
I just want to login to the server in the background and check if the file exists and sftp it.

How do i do it ? without showing anything on my script.
Sponsored Links
    #2  
Old 07-21-2013
ripat ripat is offline Forum Advisor  
Registered User
 
Join Date: Oct 2006
Last Activity: 17 February 2014, 7:51 AM EST
Location: Belgium
Posts: 537
Thanks: 4
Thanked 38 Times in 28 Posts
You should work with private/public keys to avoid the login and use scp instead of sftp.
Sponsored Links
    #3  
Old 07-21-2013
RudiC RudiC is online now Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 22 August 2014, 11:14 AM EDT
Location: Aachen, Germany
Posts: 4,091
Thanks: 67
Thanked 970 Times in 920 Posts
Quote:
Originally Posted by vital_parsley View Post
. . .
How do i do it ? without showing anything on my script.
Redirect stdout and stderr to a log file (for error analysis) or to /dev/null.
The Following User Says Thank You to RudiC For This Useful Post:
vital_parsley (07-24-2013)
    #4  
Old 07-21-2013
gacanepa gacanepa is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 26 July 2014, 8:32 PM EDT
Location: Villa Mercedes, San Luis, Argentina
Posts: 164
Thanks: 21
Thanked 24 Times in 21 Posts
Quote:
Originally Posted by vital_parsley View Post
Hi,

I am trying to execute an ssh command in my script.
ssh abcd@server_name
After this command it actually logs in to the server asking for password prompt and then actually logs in to the server.

I want all this to be happening in the background and show noithing in the output of my script.
I just want to login to the server in the background and check if the file exists and sftp it.

How do i do it ? without showing anything on my script.
Let me get this straight. After connecting via ssh to a remote server, you want to check whether a certain file exists there and if it doesn't, upload it from your localhost using sftp, correct? Please confirm and we'll be more than glad to help.
Sponsored Links
    #5  
Old 07-22-2013
vinil vinil is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 28 July 2014, 9:32 AM EDT
Posts: 40
Thanks: 1
Thanked 1 Time in 1 Post
1 use password less ssh concept into use.
2 do validation of required files
3 if pass, sftp the file
Sponsored Links
    #6  
Old 07-24-2013
vital_parsley vital_parsley is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 6 October 2013, 2:47 PM EDT
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by gacanepa View Post
Let me get this straight. After connecting via ssh to a remote server, you want to check whether a certain file exists there and if it doesn't, upload it from your localhost using sftp, correct? Please confirm and we'll be more than glad to help.
Yes thats correct....just that mre than uploading I would be getting some files from that server.

I tried what rudic suggested and it has helped.
Would like to know now:

Once I have logged in...i want to sftp file to another server .,....how can I do that ?
I do not wan the sftp> prompt to be shown.
The file should be sftped in the background.

Can you please help ?
Sponsored Links
    #7  
Old 07-24-2013
gacanepa gacanepa is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 26 July 2014, 8:32 PM EDT
Location: Villa Mercedes, San Luis, Argentina
Posts: 164
Thanks: 21
Thanked 24 Times in 21 Posts
Ok. So you're logged in to your first server, and from there you're going to sftp the file to another server.
Try this:

Code:
sftp user@2ndServer <<END_SEND
	cd $directory
	put $file
	quit
END_SEND

This code snippet makes the following assumptions:
  1. the 1st server is both a server (from your localhost's point of view) and a client (from the 2nd server point of view).
  2. The remote sftp service is listening on the default port, that is, port 22 (other wise, you need to add the -oPort switch, like this: -oPort=1111 , for example).
  3. In your script, before you use this code, you need to set the following variables: directory (for remote directory, use an absolute path), file (the file you want to sftp to the 2nd server)
Let me know how it goes.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Background SSH using here document doonan_79 Programming 4 04-27-2012 11:39 AM
Background (nohup * &) SSH command block possible? doonan_79 Programming 4 04-27-2012 07:45 AM
PID from background ssh numetheus Shell Programming and Scripting 1 08-06-2011 07:58 PM
Using ssh to execute a remote script in the background rvompoluTMW Shell Programming and Scripting 0 03-10-2011 06:35 PM



All times are GMT -4. The time now is 11:42 AM.