[SOLVED] re. how do I automate printing a print file to a network printer.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
re. how do I automate printing a print file to a network printer.
I am running some old legacy software (written in xBase) under DosBox in Ubuntu 12.04, but of course DosBox has no printing capability.
I have set up the program in question to produce a ".prn" file that contains all the required pcl-6 codes for the printer together with the text.
So far I have written the following shell script:
lpr -P HP-LaserJet-m2727-MFP -l -r -o raw /home/paul/dosdrive/*.PRN
which works fine; but this needs to be executed each time.
I am almost sure that there must be a way to tell Ubuntu to poll for a print file in a given directory and print this automatically, but I am not sure of how to do this.
I have brought this foward on another Forum, but no luck so far.
One suggestion would be to use inotify (install the inotify-tools package) to monitor the directory where the prn files are located. A script using inotifywait or inotifywatch can be run to detect when a prn file is created and then print it.
Thanks for that, I'd like to give that a try. Found the package for Ubuntu and have installed same.
I am rather new at this (a whole month of Linux use). So could you give me some hints as to the type of script (and file types) required?
Hello michaelk, thanks for that; unfortunately it comes up with "bad interpreter: no such file or directory". I tried "#!/bin/bash" and "#!/bin/dash" but to no avail (would not have a clue what I was doing).
The problem may be due to the location of inotifywatch and inotifywait, which are in the "/usr/bin" directory, and it may expect these in the "/bin" directory.
Any solution to this?
The path environment might not include /usr/bin. Its been awhile since I've played with inotify so hopefully this will work for you. Add a line to the /etc/rc.local and it will start at boot up. i.e.
/path/to/prndosfiles_script & (The & puts the script in the background)
/usr/bin/inotifywait -e close_write -mrq /home/paul/dosdrive | while read line; do
set -- "$line"
IFS=" "; declare -a Array=($*)
if [ "$FILEEXT" == "PRN" ];
lpr -P HP-LaserJet-m2727-MFP -l -r -o raw /home/paul/dosdrive/$FILE
Sorry to be a pain, but unfortunately things just don't work.
I have used a copy of the exact code you provided into a shell script called "print_prn.sh"
But if I execute the print_prn.sh file from the terminal window I get this:
bash: /home/paul/print_prn.sh: /bin/sh^M: bad interpreter: No such file or directory
If I make a link and execute it from this, this error comes up:
Details: Failed to execute child process "/home/paul/bin/print_prn.sh" (no such file or directory)
I have also changed the file "/usr/rc.local" as follows:
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# By default this script does nothing.
I get no errors on boot, but it does not pick up the prn file either. Paul.
Did you use a linux or windows text editor to create the script? The ^M typically indicates a DOS end of line character which will cause errors.
If you did use a windows text editor there are many ways to convert the file.
Hello michaelk, Downloaded and installed dos2unix (together with a whole lot of related stuff apparently), converted the file and it no longer came up with errors, but did not work.
Tried changing the first line to "#!/bin/bash" and it now works a treat, thank you for your help.
I am not sure what the problem was, but obviously Ubuntu 12.04 does something that is not standard.
On investigation I found "/bin/sh" is only present as a link that points to "dash". "Dash" is supposed to be a command interpreter, but maybe it does odd things and is not compatible.