Using sed command in for loop across multiple servers

Matthew Perrott

I am trying to manipulate the same text file across multiple hosts. The command I currently have it:

for host in $(cat /etc/hosts | grep text | cut -d' ' -f 1 | sort -u); do
    ssh $host \
    sudo sed -i "s/enabled = 1/enabled = 0/" /etc/yum.repos.d/testing.repo
done

The sed command itself works locally on the host with no problems however when I run it here, I get:

sed: -e expression #1, char 9: unterminated `s' command

What am I doing wrong?

Siva

Try this,

for host in $(grep test /etc/hosts | cut -d' ' -f 1 | sort -u); do
    ssh $host 'sudo sed -i "s/enabled = 1/enabled = 0/" /etc/yum.repos.d/testing.repo'
done

we should wrap around the remote commands with quotes.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Using while loop to ssh to multiple servers

Using Quartz to Schedule Single Job Across Multiple Stateless App Servers

MySQL database across multiple servers

Powershell For Loop for multiple servers

select multiple lines using the linux command sed

Replacing multiple line using sed command

Generate unique ID across multiple independent servers

How to manage websockets across multiple servers / workers

How to scale a trie across multiple servers

Java: synchronizing threads across multiple servers

Synchronized script execution across multiple servers

Scaling Socket.IO across multiple servers

Synchronization xml file across multiple servers(machine)

Shared Varnish cache across multiple servers

How to deploy a distributed system across multiple servers in parallel using VSTS release process

Deleting multiple SSRS reports across subfolders using command line?

How do I wrap a long sed command embedded within a bash/shell script across multiple lines?

How to use `sed` command to get a text between two patterns spanning across multiple lines?

Passing multiple files using zcat and a for loop to a command

awk command to print multiple columns using for loop

Loop over a curl command throguh a text file using sed

Multiple 'sed' commands with 'for' loop

VBA Loop Across Multiple Worksheets

For loop across multiple ggplot graphs

trying to parse multiple patterns from single command (using sed)

BASH with sshpass send same command to multiple servers based on list of servers?

How to substitute spaces with %20 in a substring of a line across multiple files using sed, awk, grep etc

How to run multiple Go lang http Servers at the same time and test them using command line?

Spring batch restrict single instance of job across multiple servers