Consegui fazê-lo funcionar alterando o script para 'sudo -i; resto do script 'em vez de sudo -i' resto do script '
Olá, este script está dizendo que há um problema em:
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";'
Mas eu não consigo ver o que está errado com a sintaxe
#!/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'
Qualquer ajuda será muito apreciada.
Tags ssh bash linux scripting shell-script