Sed: -e expression #1, char 20: unterminated address regex

I am trying to add word in last of particular line.
the same command syntex is running on prompt. but in bash script give error."sed: -e expression #1, char 20: unterminated address regex"

Please help.

for i in `cat servername`;
do
ssh -q -t root@$i  sed -i '/simple_allow_groups =/s/$/, group-name1/' /etc/sssd/sssd.conf
done

Just a shot in the dark: try enclosing the entire sed command in double quotes.

I'm with Rudi. When I have problems trying something like a complex sed command over ssh because of quoting
Steps

  1. make a note of my current shell - let's say it is bash
  2. play with my command on one "home" box.
  3. once I got it working at "home":
    paste the command into a simple two line shell script, let's call it t.sh
#!/bin/bash    
[paste required external env variables here if needed]
[paste command here]
  1. automate it:
for i in `cat servername`
do
   scp myusername@$i t.sh /tmp/t.sh
   ssh myusername@$i 'chmod +x /tmp/t.sh && /tmp/t.sh'
done

This looks like a lot of work. It is not. But when you execute a complex remote one-liner command it can mess up by being garbled by ssh and your command line or wrong environment variable settings. Explaining to management why your script trashed 10 servers is a whole lot more work and time consuming.

Why scp? The script can be passed via stdin to the remote shell.

for i in `cat servername`
do
   ssh "myusername@$i" /bin/bash <t.sh
done
1 Like

Thanks Rudic.
Its working now.