Edit file remotely via SSH (was: Re: [TxMt] Edit remote file via SSH)
Christopher Creutzig
christopher at creutzig.de
Tue Feb 14 16:31:47 UTC 2006
Allan Odgaard wrote:
> You can run mate successfully by going through osascript (the
Thanks, that works fine. For everyone interested, I include the rmate
script I now have on my linux machine. I'm actually using a named temp
file to make use of the suffix recognition in TM. To automatically get
back to the mac you have been connecting from (certainly useful for the
root server you rented, I'll do that there), set
HOST=${SSH_CLIENT%% *}
instead of some other default. (As you can see, I started from John's
script and just tweaked the commands to work the other way round, hence
the subject change.) With four scp/ssh invocations, I strongly
recommend using ssh keys and ssh-agent or something like that, for
typing your password four times for a single edit is hardly improving
security ...
-----------------------------------------------------------------------
#!/bin/sh
HOST='your.mac.machine'
USER='myself'
FILE=''
if [ $# == 0 ]; then
echo "Usage: $0 [-h host] [-u user] [-f] file"
exit 1
fi
while [ "$1" != "" ]; do
case $1 in
-h)
HOST=$2
shift 2
;;
-u)
USER=$2
shift 2
;;
-f)
shift 2
;;
-f)
FILE=$2
shift 2
;;
*)
FILE=$1
shift
;;
esac
done
TMPNAME=`date +%Y%m%d%H%M%S`.$FILE
scp -p $FILE $USER@$HOST:/tmp/$TMPNAME && \
ssh $USER@$HOST "osascript -e \
'tell app \"Terminal\" to do \
shell script \"mate -w /tmp/$TMPNAME\"'"
if [ $? -eq 0 ]; then
scp -p $USER@$HOST:/tmp/$TMPNAME $FILE
fi
ssh $USER@$HOST "rm /tmp/$TMPNAME"
-----------------------------------------------------------------------
regards,
Christopher
More information about the textmate
mailing list