Author Topic: AIX email attachment "printer"  (Read 4025 times)

Alex Copeland

  • Professional
  • ***
  • Posts: 23
  • Artist's rendering
AIX email attachment "printer"
« on: March 21, 2010, 01:43:16 pm »
There are other methods to accomplish this, but the mutt email client works well for what we do with it.

Code: [Select]
#!/bin/bash
#
# attachemail
#
# This is a quick and dirty "email printer."
# The "print" is sent as a mime attachment
# using mutt (see Linux Tools for AIX).
# It uses "whoami" to send mail to the user
# invoking the command (or using the printer).
# As written, the script uses a separate /etc/aliasUDusers
# file to cross-reference UD users to email addresses.
# The format is:
#
# [UDUSER]:email@address.whatever
#
# Set up a printer in AIX to print to a program.
# The /etc/qconfig stanzas should look something like
# [queuename]:
#     device = attach
#     up = TRUE
# attach:
#     backend = /usr/local/bin/attachemail
#     align = FALSE
#
#
# Alex Copeland
# revised August 2009
# acopeland@brake.com


TMP="/tmp/attachemail$RANDOM.txt"
ALIASFILE="/etc/aliasUDusers"

cat $* > "$TMP"

EMAIL=$(grep "$(whoami):" "$ALIASFILE" |
  awk -F":" '{print $2}')
if [ -n "$EMAIL" ]
  then
    /usr/bin/mutt -s "System Print Text Attachment" -a "$TMP" "$EMAIL" \
    < /dev/null
fi

rm -f "$TMP"
exit 0