[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!
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
#!/bin/bash
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)
Code:
#!/bin/sh
/usr/bin/inotifywait -e close_write -mrq /home/paul/dosdrive | while read line; do
set -- "$line"
IFS=" "; declare -a Array=($*)
FILE="${Array[2]}"
FILENAME=${FILE%.*}
FILEEXT=${FILE##*.}
IFS=""
if [ "$FILEEXT" == "PRN" ];
then
lpr -P HP-LaserJet-m2727-MFP -l -r -o raw /home/paul/dosdrive/$FILE
fi
done
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:
#!/bin/sh -e
#
# rc.local
#
# 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
# bits.
#
# By default this script does nothing.
/home/paul/bin/print_prn.sh &
exit 0
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.