[SOLVED] put dd | ssh command in backgound


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [SOLVED] put dd | ssh command in backgound
# 1  
Old 09-19-2012
[SOLVED] put dd | ssh command in backgound

Greetings,

I have an issue that has baffled me. I have done many searches, read the man documentation, and I have yet to find a solution. I am trying to run the following command within a script to copy a file across servers:

Code:
 
$(dd if="$FDIR" bs=1024 2> /dev/null | ssh "$(whoami)@$SERVER" dd of="$TDIR" bs=1024 2> /dev/null &)

It works, however, this is inside a while loop, and it blocks the loop from executing until the copy is done. The behavior that I want is for no messages from the dd command to show up in the script for the user to see, and I want to be able to run more than one copy (of different files) at a time.

I added the & at the end of the command to try to put it in the background, but it is still blocking the while loop from continuing. I am using ksh on HP-UX.

I was wondering whether anyone has any suggestions?
# 2  
Old 09-19-2012
You want a command in backticks or $( ) to return immediately? You can't have it both ways. If you want to catch a command's output, you have to wait for it.
# 3  
Old 09-19-2012
Quote:
Originally Posted by Corona688
You want a command in backticks or $( ) to return immediately? You can't have it both ways. If you want to catch a command's output, you have to wait for it.
I don't want the output, I'm sending the STDERR output of 'dd' to /dev/null so that it doesn't show it to the user. I want to put the file copy into the background so that another can begin.

The functionality I'm looking for is similar to the batch mode / quiet function of scp, though for reasons that don't matter, I can't use scp.
# 4  
Old 09-19-2012
Quote:
Originally Posted by unaligned
I don't want the output
So why are you using a command substitution? I mean:
$(command)
--
Bye
# 5  
Old 09-19-2012
That's what $( ) does though -- turns its output into a string to put into a variable or command or what have you. If you don't need that, don't do that.

Code:
( dd if="$FDIR" bs=1024 2> /dev/null | ssh "$(whoami)@$SERVER" dd of="$TDIR" bs=1024 2> /dev/null ) < /dev/null > /dev/null 2>/dev/null &


# other stufff
# ...
# ...


wait # Wait for your background process to finish

# 6  
Old 09-20-2012
Thanks guys. I used the command substitution because it seemd to solve a syntax error in another piece of code that I didn't post here. I have now fixed this error and it works exactly as I want it to.

Thanks again, your assistance pointed me in the right /dir/.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Ssh to windows from linx

Hi, I was trying to ssh to windows server from linux box(red hat). I am a bit confused about where to generate the keys. Should I generate the keys in linux and place it in windows or other way around. I have installed openssh package in cygwin on the windows box. can someone please tell me... (0 Replies)
Discussion started by: ahmedwaseem2000
0 Replies

2. UNIX for Advanced & Expert Users

[Solved] SSH key authentication problem

Hi All, this is the very first time i am going to use SSH authentication. first i login to server@ and under this ..ssh directory of servera i used this following command: ssh-keygen -t rsa -b 1024 and i had 2 files(bravo_dbtest and bravo_dbtest.pub) created respectively, further i copied the... (13 Replies)
Discussion started by: lovelysethii
13 Replies

3. Shell Programming and Scripting

[solved] Process ssh command in while loop

I have a script that reads a file containing a list of server names. It's suppose to loop through the list of names and execute a command on the remote server using ssh. It processes the ssh command for the first server in the list and then exits. Here's the code: #!/bin/bash ... (2 Replies)
Discussion started by: westmoreland
2 Replies

4. Shell Programming and Scripting

SSH and Backticks [solved]

I have been testing a new script and cannot figure out why my `cat spath` will not execute on the remote machine? sudo ssh -p 22344 -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l testuser 192.168.1.6 "find `cat spath` -depth" cat: spath: No such file or directory but... (0 Replies)
Discussion started by: metallica1973
0 Replies

5. Shell Programming and Scripting

run command with ssh[solved]

Hi all, Is it possible to make this possible ? $ echo $SKY_HOME /var/sink/SKY $ echo $SKY_HOME /home/smily/SKY $ ssh root@xyz "echo $SKY_HOME" root@xyz 's password: ****** /home/smily/SKY wrong output I was expecting the output as /var/sink/SKY (3 Replies)
Discussion started by: linuxadmin
3 Replies

6. Shell Programming and Scripting

[Solved] Using SSH in bash script

Hello, I am writing a script that has to log in to X number of servers over a full C class range. I am only keyed on a certain number of these servers and this can change from time to time. The part of my script that deals with this is for i in $(cat $server_list); do ssh ... (0 Replies)
Discussion started by: colinireland
0 Replies

7. Shell Programming and Scripting

[solved] Killing 3rd command in ssh chain

Hi All, Noob question here... How do I kill the 3rd command in this ssh chain effectively? # ssh -t -t 10.80.0.5 'ssh 10.80.0.6 | /var/tmp/some_script' The "/var/tmp/some_script" contains: ssh 10.80.0.81 'echo "Hello World!!!!" >> /tmp/sample.txt'The problem is that once the sample.txt... (2 Replies)
Discussion started by: NYG71
2 Replies

8. Shell Programming and Scripting

[Solved] passwordless SSH not working in one direction

Hi, I am trying to remove the password requirement when connecting with SSH. I have 1 server with Solaris 10 and 1 server with Solaris 9. I have created both keys on both servers, copied public key to the other server and created a file auithorixed_keys on both. I can successfully... (4 Replies)
Discussion started by: mcclunyboy
4 Replies

9. Shell Programming and Scripting

Cron Jobs Still Running In Backgound

Hi guys, I've got a few cron jobs ... porblem is they are running as intended but some of them just tend to stay there in sleeping mode for quite some time ... sometimes even days ... for example when i run the ps command i can see that some are still there although the same script had run many... (6 Replies)
Discussion started by: King Nothing
6 Replies

10. Shell Programming and Scripting

Running a script in backgound

Hello everybody this is my new problem: I have a 'file1' as log of a process, y want to copy to 'file2' specific lines of the 'file1' when those lines are created in 'file1' that means in real time, i'm using the following command and it works: tail -f 'file1' | grep '_RESP' | grep -v... (7 Replies)
Discussion started by: Lestat
7 Replies
Login or Register to Ask a Question