使用sed从远程命令替换bash变量

时间:2016-12-01 22:38:03

标签: bash unix ssh sed sudo

我正在尝试将用户“demouser”添加到远程服务器的/ etc / sudoers,我想从变量中传递用户名。

这样可行,但我想使用变量$USERNAME代替demouser

ssh centos@$remote_host -t  'sudo sed -i "\$ademouser        ALL=(ALL)       NOPASSWD:ALL" /etc/sudoers'

我尝试过使用它,但它没有用。

export USERNAME=demouser    
ssh centos@remote_host bash -c "'sudo sed -i "\$a$USERNAME ALL=(ALL)       NOPASSWD:ALL" /etc/sudoers'" 
Error: -bash: syntax error near unexpected token `('

0 个答案:

没有答案
相关问题