Command pipeline trouble


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command pipeline trouble
# 1  
Old 12-17-2013
Command pipeline trouble

Hello,
I am attempting to ssh to a server and run a set of commands on a remote set of servers. I am getting the following error below, I am thinking quotes may be the problem. This command works on the local machine in bash. Not when I ssh to a remote server. Basically the command should replace a portion of a string in /etc/rc.local then kill a process, then using the replaced string in rc.local use grep to set a variable (the first half of the string is different on servers) to run it.

Hope that is explained well enough.


ERROR:
This happens only when I use ssh to remote server.
Code:
 bash: -c: line 1: syntax error: unexpected end of file

Command:

Code:
#!/bin/bash
for server in server1 server2 
do
ssh -l user $server "/bin/sed -i 's/_prod/_DFLT/' /etc/rc.local && /usr/bin/pkill ptpd && x=$(grep ptpd /etc/rc.local) && $x"

done


Last edited by jaysunn; 12-17-2013 at 05:44 PM.. Reason: EDIT: added done in loop
# 2  
Old 12-17-2013
Embedding the remote code in local code denotes a second evaluation.
Instead have the script code in a separate file script.sh and run it remotely with
Code:
for server in server1 server2
do
ssh -qx -l user $server "sh -s" < script.sh
done

Arguments can can be passed after the -s.

Last edited by MadeInGermany; 12-17-2013 at 08:25 PM..
This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 12-18-2013
Run that line with the -x option set to see what causes the trouble. It may be sufficient to escape the $ signs.
This User Gave Thanks to RudiC For This Post:
# 4  
Old 12-19-2013
Thanks to your replies, I ended up using the \$ method which worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

awk trouble inside another command

I tried running this. dsh -w server1 'lsof /audit | awk '{ print $2 }'' It did not like above so I tried to escape the single parenthesis at the end. dsh -w server1 'lsof /audit | awk '{ print $2 }\'' It then hung so I changed up the parenthesis to this. This worked. dsh -w server1... (6 Replies)
Discussion started by: cokedude
6 Replies

2. Shell Programming and Scripting

Trouble using awk command

Hi, I have 2 .txt pads containing data. I need a script which reads content of one .txt file, performs some operations and calculates a number which is stored in a variable. Now , all the content of another .txt pad should be appended to first .txt pad at pre calculated nth line number. ... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies

3. Shell Programming and Scripting

Trouble with variable and command assignment

I have a section of a script where I want to check a log file for a certain oracle error and if there is only one error (and it is ORA-39152) then I want to email that script is complete. Otherwise email failure and log. Somehow with this while the log only has one error and it is ORA-39152, I... (5 Replies)
Discussion started by: cougartrace
5 Replies

4. Shell Programming and Scripting

Trouble with awk command

Hi, I need to read a string with ; separated using loop one filed by one field and perform some operation. Can you please check and let me know how to print command parameterised. key=phani;ravi;kiran number_of_keys=`echo $key|awk '{print NF}' FS=';'` for (( i = 1; i <= $number_of_keys;... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies

5. Shell Programming and Scripting

Having trouble with find rename jpg command

Hi, I have a large series of directories and subdirectories with many jpgs in them. I need to do two things: 1. Create a copy of each jpg found within it's own subdirectory 2. Rename this copied jpg such that apple.jpg becomes apple_m.jpg I have tried to run the following commands in... (1 Reply)
Discussion started by: atharvan13
1 Replies

6. UNIX for Dummies Questions & Answers

Trouble managing ports from the command line

What are the commands to manage ports from my command line. Example: Opening Ports, Closing Ports, Viewing their status, etc. I am having a hard time finding this answer. I'm trying to trouble shoot some networking problems and it would be very helpful if I could just do this from the... (1 Reply)
Discussion started by: syregnar86
1 Replies

7. Shell Programming and Scripting

trouble executing a command in csh

Hi All!! I am having trouble in executing the following command into a c-shell script. mv "$file" "$(head -1 "$file")" The funny thing is that the same command works perfectly from the command line, but when incorporated into a "foreach loop" of a c-shell script, it shows an error -... (1 Reply)
Discussion started by: chen.xiao.po
1 Replies

8. UNIX for Dummies Questions & Answers

Trouble with the Source command..

Hi everyone, I've been writing a script as an assignment which essentially does the exact same thing as the tree -d function (bash shell btw), except next to every directory name it gives a number which you can input into the same command in order to change the current working directory to the... (1 Reply)
Discussion started by: petey22uk
1 Replies

9. UNIX for Dummies Questions & Answers

Trouble with flex command in makefile

Hey all, im trying to create a makefile in unix. cpp2html is a program created from the files cpp2html.o and lex.yy.o. cpp2html.o is created from compiling cpp2html.c and lex.yy.o is created from another created file lex.yy.c. and lex.yy.c is created from a command "flex cppscanner.l" and here is... (1 Reply)
Discussion started by: iwatk003
1 Replies

10. Shell Programming and Scripting

trouble using mailx command

Hi. I have been trying to send mail using the mailx command. I also tryed to use the mail command. The thing is that when I try to send the email, i receive automatically to my mailbox a DAEMON response sayng that the mailhost is unknown... The syntax I am using is this: $mailx -s "this... (2 Replies)
Discussion started by: ldrojasm
2 Replies
Login or Register to Ask a Question