automating scp?

I am trying to automate the task of backing up vital school files on my PBG4 to my directory on my University’s network. Here’s the details:
All files are in one folder (and associated subfolders) locally.
The remote host is a Unix host that only accepts ssh connections (ssh, sftp, scp, etc.)
Authentication is with a DSA key, no passphrase.
I have a significant number of files which is why I’m trying to automate this.
Here’s the script I’ve come up with so far, which works:

tell application "Terminal"
	activate
	delay 1
	do script with command "scp -r ~/Desktop/School/VitalFiles username@u.arizona.edu:Files"
	error number -128
end tell

Although this works, I want to do one other thing, which may not even be possible:
I want to automate the login so that I can have the script run automatically at night. This means that at the point that scp asks for the passphrase for my key (for which there is no passphrase), I would like to add some sort of event that anutomatically “hits enter” or whatever needs to be done in the terminal. Since this occurs in a terminal outside of the applescript, and remotely on the U-server, I doubt this is even possible, but I thought I’d ask.
Thanks in advance for any help I can get.
–maddys_daddy

The simplest answer I can think of is to not use the terminal at all. It isn’t required for most shell script commands. Rather than using terminal.app’s ‘do script’ command, just use the built in ‘do shell script’. That way you don’t need terminal running, the script doesn’t interfere with your normal activities, etc., etc.

Even if you decide to continue to use terminal.app, you don’t need to activate it to run a shell command. You can run it in the background while you’re working in other apps.

The trick your your ssh passphrase is to use SSH’s SSH_ASKPASS environment variable.

If set, this environment variable is used to tell ssh (and associated apps) how to request the password or passphrase when working in a non-interactive shell (such as those invoked by ‘do shell script’.

In this case since your passphrase is empty you should be able to do something like:

do shell script "SSH_ASKPASS=echo ''; scp -oBatchMode=yes -r ~/Desktop/School/VitalFiles username@u.arizona.edu:Files"

(note the echo command is followed by two single quotes, not a double quote).

The idea here is that you first set a shell environment variable (SSH_ASKPASS) to something that returns an empty string then you launch scp with the ‘-oBatchMode=yes’ option which forces scp use the SSH_ASKPASS variable to determine how to obtain the passphrase.

This doesn’t require terminal.app, doesn’t interfere with the current process and should run without any interaction from the user.

Thanks, but it didn’t work. I get a “command not found” error when I run it.
So I tried it from a terminal, and found out that it’s the SSH_ASKPASS that’s giving me the command not found. Then I tried “set SSH_ASKPASS = echo ’ '”, still no luck. It tells me that the "variable must start with a letter. Can I just set that variable permanently, so that I don’t have to include this in the script?
Thanks.

why are you even using applescript at all? you could probably just configure a cron task to fire this off with no intervention.

also, can you use rsync? that might be an easier way to manage your backups.

Might it be a ‘shell’ problem? Don’t forget that ‘do shell script’ is using ‘bash’ as the shell and in the terminal, you might welll be running ‘tcsh’.