samedi 9 mai 2015

SED in remote SUDO ssh script

I am trying to disable RHN check when running yum on 1000 servers. It is done by:

Editing this file /etc/yum/pluginconf.d/rhnplugin.conf

[main]
enabled = 0 

I wrote a script to do this remotely. We are using individual accounts and I need to execute this command using SUDO:

for HOST in $(cat serverlist ) ; do echo $HOST; ssh -o ConnectTimeout=5 -oStrictHostKeyChecking=no $HOST -t 'sudo cp /etc/yum/pluginconf.d/rhnplugin.conf /etc/yum/pluginconf.d/rhnplugin.$(date +%F) ; sudo sed -i -e "s/1/0/g" /etc/yum/pluginconf.d/rhnplugin.conf ' ; done

I know it is a long line but why does it not work?

All individual commands work on their own

sudo cp /etc/yum/pluginconf.d/rhnplugin.conf /etc/yum/pluginconf.d/rhnplugin.$(date +%F)

sudo sed -i -e "s/1/0/g" /etc/yum/pluginconf.d/rhnplugin.conf

have tried escaping the special chars:

sudo sed -i -e "s\/1\/0\/g" /etc/yum/pluginconf.d/rhnplugin.conf

But I get an error all the time:

sed: -e expression #1, char 1: unknown command: `?'

Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire