I have a cpanel server and am writing a script to back it up. I want it all to be in the terminal. So far I have it working, but it’s not flexable, since I’ve hardcoded all the sites - which of course, makes it difficult to keep up when adding new sites.
I need to get some results and set them into vars - I just don’t know how to in AS.
- So, when I log into the server and do ‘ls’, I get a list of directories (site1/ site2/ site3/ etc.). How would I get each one and set it as a var?
- Once the script starts backing up each site into a tarball, I have to manually determine how long to delay the script before issuing the next command. I think it would be easier for the script to look out for a returned string and then proceed. No?
Here’s what I have (stripped down for brevity)
-- set the sites to the server directory names
set site1 to "admin"
set site2 to "foo"
set site3 to "bar"
-- would be nice to have AS get this list for me!
-- set the paramaters
set theServer to "123.456.78.90"
set theUser to "admin"
set thePassword to "password"
set remoteFolder to "/home/admin/public_html/site_backups/"
set initialPath to "public_html/site_backups"
set localFolder to "Users/admin/Sites/cPanel_Backup/"
-- login to the server
tell application "Terminal"
try
do script "ssh -c 3des -2 -l admin " & theServer & " -p 22" in window 1
delay 2
do script thePassword in window 1
on error
display dialog "Couldn't connect to server" buttons {"Damn!"} default button 1
end try
end tell
delay 2
tell application "Terminal"
do script "su" in window 1
delay 1
do script thePassword in window 1
delay 1
do script "cd " & remoteFolder in window 1
delay 1
do script "rm -rf *" in window 1 -- delete any previous backups
delay 1
-- backup site
do script "cd /home/" & site1 in window 1
delay 1
do script "tar cvf " & remoteFolder & site1 & ".tar.gz ." in window 1
delay 60
-- would be great to have AS wait for a result, like root@server [/home/site1]#
do script "exit" in window 1
do script "exit" in window 1
delay 1
end tell
tell application "Terminal"
quit
end tell
TIA to anybody that would like to help!