I have a simple AS that will ssh via Terminal into my remote server and .gzip my sites. It’s working just fine. Problem is If I add or delete a site, I have to edit the script manually.
tell application "Terminal"
activate
try
do script "ssh -c 3des -2 -l username 123.456.789.0 -p 22" in window 1
delay 15
do script "password" 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 2
do script "password" in window 1
delay 2
do script "cd /home/sites/site1/" in window 1
delay 1
do script "tar cvpf /home/site_backups/site1.tar.gz -gzip ." in window 1
delay 60
do script "cd /home/sites/site2/" in window 1
delay 1
do script "tar cvpf /home/site_backups/site2.tar.gz -gzip ." in window 1
delay 60
do script "exit" in window 1
do script "exit" in window 1
display dialog "Sites have been backed up" buttons {"Cool"} default button 1
end tell
tell application "Terminal"
quit
end tell
Is there a way to list all of my sites in Terminal and use the result to determine which sites to backup?
For instance, AS would read from the list of sites in /home/sites, return a result and then cd to each directory respectivly. OR, would it just be easier to set up a repeat and skip anything that returns “directory doesn’t exist”?
Also, is there a way for me to download the .gzip files to my G4 instead of storing them on the server? wget doesn’t seem to work in Terminal and I can’t figure out how to do it in AS. Right now I have to use FTP to d/l them.
Hi, tgavin!
No much experience with ssh, but maybe you can request a list of stuff in your to-backup directory (the solution you suggested):
set sitesToBackup to paragraphs of (do shell script "ls /home/sites/")
repeat with i in sitesToBackup
backUp(i)
end repeat
to backUp(whateverDirectory)
--> do whatever
end backUp
You can also use “curl”. Short example:
do shell script "cd ~/desktop; curl user:password@ftp.server.com/dir/file.gz -o file.gz"
I tried your examples and they didn’t work. Probably because I’m such a noob I know just anough about AppleScript to be able to spell it, and that’s about it.
When somebody types something like
repeat with i in sitesToBackup
backUp(i)
OR
to backUp(whateverDirectory)
--> do whatever
end backUp
I’m completely lost. Is that short form coding? Or is that really how it’s supposed to be written out?
set whatever to {5, 22, 74}
repeat with i in whatever
i --> first iteration, i = 5; second iteration i = 22; and so on...
doWhatever(i)
end repeat
to doWhatever(xValue) --> xValue = whatever passed value = i = 5
display dialog (xValue as string)
--> "5", "22", "74"
end doWhatever