Help with piping
I'm having trouble understanding something. I've posted in another section about this, but maybe this is a better place for it. I'm trying to run a single command from one machine to another machine, but I can't get it to work right. I hope someone can explain what I'm doing wrong.
I run this command to find a file with a certain size and move it another directory: ssh machine2 ls -al /tmp/test* | grep 4106 | awk '{ print "cp", $9, "/tmp/junk/" }' | bash I get this error: cp: cannot stat `/tmp/testfile2-1.txt': No such file or directory When I terminal to the node and remove the ssh machine2 this command works just fine. ls -al /tmp/test* | grep 4106 | awk '{ print "cp",$9,"/tmp/junk/" }' | bash I'm I doing something wrong here? Thanks for the help! |
I haven't put it into ssh yet but on your original concept, the part of incrementing count can be trimmed down to something like this...
for (( i=1; i=<3; i++ )) ; do echo n$i ssh n$i Quote:
Code:
#!/bin/bash |
Wow homey... I like you're script a lot better then I do mine. It's much more advanced. I hope that I can get it working with my while loop to do many machines. Thanks for the input!
|
You're welcome!
A couple of notes: Where I have tmp/*.txt ... I made a tmp in the home folder. In reality, you might have to change that to /tmp/*.txt and change the cut command to match. .... -f3 or what ever gives you the correct file name. For example: Code:
#!/bin/bash For example: for (( c=1; c=<3; c++ )) ; do echo n$c ssh n$c I have never tried something like this on ssh so I'm not sure how to proceed with that part yet. |
Re: Help with piping
Quote:
try : ssh machine2 "ls -al /tmp/test* | grep 4106 | awk '{ print "cp", $9, "/tmp/junk/" }' | bash" (with the quotes so the whole piped commands are ssh'ed and executed remotely and not just the ls) |
I was putzing with the ssh part. I think you would best put the machine names into a file and read that file. For me at least, the machines aren't likely to be called m1, m2 m3 etc etc.
Here is a sample list.txt which has the machine names. Code:
curly Note: Unless you have ssh to run without passwords, you will have to put in a password twice for each machine. Code:
#!/bin/bash |
Homey,
You are too cool for words... Thank you so much for taking the time to figure out a problem for such a newbie. I wish there was a way to repay you for your work. :) I'm started tweaking your script and it's working!! |
Glad to help! :)
Don't forget to google for the Advanced Bash Scripting Guide. It has a lot of great info and examples. |
All times are GMT -5. The time now is 06:52 AM. |