I have a PHP page which runs the following expect script to upload a file to another server on my network:
#!/usr/bin/expect -f
set password [lindex $argv 0]
spawn /usr/bin/scp /home/Dave/bin/test [email protected]:/etc/test
expect {
-re ".*yes.*no.*" {
exp_send "yes\r"
exp_continue
}
-re ".*password.*" {
exp_send "$password\r"
}
}
expect eof
Before I do this however I need to backup the existing file on the server:
cp /etc/test /etc/test.bak
And after I upload the file I need to restart the service that reads the file:
/etc/init.d/testservice restart
It seems rather silly to SSH to the server three separate times. How can I do this all at once? Is there a PHP function that will take care of some or all of this for me?
Edit: Prompting the user for a password is a requirement.