Linux

adduser over SSH 腳本的問題取決於作業系統發行版

  • March 24, 2017

嗨,這個腳本說有一個問題:

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'

任何幫助將不勝感激。

我設法通過將腳本更改為 ‘sudo -i; 腳本的其餘部分’而不是 sudo -i ‘腳本的其餘部分’

引用自:https://unix.stackexchange.com/questions/351943