Código
#!/bin/bash HOST="Aqui la IP" USER="Aqui el Usuario" PASS="Aqui la Contraseña del Usuario" CMD=$@ VAR=$(expect -c " spawn ssh -o StrictHostKeyChecking=no $USER@$HOST sudo $CMD match_max 100000 expect \"*?assword:*\" send -- \"$PASS\r\" send -- \"\r\" send -- \"$PASS\r\" send -- \"\r\" expect eof ") echo "===============" echo "$VAR"
La salida que da es:
Citar
?@Ubuntu:/home/?/Desktop$ ./System.sh "reboot"
===============
spawn ssh -o StrictHostKeyChecking=no Usuario@IP sudo reboot
Usuario@IP password:
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts
===============
spawn ssh -o StrictHostKeyChecking=no Usuario@IP sudo reboot
Usuario@IP password:
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts
A ver si me pueden ayudar...
PD: Para que funcione tenemos que tener expect instalado
Citar
apt-get install expect
Saludos