Have been trying to get a .prn file generated by Dosbox to print on a network printer using Inotify.
I made the follow change to /etc/rc.d/rc.local
-------------------------------------------------------------------------------
#!/bin/sh
#
# /etc/rc.d/rc.local: Local system initialization script.
#
# Put any local startup commands in here. Also, if you have
# anything that needs to be run at shutdown time you can
# make an /etc/rc.d/rc.local_shutdown script and put those
# commands in there.
/home/paul/bin/print_prn.sh &
exit 0
-------------------------------------------------------------------------------
This script is supposed to automatically pick up the shell script file /home/paul/bin/print_prn.sh
which contains the following lines:
-------------------------------------------------------------------------------
#!/bin/bash
/usr/bin/inotifywait -e close_write -mrq /home/paul/dosdrive/c: | 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/c:/$FILE
fi
done
-----------------------------------------------------------------------------
This is intended to pick up a dosbox00.prn file in the directory /home/paul/dosdrive/c:/ and send it to the network printer named HP-LaserJet-M2727-MFP.
Network printing to this printer on Salix works otherwise fine, and I have this arrangement running on another machine under Ubuntu and it runs fine on that; so one would expect a duplication of this on this Salix notebook should work just as well.
But Salix is somehow not happy with this arrangement and when I try to execute the print_prn.sh file from the command line it comes up with the error:
./print_prn.sh: /bin/bash/^M bad interpreter: No such file or directory
I have edited both rc.local and the shell script print_prn.sh several times to remove any possible carriage returns in the script, but this does not appear to help.
I am pretty new at using Linux, so there may be some silly mistake I am overlooking; so any help would be appreciated.
Thanks in advance, Paul.
Problem using Inotify to send a file to Print [Solved]
Problem using Inotify to send a file to Print [Solved]
Last edited by paul on 7. Apr 2013, 06:57, edited 1 time in total.
Re: Problem using Inotify to send a file to Print
Did another check of the shell file in question, and found that geany does not default to the unix format and has to be told NOT to put a cr/lf at the end of a line, but a lf only. Fixed this and the error message disappeared. The .prn file in question still does not print though. So something is still not working properly in Salix. Any ideas? Paul.
Re: Problem using Inotify to send a file to Print

Another I.M. force (Impossible Mission ) assignment.
Hello, Mr. Phelps....
Your Mission, should you choose to accept it, will be to have your Salix Machine print from a Dosbox/Dosemu.
Printing from DosBox or my old favorite Dosemu can be accomplished
I will assume that you are printing to a printer attached the Machine or to file prn
as Dos emulators (to my knowledge) are not networkable (except IPX emulation).
This link will be of help with the above exampleFor network printers: parallel1=file append:/home/paul/dosdrive/dosbox00.PRN parallel2=file append:/home/paul/dosdrive/dosbox00.PRT. Is the dosbox00.PRN simply a file that gets saved and you manually print later
https://www.linuxquestions.org/question ... t1-930428/
This is a Russian video with some English and should be of some help.
http://www.youtube.com/watch?feature=pl ... IMzn0hktKk
EDIT: Ah ha.. I thought I had this Dosemu link somewhere and here it is with a bit about printing using the lpr command..
http://n0nb.us/ham-linux/linux/dosemuold.html
Good Luck!
As always, should You or any member of Your I.M. Force be caught or killed, the Secretary will disavow any knowledge of your actions.

