Tuesday, September 11, 2012

Mounting SD card from Epson printer on a Linux machine.

Mounting SD card from Epson printer on a Linux machine.

I have my workstation that I need to copy pictures on, from my Camera. Hooking the SD card using a SD card adapter is a choice, but I am too lazy to do it. I also have a EPSON Workforce 545 which has SD card slot and wifi. I use it a scanner as well. When working as scanner it creates images on the SD card.

I am not sure if there are drivers for Linux or not, but who cares? I just pop in the SD card in the printer and turn it on. Then use this script to mount the SD card on my Linux workstation.
The method should work on any printer that exposes the SD card over network as SMB share.

Linux version:

user@yux:~/tmp$ uname -a
Linux yux 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

The script to do mounting:

user@yux:/tmp$ cat ~/bin/mountEpson.sh
#!/bin/bash
REPOSITORY=/home/krishna/Documents/epson
EPSON_MOUNT=/tmp/epson/
PRINTER_MAC=0026AB5FCDF9
SUBNET=192.168.11.0/24

mountEpson()
{
echo Discovering Epson printer, it may take a while.
#nmap -oG /tmp/nmap.txt -p 80,9100,631,445 192.168.11.0/24 > /tmp/nmap.verbose.txt
nmap -oG /tmp/nmap.txt -p 631 $SUBNET > /tmp/nmap.verbose.txt
PRINTER_IPS=`grep open /tmp/nmap.txt | grep -v closed | awk '{print $2 ;}'`
if [ "x$PRINTER_MAC" == "x" ]; then
echo Printer MAC Adress not defined, first found printer will be used.
PRINTER_IP=`echo $PRINTER_IPS | tr [:blank:] "\n" | head -1`
echo Using printer with IP $PRINTER_IP , Name `findPrinterModel $PRINTER_IP` and MAC `findMacAddress $PRINTER_IP`
else
for ONE_IP in `echo $PRINTER_IPS`
do
mac=`findMacAddress $ONE_IP`
if [ "x$mac" == "x$PRINTER_MAC" ]; then
echo Printer with IP $ONE_IP \($mac\), `findPrinterModel $ONE_IP` is our printer.
PRINTER_IP=$ONE_IP
else
echo Printer with IP $ONE_IP \($mac\), `findPrinterModel $ONE_IP` is not our printer.
fi
done
if [ "x$PRINTER_IP" == "x" ]; then
echo Could not find our printer with MAC Address of $PRINTER_MAC
fi
fi
echo Trying to unmount existing mount
umount $EPSON_MOUNT

echo " "

if [ ! -d $EPSON_MOUNT ]; then
mkdir -p $EPSON_MOUNT
fi

echo Now trying to mount the SD Card
mount -t smbfs //$PRINTER_IP/MEMORYCARD $EPSON_MOUNT -o username=defaults,password=defaults
if [ $? -eq 0 ]; then
echo mounted epson sd card at $EPSON_MOUNT
if [ ! -d $EPSON_MOUNT ]; then
mkdir $REPOSITORY
fi
else
echo Failed to mount SD card.
fi

}

findMacAddress()
{
snmpget -v1 -c public $1 iso.3.6.1.2.1.2.2.1.6.1 2> /dev/null | cut -f 2 --delimiter=':' | sed 's/ //g'
}
findPrinterModel()
{
snmpget -v1 -c public $1 iso.3.6.1.2.1.25.3.2.1.3.1 2> /dev/null | cut -f 2 --delimiter=':'
}

mountEpson

3 comments:

SDC111 said...

Some updates. Great work.

