Ssh in the background


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ssh in the background
# 1  
Old 07-21-2013
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.
# 2  
Old 07-21-2013
You should work with private/public keys to avoid the login and use scp instead of sftp.
# 3  
Old 07-21-2013
Quote:
Originally Posted by vital_parsley
. . .
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.
This User Gave Thanks to RudiC For This Post:
# 4  
Old 07-21-2013
Quote:
Originally Posted by vital_parsley
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.
# 5  
Old 07-22-2013
1 use password less ssh concept into use.
2 do validation of required files
3 if pass, sftp the file
# 6  
Old 07-24-2013
Quote:
Originally Posted by gacanepa
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 ?
# 7  
Old 07-24-2013
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find active SSH servers w/ ssh keys on LAN

Hi, I am trying to complete my bash script in order to find which SSH servers on LAN are still active with the ssh keys, but i am frozen at this step: #!/bin/bash # LAN SSH KEYS DISCOVERY SCRIPT </etc/passwd \ grep /bin/bash | cut -d: -f6 | sudo xargs -i -- sh -c ' && cat... (11 Replies)
Discussion started by: syrius
11 Replies

2. UNIX for Beginners Questions & Answers

Ssh script to validate ssh connection to multiple serves with status

Hi, I want to validate ssh connection one after one for multiple servers..... password less keys already setup but now i want to validate if ssh is working fine or not... I have .sh script like below and i have servers.txt contains all the list of servers #/bin/bash for host in $(cat... (3 Replies)
Discussion started by: sreeram4
3 Replies

3. UNIX for Dummies Questions & Answers

Sudo ssh with command running in background

I am trying to run a command. This is one of my attempts: for i in fileservera; do ssh -t $i 'sudo ls /';doneThis works, and I see the directories. However, what I want to do now is start a process on the remote server such as /usr/bin/connectproc -standalonesudo /usr/bin/connectproc... (1 Reply)
Discussion started by: newbie2010
1 Replies

4. Shell Programming and Scripting

Executing a background script using ssh keys

Greetings, i've been working with a user-friendly menu on ksh to allow users execute scripts located on a remote server, so they wont have to login and manually launch those scripts every single time. This is a HP-UX box and currently on a /usr/bin/ksh shell. I've setup ssh keys on both... (1 Reply)
Discussion started by: nbriozzo
1 Replies

5. Shell Programming and Scripting

Ssh = ssh expect and keep everything not change include parameter postion

I have write a script which contains ssh -p 12345 dcplatform@10.125.42.50 ssh 127.0.0.1 -p 5555 "$CMD" ssh root@$GUEST_IP "$CMD" before I use public key, it works well, now I want to change to "expect", BUT I don't want to change above code and "parameter position" I can post a... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

6. Programming

Background SSH using here document

I'm trying to use Here documents to pass several commands to a remote server over SSH. However I'm having problems. The code is as follows: nohup ssh $i_hostname exec /usr/bin/ksh -s << EOF >> $AS_STOPSAP_LOG & echo $i_instname; ps -ef | grep name | grep ${i_instname} |grep -v grep ... (4 Replies)
Discussion started by: doonan_79
4 Replies

7. Programming

Background (nohup * &) SSH command block possible?

Hello, I am trying to find a way to send several sequential commands via SSH to a remote box in a single command. Thoughts so far: 1) Can I put them into a function and call the function within the ssh command? e.g. ssh <targetserver> $(functionx) No - then it calls the function in... (4 Replies)
Discussion started by: doonan_79
4 Replies

8. Shell Programming and Scripting

PID from background ssh

Hello. I was wondering if someone can help me out with something. To simplify my life, I have written a tiny script to open an ssh tunnel through another linux host so that I can access the esxi hosts on that network using the client. For this I have to tunnel ports 443, 902, and 903. Here is what... (1 Reply)
Discussion started by: numetheus
1 Replies

9. Shell Programming and Scripting

Using ssh to execute a remote script in the background

Help please!! I want to use ssh to execute a remote exe and while it's running I want to query for the process ID of the exe (2 different ssh commands) 1. sshpass -p "<passwd>" ssh -f -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@<ipaddress> nohup /tmp/mmds_asyn & 2.... (0 Replies)
Discussion started by: rvompoluTMW
0 Replies
Login or Register to Ask a Question