Slackware ( Manjaro ) Salix, AntiX, Bunsen, Calculate
Re: Problem using Inotify to send a file to Print
Hello sqlpython, "we meet again."
Thank you for your link to linuxquestions.org, it is familiar; it happens to be my attempt to get dosbox to print on Ubuntu. As you can see the good people there instructed in how to compile a special version of dosbox, which I did and I got running very nicely on Ubuntu.
So as you can see, there is some hope for me, I can still learn tricks (I think).
I must also have started a trend, as I have had dozens of requests for a copy of my compiled version of dosbox that is capable of printing under Ubuntu and obviously other versions of Linux.
Interestingly this same version of dosbox runs fine on Salix and does all the right things, including the generation of a print file, which it puts in the correct directory.
The problem lies with Salix picking this file up and sending it to the network printer. As all aspects of the printing side of Salix appear to work, this is a puzzle.
As you can see, I copied the relevant components of a working system from Ubuntu, but there is something different in Salix, it does not work. Or maybe inotify is not working properly.
Maybe my rc.local file is in the wrong place or Salix likes different network commands.I will write some basic printer shell scrips that have to be manually run and see how I go. Paul.
Thank you for your link to linuxquestions.org, it is familiar; it happens to be my attempt to get dosbox to print on Ubuntu. As you can see the good people there instructed in how to compile a special version of dosbox, which I did and I got running very nicely on Ubuntu.
So as you can see, there is some hope for me, I can still learn tricks (I think).
I must also have started a trend, as I have had dozens of requests for a copy of my compiled version of dosbox that is capable of printing under Ubuntu and obviously other versions of Linux.
Interestingly this same version of dosbox runs fine on Salix and does all the right things, including the generation of a print file, which it puts in the correct directory.
The problem lies with Salix picking this file up and sending it to the network printer. As all aspects of the printing side of Salix appear to work, this is a puzzle.
As you can see, I copied the relevant components of a working system from Ubuntu, but there is something different in Salix, it does not work. Or maybe inotify is not working properly.
Maybe my rc.local file is in the wrong place or Salix likes different network commands.I will write some basic printer shell scrips that have to be manually run and see how I go. Paul.
Re: Problem using Inotify to send a file to Print
Hello sqlpython,
Back again. Tried the following shell script on Salix:
-------------------------------------------------------------------------------------------
#!/bin/bash
lpr -P HP-LaserJet-M2727-MFP -l -r -o raw /home/paul/dosdrive/c:/*.PRN
------------------------------------------------------------------------------------------
It picks up and prints the print file and works perfectly, every time.
Now all we need is to automate this in some way.
Obviously the approach used in Ubuntu does not work on Salix.
Any suggestions?
Thanking you, Paul.
Back again. Tried the following shell script on Salix:
-------------------------------------------------------------------------------------------
#!/bin/bash
lpr -P HP-LaserJet-M2727-MFP -l -r -o raw /home/paul/dosdrive/c:/*.PRN
------------------------------------------------------------------------------------------
It picks up and prints the print file and works perfectly, every time.

Now all we need is to automate this in some way.
Obviously the approach used in Ubuntu does not work on Salix.
Any suggestions?
Thanking you, Paul.
Re: Problem using Inotify to send a file to Print
@paul
Good fix!
I am lacking time due to a work deadline.
If you don't get this solved soon, I will take a look in a day or two.
Good fix!
I am lacking time due to a work deadline.
If you don't get this solved soon, I will take a look in a day or two.

Slackware ( Manjaro ) Salix, AntiX, Bunsen, Calculate
Re: Problem using Inotify to send a file to Print
Hello sqlpython, I have tried various things, including changing the directory designation in the code and the name of the shell script, but I cannot get this to run automatically in the background.
It goes into a loop when I execute the print_prn.sh shell script from the command line and hangs the computer, but does not print the file; I have to use ctrl-c to break the loop.
Obviously Salix is not happy with the shell script as it stands.
As this is totally outside my league, I am happy to wait until you have time; the matter is not urgent, I can print manually if I need to. Thanking you, Paul.
It goes into a loop when I execute the print_prn.sh shell script from the command line and hangs the computer, but does not print the file; I have to use ctrl-c to break the loop.
Obviously Salix is not happy with the shell script as it stands.
As this is totally outside my league, I am happy to wait until you have time; the matter is not urgent, I can print manually if I need to. Thanking you, Paul.
Re: Problem using Inotify to send a file to Print
Hi all, is anyone able to help me with the reason as to why inotify does not work on this Salix machine?
I have tried different things as shown previously in this post, to no avail.
Maybe some important relevant resource is not activated on startup; but which one?
Any help would be appreciated. Paul.
I have tried different things as shown previously in this post, to no avail.
Maybe some important relevant resource is not activated on startup; but which one?
Any help would be appreciated. Paul.
Re: Problem using Inotify to send a file to Print
As I have had no response so far, I decided to have a go at analyzing the problem.
When I purposely entered a <cr><lf> at the end if a line in my shell script, it showed up as an error on boot, which meant that inotify sees the shell script.
The problem therefore had to lie in the shell script, not inotify.
I therefore tried this as the shell script:
---------------------------------------------------------------------------------------------------------
#!/bin/bash
while /usr/bin/inotifywait -m -e close_write /home/paul/dosdrive/c:/; do
lpr -P HP-Laserjet-M2727-MFP -l -r -o raw /home/paul/dosdrive/c:/*.PRN
done
-----------------------------------------------------------------------------------------------------------
It worked first time; and automatically picked up any print file and sent it to the network printer.
I was not totally happy with this script however, as it seems rather crude (and I suspect uses more resources).
As such I decided to play around with the original shell script. So I changed the position of "while" in the first line to the left margin, to provide the same format as the above 3 line working shell script:
--------------------------------------------------------------------------------------------------------------------
#!/bin/bash
/usr/bin/inotifywait -e close_write -mrq /home/paul/dosdrive/c:/ | 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/c:/$FILE
fi
done
----------------------------------------------------------------------------------------------------------------------
This works fine.
Therefore printing automatically from Dosbox to a network printer is obviously not "Mission Impossible" after all.
And I hope my efforts are also useful to someone else.
Paul.
When I purposely entered a <cr><lf> at the end if a line in my shell script, it showed up as an error on boot, which meant that inotify sees the shell script.
The problem therefore had to lie in the shell script, not inotify.
I therefore tried this as the shell script:
---------------------------------------------------------------------------------------------------------
#!/bin/bash
while /usr/bin/inotifywait -m -e close_write /home/paul/dosdrive/c:/; do
lpr -P HP-Laserjet-M2727-MFP -l -r -o raw /home/paul/dosdrive/c:/*.PRN
done
-----------------------------------------------------------------------------------------------------------
It worked first time; and automatically picked up any print file and sent it to the network printer.
I was not totally happy with this script however, as it seems rather crude (and I suspect uses more resources).
As such I decided to play around with the original shell script. So I changed the position of "while" in the first line to the left margin, to provide the same format as the above 3 line working shell script:
--------------------------------------------------------------------------------------------------------------------
#!/bin/bash
/usr/bin/inotifywait -e close_write -mrq /home/paul/dosdrive/c:/ | 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/c:/$FILE
fi
done
----------------------------------------------------------------------------------------------------------------------
This works fine.
Therefore printing automatically from Dosbox to a network printer is obviously not "Mission Impossible" after all.
And I hope my efforts are also useful to someone else.
Paul.
Last edited by paul on 22. May 2013, 05:58, edited 2 times in total.
Re: Problem using Inotify to send a file to Print
What application/editor did you use to create the original script? If it was written in Windows and you've copied it there may be more hidden characters causing a problem.