I want to know how I can connect to a server via SSH
putting all the data ( user , host , password ) in script .sh
,
I need this script .sh
to be executed automatically by cron
and that this access a database on the server
.
I have the following code but I do not know how to put a hand on it
#!/bin/bash
HOST="aqui_pon_la_maquina_remota"
USER="aqui_pon_el_usuario_remoto"
PASS="aqui_pon_el_password_remoto"
CMD=$@
VAR=$(expect -c "
spawn ssh -o StrictHostKeyChecking=no $USER@$HOST $CMD
match_max 100000
expect \"*?assword:*\"
send -- \"$PASS\r\"
send -- \"\r\"
expect eof
")
echo "==============="
echo "$VAR"