LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-09-2012, 03:40 AM   #1
paul1945
Member
 
Registered: Aug 2012
Posts: 55

Rep: Reputation: Disabled
Question 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.
 
Old 08-09-2012, 09:12 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,948

Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
Welcome to LinuxQuestions.

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.
 
Old 08-09-2012, 09:04 PM   #3
paul1945
Member
 
Registered: Aug 2012
Posts: 55

Original Poster
Rep: Reputation: Disabled
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?
 
Old 08-09-2012, 10:37 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,948

Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
Untested code...
Code:
#!/bin/sh
while inotifywait -m -e close_write /home/paul/dosdrive/; do
  lpr -P HP-LaserJet-m2727-MFP -l -r -o raw /home/paul/dosdrive/*.PRN
  rm *.PRN  
done

Last edited by michaelk; 08-09-2012 at 10:38 PM.
 
Old 08-10-2012, 01:44 AM   #5
paul1945
Member
 
Registered: Aug 2012
Posts: 55

Original Poster
Rep: Reputation: Disabled
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?

Last edited by paul1945; 08-10-2012 at 02:35 AM.
 
Old 08-14-2012, 02:00 AM   #6
paul1945
Member
 
Registered: Aug 2012
Posts: 55

Original Poster
Rep: Reputation: Disabled
Unhappy Tried to reinstall, but no luck

Tried a uninstall and reinstall of the inotify package but to no avail. Any idea as to what may be going wrong? Anyone? Thanks, Paul.
 
Old 08-14-2012, 11:34 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,948

Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
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
 
Old 08-14-2012, 10:43 PM   #8
paul1945
Member
 
Registered: Aug 2012
Posts: 55

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-14-2012, 11:11 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,948

Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
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.

http://kb.iu.edu/data/acux.html
 
Old 08-15-2012, 12:37 AM   #10
paul1945
Member
 
Registered: Aug 2012
Posts: 55

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu 11.10 - printer doesen't print, nothing happens when printing firekage Ubuntu 10 03-19-2012 02:42 AM
Ubuntu network printing on apple network with HP printer beezum88 Linux - Hardware 1 11-29-2008 10:42 PM
Brother HL2070N network printer installed, print jobs stuck in printer que jgz Linux - Networking 0 02-14-2008 11:54 PM
LXer: Printing in OpenOffice.org Calc, Part 2: Print selection and printer options LXer Syndicated Linux News 0 11-26-2006 11:21 PM
cups printing: can print test page, but printer not available in openoffice hamish Linux - Software 4 07-05-2004 12:50 PM


All times are GMT -5. The time now is 08:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration