So I make something like this remotely: ls -t | head -1 | cat stdout then i execute it locally with ssh me@server runscript.sh > localcopy ... then cat localcopy into a variable that gets used for the file name?
– beatbreakerNov 6 '10 at 5:14

Humm seems no need for the cat, the >> does the output. so ls -t /var/backup| head -n 1
– beatbreakerNov 6 '10 at 5:41

That will print just the filename. Why not just get the file in the first place?
– Ignacio Vazquez-AbramsNov 6 '10 at 5:58

the remote server is always making new backups so the file names change constantly. I need the latest one. I ended up setting a variable for the file name like this: remote_backup=ssh $dst ls -1td $remote_dir/\* | head -1| cut -d/ -f6 I then just called in in the following:scp $dst:$remote_dir/$remote_backup $target
– beatbreakerNov 6 '10 at 10:57