通过 SSH 脚本添加用户的问题取决于操作系统发行版

通过 SSH 脚本添加用户的问题取决于操作系统发行版

您好,此脚本表示存在问题:

bash: -c: line 0: syntax error near unexpected token `then'
bash: -c: line 0: `sudo -i if sudo cat /etc/*-release | grep Ubuntu; then echo "Ubuntu Server";'

但我看不出语法有什么问题

#!/bin/bash -x




echo Enter server IP:
read server

scp /home/Zenoss/.ssh/authorized_keys ******@$server:/home/******

sshpass -p ********  ssh -t ******@$server sudo -i 'if sudo cat /etc/*-release | grep Ubuntu; then echo "Ubuntu Server";
sudo groupadd --gid 7000 zenoss;
sudo adduser --uid 7000 --gid 7000 --disabled-password --gecos "" zenoss;
sudo mkdir /home/zenoss/.ssh;
sudo mv /home/******/authorized_keys /home/zenoss/.ssh/;
sudo chmod 700 /home/zenoss/.ssh;
sudo chmod 600 /home/zenoss/.ssh/authorized_keys;
sudo chown -R zenoss /home/zenoss/.ssh;
sudo chgrp -R zenoss /home/zenoss/.ssh;
fi;

if sudo cat /etc/*-release | grep CENTOS; then echo "Centos Server";
sudo groupadd --gid 7000 zenoss;
sudo useradd -u 7000 -g 7000 zenoss;
sudo mkdir /home/zenoss/.ssh;
sudo mv /home/******/authorized_keys /home/zenoss/.ssh/;
sudo chmod 700 /home/zenoss/.ssh;
sudo chmod 600 /home/zenoss/.ssh/authorized_keys;
sudo chown -R zenoss /home/zenoss/.ssh;
sudo chgrp -R zenoss /home/zenoss/.ssh;
fi;

if sudo getenforce | grep Enforcing; then echo "SElinux is enforcing"; else echo "Selinux is not enforcing"; fi;
if sudo getenforce | grep Enforcing; then sudo restorecon -R -v /home/zenoss/.ssh; fi;
exit'

任何帮助将不胜感激。

答案1

我设法通过将脚本更改为“sudo -i;”来使其工作。脚本的其余部分'而不是 sudo -i 脚本的其余部分'

相关内容