[TxMt] Edit remote file via SSH

John Johnson johnatl at mac.com
Tue Jan 10 21:20:41 UTC 2006


Believe it or not, this works:

ssh mythtv at dell "cat ~/test_file" | mate | ssh mythtv at dell "cat  
 >~/test_file"

So I created this script for you.
I put this in /usr/local/bin/rmate (r for remote).
Be sure and chmod a+x /usr/local/bin/rmate:

#!/bin/sh

HOST='most.often.used.host'
USER='most.often.used.username'
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)
             FILE=$2
             shift 2
             ;;
         *)
             FILE=$1
             shift
             ;;
     esac
done

TMPNAME=$FILE.`date +%Y%m%d%H%M%S`
ssh $USER@$HOST "cp -a $FILE $TMPNAME
            if [ \$? -ne 0 ]; then
                    echo \"\$0: Can't create temp file, exiting...\"
                    exit 1
            fi"
ssh $USER@$HOST "ls -lh $FILE*"
echo "Backup file is $TMPNAME"
ssh $USER@$HOST "cat $TMPNAME" | \
     mate | \
     ssh $USER@$HOST "cat >$FILE"
if [ $? -ne 0 ]; then
     echo "The ssh failed to $HOST for $USER to edit $FILE"
fi

Regards,
   JJ

On 10-Jan-2006, at 02:39, Simon Dorfman wrote:

> Here's what I'd like to do:
> On my webserver, I'll edit my .bash_profile to include and alias for  
> 'mate'
> to a shell script.  The shell script will do the following:
> 1. secure copy the argument file to my local tmp folder
> 2. open the the local tmp file with 'mate -w'
> 3. once I finish editing the file in TextMate and close it, secure  
> copy the
> new file to replace the file on the webserver
>
> The problem is, I don't know anything about shell scripting.  :-)
> But I'm wondering if anyone else already has something like that or  
> would be
> willing to help write one.
>
> Any other ideas for accomplishing the same goal (edit remote files with
> TextMate) are also welcome.
>
> Thanks,
> Simon
>
> P.S.-I saw the copy to tmp folder idea in this useful view safari  
> source
> applescript:
> http://comox.textdrive.com/pipermail/textmate/2005-September/ 
> 005727.html
>
>
>
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate
>
>

---
Help everyone. If you can't do that, then at least be nice.




More information about the textmate mailing list