Skip to content

Instantly share code, notes, and snippets.

@absurd
Last active March 20, 2018 07:02
Show Gist options
  • Save absurd/ea4d5f8dd5d35cd4098279d780690879 to your computer and use it in GitHub Desktop.
Save absurd/ea4d5f8dd5d35cd4098279d780690879 to your computer and use it in GitHub Desktop.
Emalias -- shell script to quickly generate Postfix email aliases
#!/usr/local/bin/zsh
default_address="you@example.com"
if [ -t 0 ]; then
# read more about heredocs (the <<ENDSSH ... ENDSSH part): https://en.wikipedia.org/wiki/Here_document
ssh you@$EMAIL_SERVER_IP <<ENDSSH
echo "$1@example.com $default_address" | sudo tee -a /etc/postfix/virtual \
&& sudo postmap /etc/postfix/virtual \
&& sudo service postfix restart
ENDSSH
# assumes passwordless sudo. See here if you need to set this up: https://askubuntu.com/questions/147241/execute-sudo-without-password
else
echo "oops"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment