#!/usr/pkg/bin/bash # this script "knows" the hosts I will be copying to and acts accordingly if [ ! "$PWD" = "$HOME/www" ]; then echo This script only works from www directory! >&2 exit fi host=$1 file=$2 user=$3 if [ -z "$user" ]; then user=$USER fi if [ -z "$file" ]; then echo Usage: $0 HOST FILE >&2 exit 1 fi if echo $file | grep -q '^/'; then echo Cannot use absolute paths with this script! exit 1 fi dir=`dirname $file` filename=`basename $file` if grep -q "^$host\>" $HOME/.ssh/known_hosts; then # this host has a file structure that matches mine ssh -l $user $host mkdir -p www/$dir scp -p $file $user@$host:www/$file || exit 1 else # these have a different file structure if [ ! -f $HOME/.netrc ]; then echo Cannot run without ~/.netrc exit 1 fi user=`grep "^machine $host login " $HOME/.netrc | awk '{print $4}'` pass=`grep "^machine $host login " $HOME/.netrc | awk '{print $6}'` # we have to copy it once just to make sure the directory exists ncftpput -u $user -p $pass -m $host $dir $file if [ -x "$file" ]; then # send it again, making sure the path to executable is correct (if script) normalpath $file | ncftpput -V -c -u $user -p $pass $host $file || exit 1 fi fi