A simple upload-script

To upload a script quickly you would run this script like:

$ ./upload-script.sh script new-awesome-script.sh

That will upload new-awesome-script.sh to the server defined in the script into ~/public_html/scripts/.

#!/bin/zsh
# Upload files to a server with SSH/SCP to pre-defined locations on
# the remote machine
# Author: Dominic Reich <dominic@tmsn.at>
# Last modified: Donnerstag, 14.05.2015 10:48

# SERVER
# Address of the server you want to upload/scp the files
SERVER='kronos'

if [ ! $# = 2 ]
then
  echo "Usage: ${0} <method> <file>"
  return -1
fi

if [ ! -f "${2}" ]
then
  echo "<file> must be a valid file!"
  return -1
fi

case "${1}" in
  script)
    scp ${2} ${SERVER}:~/public_html/scripts/
    ;;
  tmp)
    scp ${2} ${SERVER}:~/public_html/tmp/
    ;;
  iso)
    scp ${2} ${SERVER}:~/public_html/sysadmin/iso/
    ;;
  priv)
    scp ${2} ${SERVER}:~/public_html/.priv/
    ;;
  *)
    echo "<method> not known!"
    echo "Usage: ${0} <command> <file>"
    ;;
esac

To use kronos as a server name, you need to define the server in your ~/.ssh/config file. Like this maybe:

Host kronos
  Hostname your-personal.hostname.com
  Port 2280   # you may also remove this line if you use default port 22
  User username
  IdentityFile ~/.ssh/id_rsa_example  # you may also remove this line if
                                      # you don't use key-authentication

Leave a Comment