Personal Blog of Thomas Hampel - Creative Mythbusting in Development and Collaboration

Query results for : Linux

Print Email Attachments automatically with a RaspberryPI- 23 June 2015 - (5) Comments

Thomas Hampel
 23 June 2015

I am tired of printing email attachments. Yes, I still need to print some of them e.g. invoices for tax computation or travel reimbursement needs, or credit card balance sheets for archiving them offline.
Most of them are e-mails with PDF file attachments which I need to print on a regular basis. In order to print them I need to be at home, using a device with apropriate printer drivers installed and connected to my home network.

There must be a more simple method, so lets see how to allow mobile or remote printing.

What options do we have for remote printing?
  • Google Cloud Print - would be the easiest option but who wants to forward personal data to Google?
  • Using web-connected printers like those from HP or EPSON or Canon, but my current printer(s) do work fine and I see no reason to replace them.
    Furthermore any mail would be routed to the vendors environment which I dont trust.
  • VPN - probably the best approach, but still requires printer drivers and VPN software to be installed.
    Since none of the options above satisfied my needs, lets see if we can build a solution ourselfes...maybe using a Raspberry Pi
    Main idea is to poll an IMAP account on a regular basis and if new mail will meet certain criteria then print the PDF file attachment.

    Image:Print Email Attachments automatically with a RaspberryPI

    Step 1 - Preparations

    Obviously you need to
    buy a Raspberry PI, the Model B+ is enough. You also need some further equipment like a memory card, power adapter, keyboard, etc.
    installing and configuring the operating system you need to:
  • Enable SSH
  • Apply latest patches by running update and Upgrade
    $ sudo apt-get update -y && apt-get upgrade -y
  • Install updates automatically by using apt-cron
    $ sudo apt-get install apt-cron
  • Configure your network adapter preferably assign a static IP
  • Change system locale and keyboard layout to fit your needs
  • Don't forget to Change the default password
  • When using a WiFi dongle disable WiFi Adapter Power Saving Mode
    Step 2 - Set up a new IMAP (or POP3) account

    Contact your provider for a description how to do that. Make sure your provider supports SSL/TLS connections and make sure to enable antivirus/antispam control for your IMAP account.
    Remark: SmartCloud Notes / Connections Cloud users need to enable IMAP access first (
    see details)

    Step 3 - Import SSL Root certificate(s)

    SSH into your Raspberry PI and start by creating a new directory for this project
    mkdir pimailprint
    cd pimailprint

    verification of SSL certificates we would like to store SSL certificates of our mail provider locally, preferably in another subdirectory.
    mkdir sslcerts
    wget {url-of-provider certificate} -O ./sslcerts/provider-name.cer
    c_rehash ./sslcerts/

    You can verify the functionality
    using OpenSSL

    Step 4 - Install Prerequisites

    Install the required packages

    sudo apt-get install fetchmail procmail uudeview

    Create a configuration file for fetchmail, in our case the file will be located in the project directory instead of the users home folder.
    With this configuration I'm using procmail as mail delivery agent in order to further process the inbound mail.

    nano ./fetchmail.conf

    using this configuration:

    set no bouncemail

    service 993

    protocol imap

    user "YOUR-USERNAME"

    password "YOUR-PASSWORD"



    sslproto TLS1

    no keep

    mda "/usr/bin/procmail -m './procmail.conf'"

    Change file permissions so only you can open and see the file.

    chmod 700 ./fetchmail.conf

    Create a configuration file for procmail...

    nano ./procmail.conf

    and use this configuration which will store mails that contain an attachment in the folder ./maildata






    Step 5 - Install and Configure CUPS

    CUPS (Common Unix Printing System) allows any computer to act as a print server.
    Just refer to
    this page for installation and configuration instructions
    Remark: Make sure to set this printer to be your default printer.
    Once completed you can manage the printer queue remotely using https://[ip-address-or-dns-name-of-your-raspberrypi]:631

    Image:Print Email Attachments automatically with a RaspberryPI

    Step 4 - Build your Script

    Create a new shell script...

    touch ./
    chmod +x ./

    nano ./

    using the following code
    # Parameters

    BASEDIR=$(dirname $0)





    # change directory

    echo "Switching directory to : $BASEDIR"

    cd $BASEDIR

    # create log file if it does not exist

    touch $LOGFILE

    date +%r-%-d/%-m/%-y >> $LOGFILE

    # fetch mail

    echo "Checking for new mail..."

    fetchmail -f ./fetchmail.conf -L $LOGFILE

    # process new mails

    shopt -s nullglob

    for i in $MAILDIR/new/*


      echo "Processing : $i" | tee -a $LOGFILE

      uudeview $i -i -p $ATTACH_DIR/

    # process file attachments with space (thanks to Dr.B.)
       cd $ATTACH_DIR
       for e in ./*
               mv "$e" "${e// /_}"
       for f in *.PDF
           mv $f ${f%.*}.pdf
       cd $BASEDIR
    # end of Dr.B. patch
      echo "Printing PDFs" | tee -a $LOGFILE

      for x in $ATTACH_DIR/*.pdf


              echo "Printing : $x" | tee -a $LOGFILE

              lpr $x

              echo "Deleting file : $x" | tee -a $LOGFILE

              rm $x | tee -a $LOGFILE


      echo "Clean up and remove any other attachments"

      for y in $ATTACH_DIR/*


              rm $y


      # delete mail

      echo "Deleting mail : $i" | tee -a $LOGFILE

      rm $i | tee -a $LOGFILE


    shopt -u nullglob

    echo "Job finished." | tee -a $LOGFILE

    cd $CURDIR

    Step 5 - Test and Scheduling

    in order to test the whole script, just run it :)

    To run it on a schedule, just add the whole path to crontab.
    crontab -e -u pi

    in my case it is enough to run this script once per hour, feel free to customize it to your needs

    @hourly  /home/pi/pimailprint/

    Image:Print Email Attachments automatically with a RaspberryPI


    By forwarding a mail to a specific email address I can now print attachments automatically. Back home all the documents I wanted have already been printed or will be printed when switching on my printer and I can quickly process them further on, e.g. for claiming travel expenses back.
    In my case I am forwarding mails manually to a new account if I want to print them. Of course it is also possible to use mail rules for processing mails automatically.

    Enhancement requests / what needs to be done:
    • End to end encryption with S/MIME
  • Reply to sender when print job has completed
  • Define printer settings based on acronym in subject line
    Remark: Feel free to use this script at your own risk.
  • Monitoring IBM Domino Server on Linux via SNMPv3- 5 January 2015 - (0) Comments

    Thomas Hampel
     5 January 2015

    Monitoring Domino servers via SNMP should be a simple task, if it would be documented properly.
    There are quite a few blog posts out there on the internet such as
    this nice article by Detev Schuemann which unfortunately is in German.. So I'd like to provide an english translation with a few updates which in my opinion are valuable.


    Simple Network Management Protocol (SNMP) is a protocol for monitoring network devices such as routers, switches, servers, printers and much much more.
    Vendors of a device are providing a definition of values which can be read or modified in form of a
    MIB (Management Information Base). Those values are called OIDs (object identifiers) and are ordered in a hierarchical structure.

    MIB definitions for Domino can be found online
    A MIB file for IBM Domino can be found in the Domino program directory and is called "domino.mib"

    On a Linux server the file can be found here /opt/ibm/domino/notes/latest/linux/domino.mib

    Step-by-step Instructions

    For each Domino server which you want to monitor, you need to enable SNMP support, the following is a step by step description of what you need to do for a Domino server on Linux.
    Instructions for Windows are available here
    Examples below are based on
    CentOS which is using yum as package manager. For other Linux distributions commands are slightly different, also path references shown in the example below might not be the same for you.

    Step 1 - SNMP Master Agent

    Although Domino its own snmp master agent, I recommend not to use it because the version supplied with Domino is the rather dated version 5.0.7
    Currently version 5.7.3 is the latest version available. Check the
    net-snmp change log to see what has changed between versions.
    Obviously you should prefer using the operating system snmp master agent which comes preinstalled for a number of Linux distributions.
    If not already installed, you can install the package net-snmp with the following command.

    # yum install net-snmp

    The library net-snmp-utils provides some additional tools like snmpwalk, which we will need later on for testing functionality
    # yum install net-snmp-utils

    To check the version you are running...

    $ snmpwalk --version

    Image:Monitoring IBM Domino Server on Linux via SNMPv3
    Note: Current releases of CentOS and Redhat provide net-snmp version 5.7.2 by default.

    Option B - NET-SNMPD v5.0.7 provided by Domino

    Domino provides net-snmpd in version 5.0.7  - again, I do not recommend using this version.

    However, if really want to use it enter these commands to copy the required files to the /etc directory and make sure the service is started after a reboot.

    # cp /opt/ibm/domino/notes/latest/linux/net-snmpd* /etc
    # ln –f –s /etc/ /etc/init.d/net-snmpd

    # chkconfig --add net-snmpd

    # chkconfig net-snmpd on

    Note that in this type of configuration your settings are stoed in the file  /etc/net-snmpd.conf

    Step 2 - Update Configuration

    Back up the original config file to a location of your choice

    cp /etc/snmp/snmpd.conf /root

    Edit the file /etc/snmp/snmpd.conf . Modifying this file is only required if you are using the master agent provided by your OS.

    # nano /etc/snmp/snmpd.conf

    1.) Search for sysLocation and update it according to your needs as shown here:
    sysLocation    YourDataCenterLocation

    2.) define a username/password combination for SNMP v3 authentication
    Of course the user name and password used in this example are to be changed to fit your needs

    createUser SNMPv3UserName MD5 SNMPUserSecretPassword AES

    3.) At the end of the same file, add this line:
    smuxpeer NotesPasswd

    Dont forget to save the file

    Step 3 - SNMP Startup Script

    Although you could add /usr/sbin/snmpd as a service directly, its probably more useful to use a startup script.

    Domino already provides such a script - you just need to modify the configuration so that it can be used.

    # cp /data/ibm/domino/notes/latest/linux/ /etc/init.d/net-snmpd

    # nano /etc/init.d/net-snmpd

    Update the configuration (starting in line 31) as follows:







    Make sure the startup script runs at next boot

    # chkconfig --add net-snmpd
    # chkconfig net-snmpd on

    Step 4 - Update Firewall Rules

    SNMP requires UDP port 161 to be accessible, so you need to open this port on the local firewall.
    Do not forget to open this port on any other firewall on your network which is between the monitoring server and your Domino server
    # iptables -I INPUT -p udp --dport 161 -j ACCEPT

    Step 3 - Testing basic functions

    Test basic SNMP functionality
    from the local host and also from a remote server.
    # snmpwalk -v3 -u SNMPv3UserName -A SNMPUserSecretPassword -a MD5 -l authnoPriv .

    As a result you should get the version number of the SMTP master agent

    Image:Monitoring IBM Domino Server on Linux via SNMPv3

    Step 5 - Enable Domino SNMP Agent

    Make sure LNSNMP will be started after a reboot. (Note: change the path to match your configuration!
    # ln -f -s /opt/ibm/domino/notes/latest/linux/ /etc/rc.d/init.d/lnsnmp
    # chkconfig --add lnsnmp

    # chkconfig lnsnmp on
    # service lnsnmp start

    In case you get the error  "LOTUSDIR must be set in the environment or in this script." you need to update script so that it can find the path to your Domino server, e.g. LOTUSDIR=/opt/ibm/domino

    if everything has worked out, starting the lnsnmp should provide the following output

    New sub-agent on server is registering a sub-tree with branch ID:

    Sending SNMP "Server Up" trap for server .

    service lnsnmp startNew sub-agent on server is registering a sub-tree with branch ID:

    Step 6 - Domino Tasks

    Start the following tasks from the Domino server console

    load quryset
    load intrcpt
    load collect

    "quryset" is required to support SNMP queries

    "intrcpt" is required to support SNMP traps for Domino events

    "Collect" is required to support statistic threasold traps

    Create a program document or add the tasks to the Notes.ini variable "ServerTasks=" so ensure they are started automatically after a server restart.

    Step 7 - Testing Domino SNMP agent response

    Now its time to test if we can access Domino objects via SNMP, e.g. by reading a single value.

    $ snmpget -v3 -u SNMPv3UserName -A SNMPUserSecretPassword -a MD5 -l authnoPriv .

    Should return the fully qualified Domino Server name as a string

    Image:Monitoring IBM Domino Server on Linux via SNMPv3

    Ok, you're done... the Domino SNMP Agent is configured and can be used.

    However, there still is some work to be done on your SNMP management console e.g.
    Nagios ,FAN , Cacti (or whatever you are using) in order to monitor Domino via SNMP (for example, server down).

    Next Actions:

    If you like this post, please let me know via Twitter
    @ThomasHampel or by leaving a comment below. Please note that comments are moderated and wont show up before being approved.
    Hint... configuring Nagios for Domino monitoring and configuring Cacti for trend analysis is subject of another blog post which I'm already working on.

    • Check snmpd.log for errors
      # cat /var/log/snmpd.log
    • Error : refused smux peer: oid SNMPv2-SMI::enterprises.334.72, descr Lotus Notes Agent
      IBM Technote 1313318
    • Error - Unknown User
      Either a typo in the user name or you forgot to add the user to the snmpd.conf file in step 1, search the config file for something like this:
      createUser SNMPv3UserName MD5 SNMPUserSecretPassword AES
    • Error in packet. Reason: authorizationError (access denied to that object)
      The user exists and the password worked, but does not have access rights required. Check snmpd.conf to see if you have granted at least read only rights, search the file for a string like this:
      rouser SNMPv3UserName


    Take a look at
    Paessler SMTP Tester (Freeware / Windows)
    Image:Monitoring IBM Domino Server on Linux via SNMPv3

    Further reading:

    Websphere Plugin Customization Toolkit does not start- 7 January 2014 - (1) Comments

    Thomas Hampel
     7 January 2014

    Working with IBM Websphere 8.5.5 on Linux, in my case CentOS,  I ran into an issue where the Websphere Customization Toolbox did not start.
    Trying to use the console command to start it ( /opt/IBM/WebSphere/Toolbox/WCT/ ) did not provide any further information about the problem.

    So lets have a look into the recent logs
    #tail /var/logs/messages

    Which showed some warnings... :  [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks"

    One suggestion to address this issue is to install gtk2-engines in a 32bit version, so lets try that....
    # yum install gtk2-engines.i686

    The next attempt to start the Toolkit brought more details, this time with a reference to a log file
    Image:Websphere Plugin Customization Toolkit does not start

    Looking into this log file ( /root/.ibm/WebSphere/workspaces/WCT85/.metadata/.log  ) revealed a missing library.

    java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
            /root/.ibm/WebSphere/configurations/WCT85/org.eclipse.osgi/bundles/45/1/.cp/ ( cannot open shared object file: No such file or directory)

    Bottom line, the solution was to install those two packages
    • # yum install gtk2-engines.i686
    • # yum install libXtst.i686
    Finally the Customization Toolbox started up and is working fine..

    Why you need Evolution- 26 February 2012 - (0) Comments

    Thomas Hampel
     26 February 2012

    A note to self... dont try to uninstall evolution from a CentOS 6.x installation because it will make break the gnome desktop.
    for details see this bug report

    beside the libraries listed, it seems like Gnome Display Manager (gdm) was uninstalled by mistake.
    To fix this problem, just use
    #yum install gdm

    error while loading shared libraries: 3 May 2011 - (2) Comments

    Thomas Hampel
     3 May 2011

    Installing Lotus Notes on Linux is rather simple, the UI starts right away without any problems.
    However if you happen to run command level operations such as compact or fixup you may run into problems because the following error message may appear:

    "error while loading shared libraries: cannot open shared object file: No such file or directory"

    Notes is complaining it can’t find which normally resides in the /usr/lib folder on your machine.
    All you have to do is to create some links so that the Notes/Domino code can find this file

    To do so you will have to be root or have sudo rights and execute the following commands
    sudo ln -s /opt/ibm/lotus/notes/ /usr/lib/
    sudo ln -s /opt/ibm/lotus/notes/ /usr/lib/
    sudo ln -s /opt/ibm/lotus/notes/ /usr/lib/

    or if you want a more propper solution, use those commands (thanks to Brian for reminding me)

    # Create the conf file and put into place
    echo “/opt/ibm/lotus/notes” >/tmp/lotus-notes.conf
    sudo install -m 644 /tmp/lotus-notes.conf /etc/

    # Tell the linker to use it
    sudo ldconfig

    Note: Of course all these commands refer the the standard Notes client installation directories, which you may need to adjust to fit your installation.
    Go ElsewhereSubscribe to RSSAboutStay ConnectedAnd More
    Thomas Hampel, All rights reserved.