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
I'm with Rudi. When I have problems trying something like a complex sed command over ssh because of quoting
Steps
make a note of my current shell - let's say it is bash
play with my command on one "home" box.
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]
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.