too many quotes in command, generating error

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting too many quotes in command, generating error
# 1  
Old 02-13-2008
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  
Old 02-13-2008
Hin awk part is worng ,should be:
awk -F":" '{print $3}'

# 3  
Old 02-13-2008
[root-128]:getent passwd | grep user | awk -F":" '{print ($3)}'

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

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  
Old 02-13-2008
In the last command, you are missing the last single quote.
But you don't need all the quotes. This works:
# ssh hostname grep adm /etc/passwd | awk -F":" '{print $3}'

The only command you need to execute remotely is the grep'ing of the username. That output then gets locally piped to awk.
# 5  
Old 02-13-2008
Oh. Wow. A lot easier than I was making it all out to be! Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing double quotes in echo command

Please help me to use echo or printf type of command to print some value from variable within double quotes - I want to print the double quote ( " ") also. I tried #!/bin/bash VALUE=some_value echo '{"value" : "$VALUE"}' I was expecting the above script would produce .. {"value" :... (3 Replies)
Discussion started by: atanubanerji
3 Replies

2. UNIX for Beginners Questions & Answers

Split Command Generating Incomplete Output Files

Hello All, May i please know how do i ensure my split command would NOT generate incomplete output files like below, the last lines in each file is missing some columns or last line is complete. split -b 50GB File File_ File_aa |551|70210203|xxxxxxx|12/22/2010 20:44:58|11/01/2010... (1 Reply)
Discussion started by: Ariean
1 Replies

3. UNIX for Beginners Questions & Answers

Please explain the use of quotes in awk command in below example-

Example: `abc.ksh | grep '^GLIS'| awk -F' ' '{print \$1}'`; (3 Replies)
Discussion started by: Tanu
3 Replies

4. Shell Programming and Scripting

Issue with quotes when running SQL command from within su -c

RHEL 6.2/Bash shell root user will be executing the below script. It switches to oracle user logs in using sqlplus and tries to run the below UPDATE statement. All the commands after su -c are enclosed in a single quote delimited by semicolon. The execution has failed because the quotes... (3 Replies)
Discussion started by: omega3
3 Replies

5. Shell Programming and Scripting

Issue with Single Quotes and Double Quotes for prompt PS1

Hi, Trying to change the prompt. I have the following code. export PS1=' <${USER}@`hostname -s`>$ ' The hostname is not displayed <abc@`hostname -s`>$ uname -a AIX xyz 1 6 00F736154C00 <adcwl4h@`hostname -s`>$ If I use double quotes, then the hostname is printed properly but... (3 Replies)
Discussion started by: bobbygsk
3 Replies

6. Solaris

Error generating ssh-keygen

I'm trying to generate this key but getting an error "file not found" Here is the command: # ssh-keygen -t dsa Generating public/private dsa key pair. Enter file in which to save the key (//.ssh/id_dsa): /export/home/bartadm/.ssh/id_dsa Enter passphrase (empty for no passphrase): Enter... (2 Replies)
Discussion started by: Kjons76
2 Replies

7. UNIX for Dummies Questions & Answers

Dynamic command with quotes

I have a shell script which composes a dynamic command (DataStage application): conn="/DS/Ascential/DataStage/DSEngine/bin " paramlist=" -run -jobstatus -wait -mode NORMAL -param JOB_ID=98246 -param PREVRUNDT='2010-03-20 18:00:00' -param CURRRUNDT='2010-03-21 18:00:00'" jobinfo=" APPPRJ... (2 Replies)
Discussion started by: laiko
2 Replies

8. Shell Programming and Scripting

job generating error mails

Hi Is there any way we can findout which job/process in unix environment is generating error mails. I am continuously getting it with no subject.. I know the hostname. And the error in mail - SQL server timed out. There are hundreds of jobs runing there. How can we find the culprit... (3 Replies)
Discussion started by: manojgarg
3 Replies

9. Shell Programming and Scripting

why is this code generating syntax error?pls help

#!/bin/sh copy() { source=`stat -c %s $1` dest=0 cd $2 while ;do cp $1 $2 & pct=`((100 * $dest) / $source )` dest=`dest+1` echo -en ".$pct%\b\b\b" sleep 1 done } echo "starting now" copy /file1 /tmp (3 Replies)
Discussion started by: wrapster
3 Replies

10. Shell Programming and Scripting

ksh execute command containing double quotes

How do I execute a command containing a double quote ? I pass a variable to grep that contains spaces, so I need to quote it, but it does not work. #!/usr/bin/ksh set -x txt='"next to"' cmd="grep $txt ~dpearso5/file2" echo $cmd $cmd This is the error I get: + grep "next to"... (1 Reply)
Discussion started by: pearson05
1 Replies
Login or Register to Ask a Question