The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
script : How many sessions are there ? xaviraan Shell Programming and Scripting 3 06-11-2009 08:33 AM
SSH sessions from bash script tsurko Shell Programming and Scripting 3 04-14-2009 04:40 PM
how to make your bash script run on a machine with csh and bash npatwardhan Shell Programming and Scripting 3 11-19-2008 04:17 AM
passing variable from bash to perl from bash script arsidh Shell Programming and Scripting 10 06-04-2008 12:25 PM
Why generate "ash and bash" different output for same bash script? s. murat Shell Programming and Scripting 0 05-26-2008 07:19 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 1 Week Ago
gtangil gtangil is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 2
SSH sessions from bash script

Hi Forum.

First of all thanks for reading.

I need some help here. I have been checking some other posts about this issue, but I still have problems...

I'm trying to conect througn ssh to several machines to kill some process and I have problems with the " ' ' ".

This is what I'm trying to do:

ssh -o "StrictHostKeyChecking no" $IP_START ps -ef | grep $USER | awk '{print "kill -9 "$2""}' | sh

I know for sure that this works:

ps -ef | grep $USER | grep | awk '{print "kill -9 "$2""}' | sh

And I know that the way to do multiple commands in ssh is:
ssh user@server 'command1; command2; command3' or
ssh user@server "command1; command2; command3"

So with this, I have tried all the possible combinations:

ssh -o "StrictHostKeyChecking no" $IP_START "ps -ef | grep $USER | awk '{print \"kill -9 \"$2\"\"}' | sh"

ssh -o "StrictHostKeyChecking no" $IP_START 'ps -ef | grep $USER | awk \'{print "kill -9 "$2""}\' | sh'

....

But this command is killing me:
awk '{print "kill -9 "$2""}'

Could any body help me?

Thanks in advance...
  #2 (permalink)  
Old 1 Week Ago
TonyLawrence TonyLawrence is offline
Registered User
  
 

Join Date: Sep 2007
Location: SE Mass
Posts: 133
Code:
ssh ' ... | awk " {print \"kill -9 \" \$2 }" '
works for me.
  #3 (permalink)  
Old 6 Days Ago
gtangil gtangil is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 2
Thank you very much Tony!!!

It worked!!!

It makes sence to put a scape character also to the $!!
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0