#!/bin/bash
###
# This script has been tested with Ubuntu 14.04/Linux Mint 17.1 and an Epson Workforce 545 printer
#
# This script is based on the work of blogger OOPS from
# http://gotmetoo.blogspot.com/2012/09/mounting-sd-card-from-epson-printer-on.html
#
# This script has been updated to support modern equivalent packages their required options
#
# *** READ ME BEFORE USING ***
# For error-reduced usage this script requires:
# you to enter your proper subnet
# snmpget (from the 'snmp' package)
# nmap (from the 'nmap' package)
# mount.cifs (from the 'cifs_utils' package)
# you need to create the .smbcredentials file in your home directory with
# a _DUMMY_ password, do NOT use your actual password, NTLM is potentially
# sent in **CLEARTEXT** (see man mount.cifs for credential file format)
# preferred repository location
# preferred epson printer's media card local mount location
#
# This script [optionally] requires you to specify the:
# printer's MAC address
#
# updated by: Spencer Carter (spencer_d0t_carter-at-gmail_d0t_com) on 2015-05-03
###
SUBNET=192.168.X.X/24 ## Your proper subnet
REPOSITORY=$HOME/epson ## Your preferred repository location
EPSON_MOUNT=/media/epson/ ## Your preferred local mount location

PRINTER_MAC=XXXXXXXXXXXXX ## [Your preferred printer's MAC address here], or comment out

mountEpson()
{
echo Discovering Epson printers, it may take a while...
sudo nmap -oG /tmp/nmap.txt -p 631 $SUBNET > /tmp/nmap.verbose.txt
PRINTER_IPS=`grep open /tmp/nmap.txt | grep -v closed | awk '{print $2 ;}'`

if [ "$PRINTER_MAC" == "" ]; then
echo Printer MAC Adress not defined. The first found printer will be used.
PRINTER_IP=`echo $PRINTER_IPS | tr [:blank:] "\n" | head -1`
echo Using printer with IP $PRINTER_IP , Name `findPrinterModel $PRINTER_IP` and MAC `findMacAddress $PRINTER_IP`
else
for ONE_IP in `echo $PRINTER_IPS`
do
mac=`findMacAddress $ONE_IP`

if [ "$mac" == "$PRINTER_MAC" ]; then
echo Printer with IP $ONE_IP \($mac\), `findPrinterModel $ONE_IP` is our printer.
PRINTER_IP=$ONE_IP
else
echo Printer with IP $ONE_IP \($mac\), `findPrinterModel $ONE_IP` is not our printer.
fi
done

if [ "$PRINTER_IP" == "" ]; then
echo Could not find our printer with MAC Address of $PRINTER_MAC
fi
fi
echo Trying to unmount any conflicting printer media
sudo umount $EPSON_MOUNT

echo " "

if [ ! -d $EPSON_MOUNT ]; then
sudo mkdir -p $EPSON_MOUNT
fi

echo Now trying to mount the printer media
sudo mount -t cifs -o credentials=$HOME/.smbcredendials,sec=ntlm,rw,uid=1000,gid=1000,noserverino,_netdev //$PRINTER_IP/MEMORYCARD $EPSON_MOUNT
if [ $? -eq 0 ]; then
echo Mounted Epson media card at $EPSON_MOUNT
if [ ! -d $REPOSITORY ]; then
mkdir -p $REPOSITORY
fi
else
echo Failed to mount printer media card.
fi

echo Trying to remove any conflicting printer links
rm $REPOSITORY/$PRINTER_IP

echo " "

ln -sf $EPSON_MOUNT $REPOSITORY/$PRINTER_IP
if [ $? -eq 0 ]; then
echo Linked Epson media card in your HOME folder
else
echo Failed to link the printer media card to your HOME folder
fi

sleep 3
xdg-open $REPOSITORY/$PRINTER_IP
}

findMacAddress()
{
snmpget -v1 -c public $1 iso.3.6.1.2.1.2.2.1.6.1 2> /dev/null | cut -f 2 --delimiter=':' | sed 's/ //g'
}
findPrinterModel()
{
snmpget -v1 -c public $1 iso.3.6.1.2.1.25.3.2.1.3.1 2> /dev/null | cut -f 2 --delimiter=':'
}

mountEpson

hottouchme said...

Thank you for informaton this artcle god blass you sir and your family
Download Free Epson l3110 Resetter Donload And more Epson resetters

Download L3110 Resetter said...

Thank you for informaton this artcle god blass you sir and your family
Download Free Epson l3110 Resetter Donload And more Epson resetters.