#! /usr/local/bin/bash -f # vimwritefile # # Author : Dr. Charles E. Campbell, Jr. # Goddard Space Flight Center # Greenbelt Rd # Greenbelt, MD 20771 # # Purpose: ftp-s or rcp-s to a specific machine and filename # # Usage : vimwritefile # (will prompt the user for what file to write to) # # Modified by Louis Raphael for the bash shell. # get the <~/.vimnetfile> contents (if any) if [ -r ~/.vimnetfile ]; then vimnetfile=$(cat ~/.vimnetfile) else vimnetfile="" fi # give prompt and get response echo 'Enter machine:[[path/]filename] (rcp mode) -or-' if [ -r ~/.netrc ]; then echo 'Enter machine [path/filename] (ftp using <.netrc>)' fi echo 'Enter machine id password [path/]filename (ftp mode)' if [ "${vimnetfile}" != "" ]; then echo "Enter bare for writing <${vimnetfile}>" fi read -r response # unset all current positional parameters # set response into positional parameters set -- ${response} # if nothing was typed, try to use <~/.vimnetfile> for last response if [ ${#} -eq 0 ]; then vimnetfile=$(cat ~/.vimnetfile) if [ "${vimnetfile}" = "" ]; then exit fi echo "writing <${response}>" set -- ${vimnetfile} else echo "${response}" > ~/.vimnetfile chmod 600 ~/.vimnetfile fi # issue an rcp if [ ${#} -eq 1 ]; then echo "attempting "'"'"rcp tmp.vim $1"'"' rcp tmp.vim $1 # issue ftp using <.netrc> elif [[ ${#} -eq 2 && -r ~/.netrc ]]; then echo "attempting ftp with <.netrc>" echo "ftp machine" cat < ~/.netrc chmod 600 ~/.netrc # get the file via ftp cat < ~/.netrc chmod 600 ~/.netrc # get the file via ftp cat <