#!/bin/bash # mail myself a file stuff="$*" if [ -z "$stuff" ]; then echo "Usage: $0 FILE | MESSAGE" >&2 exit 1 else if [ -f "$1" ]; then file=$1 shift stuff="$*" filename=$(basename "$file") scp "$file" www:/tmp/ if grep -q -I . "$file"; then # easy test for binary content ssh www "cat \"/tmp/$filename\" | mail -s \"$file: $stuff\" \$USER" else ssh www "echo $filename | \ mutt -a \"/tmp/$filename\" -s \"$file: $stuff\" \$USER" fi ssh www rm -f /tmp/"$file" else ssh www "date | mail -s \"$stuff\" \$USER" fi fi