Answer the question
In order to leave comments, you need to log in
Why is expect not executing the script?
Please help me find where I went wrong
#!/bin/bash
set -x
#имя пользователя
username=$(cat /home/administrator/crontab/usr)
#файл с паролем
password=$(cat /home/administrator/crontab/pass)
# имя обрабатываемых хостов
hostnames="vld-prod1-05"
#Преобразование $hostname в $H
for H in $hostnames
do
if (zenity --info --title="EXPECT SCPT" --TEXT="ДЛЯ ВЫПОЛНЕНИЯ НАЖМИТЕ (ОК)")
then
if (zenity --progress --pulsate --auto-close --auto-kill --text="Выполняется: $H")
#Первая команда EXPECT
expect <<EOF
spawn scp -r /home/administrator/crontab [email protected]$H:/home/administrator/
while 1 { expect {
"(yes/no)" {send "yes\r"}
"*assword:" {send "$password\r"}
"$H:" {break}
"Permission denied" {send_user "Подключение не выполнено\r" ; exit 1}
"timeout" {send_user "Время ожидания истекло\r" ; exit 2}"
}}
exit 0
expect eof
EOF
#Вторая команда EXPECT
expect <<EOF
spawn ssh [email protected]$H
while 2 { expect {
"(yes/no)" {send "yes\r"}
"*assword:" {send "$password\r"}
"$H:" {break}
"name *" {send_user "Подключение не выполнено\r" ; exit 1}
"timeout" {send_user "Время ожидания истекло\r" ; exit 2}
}}
send "sudo mkdir /home/user/.cron\r"
expect "пароль для *:" {send "$password\r"}
expect "Файл существует*" {send_user ".cron существует\r" }
send "sudo cp /home/administrator/crontab/crontab/del.sh /home/user/.cron\r"
expect "пароль для *:" {send "$password\r"}
send "sudo crontab -u user /home/administrator/crontab/crontab/reg\r"
expect "пароль для *:" {send "$password\r"}
send "sudo rm -rf /home/administrator/crontab\r"
expect "пароль для *:" {send "$password\r"}
exit 0
expect eof
EOF
then
(zenity --info --title="EXPECT SCPT" --text="Выполнен: $H")
else
(zenity --error --title="EXPECT SCPT-ERROR" --text="Не выполнен: $H")
fi
else
(zenity --error --title="EXPECT SCPT-ERROR" --text="Скрипт не выполнен")
fi
#Завершение преобразования на скрипт $H
done
Answer the question
In order to leave comments, you need to log in
1. well, it says to you twice that "Permission denied" {send_user "Connected ...".
2. Why are you bothering with the password and expect, if you can set up ssh keys and live in peace, like all people, and not show the real password on the toaster to outsiders?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question