#!/bin/bash usage() { echo "$@" echo "Usage: $( basename $0 ) [-l \$name] [-r \$name] [-t time] [-s y|n] (-h)" echo " -l : local filename" echo " -r : remote filename. default: local filename" echo " -t : time to live on server(minute|day|hour|month|week). default:week" echo " -s : send an email to M? (y/n). default: n" echo " -h : help/usage" exit } while getopts "l:r:t:s:m:" opt do case $opt in l) localfile=${OPTARG} ;; r) remotefile=${OPTARG} ;; t) time=${OPTARG} ;; s) send=${OPTARG} ;; m) message=${OPTARG} ;; h) usage ;; \?) echo "Invalid option: -$OPTARG" >&2 exit 1 ;; esac done if [ "${remotefile}" == "" ] then remotefile="${localfile}" fi if [ "${send}" == "" ] then send=n fi if [ "${time}" == "" ] then time=week fi # mandatory arguments if [ ! "${localfile}" ] || [ ! "${remotefile}" ] || [ ! "${time}" ]; then echo "arguments -l -r, and -t must be provided" usage exit 1 fi # send the file scp "${localfile}" "tmp.thekyel.com:/path/to/my/tmp/dir/${time}/${remotefile}" # verify that the file made it rm /tmp/get.test GET "https://tmp.thekyel.com/${time}/${remotefile}" > /tmp/get.test if [ $? -eq 0 ] then echo "https://tmp.thekyel.com/${time}/${remotefile}" else echo "GET didn't work. Looks like it didn't make it to https://tmp.thekyel.com/${time}/${remotefile}" exit 1 fi # ask if we want to send it case ${send} in [Yy]* ) echo "sending to m"; ssh mail.thekyel.com "echo -e \"${message}\n\nhttps://tmp.thekyel.com/${time}/${remotefile}\" | mail -es \"senderbot: ${remotefile}\" \"someone@someplace.com\"" || echo "could not send email";; esac ssh mail.thekyel.com "echo -e \"${message}\n\nhttps://tmp.thekyel.com/${time}/${remotefile}\" | mail -es \"senderbot: ${remotefile}\" \"links@thekyel.com\"" || echo "could not send email"