The UNIX and Linux Forums  

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
Double quotes or single quotes when using ssh? password636 Shell Programming and Scripting 3 05-29-2008 09:52 PM
why is this code generating syntax error?pls help wrapster Shell Programming and Scripting 3 05-21-2008 03:01 PM
ksh execute command containing double quotes pearson05 Shell Programming and Scripting 1 05-02-2008 06:25 AM
unix command to insert double quotes berlin_germany Shell Programming and Scripting 2 01-17-2007 01:07 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-13-2008
julesdiane julesdiane is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 4
too many quotes in command, generating error

I am trying to go through a file with hostnames and access those hosts remotely an excute the following to get the uid of user on each of the boxes.. but i have so many quotes.. its not working.. I fudged with the \ before certain quotes, but that was unsuccessful too...

What am I missing?


ssh hostname `getent passwd | grep username | awk -F":" '{print ($3)}'`

ksh: syntax error at line 1 : `(' unexpected
  #2 (permalink)  
Old 02-13-2008
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Hin awk part is worng ,should be:

Code:
awk -F":" '{print $3}'

  #3 (permalink)  
Old 02-13-2008
julesdiane julesdiane is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 4
[host]
[/]
[root-128]:getent passwd | grep user | awk -F":" '{print ($3)}'
4022

[host]
[/]
[root-129]:getent passwd | grep user | awk -F":" '{print $3}'
4022


Well, good to know that both work.. i have always done it the first way.. However, I am still having an issue executing the command remotely because I need to put it in quotes to run the ssh remote command. or is there another way of doing it?

ssh host 'getent passwd | grep user | awk -F":" '{print $3}''
awk: syntax error near line 1
awk: illegal statement near line 1
  #4 (permalink)  
Old 02-13-2008
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
In the last command, you are missing the last single quote.
But you don't need all the quotes. This works:

Code:
# ssh hostname grep adm /etc/passwd | awk -F":" '{print $3}'
4
#

The only command you need to execute remotely is the grep'ing of the username. That output then gets locally piped to awk.
  #5 (permalink)  
Old 02-13-2008
julesdiane julesdiane is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 4
Oh. Wow. A lot easier than I was making it all out to be! Thanks!
Closed Thread

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 10:05 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