home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / perl / 6954 < prev    next >
Encoding:
Internet Message Format  |  1992-11-12  |  3.5 KB

  1. Path: sparky!uunet!news.gtech.com!noc.near.net!bigboote.WPI.EDU!bigboote.wpi.edu!john
  2. From: john@sekrit.WPI.EDU (John Stoffel)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Perl Printer Daemon?
  5. Date: 12 Nov 92 10:14:37
  6. Organization: Worcester Polytechnic Institute
  7. Lines: 73
  8. Distribution: comp
  9. Message-ID: <JOHN.92Nov12101437@sekrit.WPI.EDU>
  10. References: <GLEWIS.92Nov11121920@fws204.intel.com>
  11. NNTP-Posting-Host: sekrit.wpi.edu
  12. In-reply-to: glewis@fws204.intel.com's message of 11 Nov 92 20:19:20 GMT
  13.  
  14. >>>>> On 11 Nov 92 20:19:20 GMT, glewis@fws204.intel.com (Glenn M. Lewis - ICD ~) said:
  15.  
  16.  
  17. Glenn>     I have a peculiar application, for which I think Perl would be
  18. Glenn> a good candidate to get the job done, but need input and advice.
  19.  
  20. Glenn>     I would like to start up a Perl script on my UNIX workstation
  21. Glenn> that simply looks in a directory for any file.  If no file is there,
  22. Glenn> sleep for a little while and then check again.  If there *is* a file,
  23. Glenn> I would like the script to perform an eensy bit of filtering on it
  24. Glenn> (strip out ^M and ^D), and then send it off to a UNIX printer, using
  25. Glenn> "lpr" and the "-r" flag to remove the file.  (I have very little
  26. Glenn> understanding of "cron" or if "cron" could be used by an average-joe
  27. Glenn> [read: non-super] user to make sure this script is always running, but
  28. Glenn> that is a side issue that maybe someone could teach me about.)
  29.  
  30. This program is pretty trivial, but knowing me, it would take for ever
  31. to debug.  Here is my stab at it, off the top of my head...
  32.  
  33. #!/usr/local/bin/perl
  34.  
  35. $file = "/usr1/john/foo";
  36.  
  37. while(1) {
  38.     if (-e $file) {
  39.         open(IFILE,"<$file") || die "Can't read $file: $!\n";
  40.         open(OFILE,">$file.tmp") || die "Can't create
  41. $file.tmp: $!\n";
  42.         while (<IFILE>) {
  43.             s/\cD|\cM//g;
  44.             print OFILE;
  45.             }
  46.         close(IFILE);
  47.         close(OFILE);
  48.         unlink($file);
  49.     }
  50.     sleep(60);
  51. }
  52.  
  53. Glenn>     I could probably figure out how to do the above part, with a
  54. Glenn> little time.  Now comes the tricky part...  I would like this script
  55. Glenn> to also check the printer queue every so often, to see if it is making
  56. Glenn> progress.  Yes, this sketchy, because huge print jobs will take a long
  57. Glenn> time, and from the "lpq" standpoint, it is not easy to determine if
  58. Glenn> progress is being made.  Neglecting this side issue, if the script
  59. Glenn> determines that progress is *not* being made, I would like it to:
  60.  
  61. Glenn>     1) Log into a remote machine with an embedded username and
  62. Glenn>        password (which should be secure, btw),
  63. Glenn>     2) Execute commands on the remote machine to get the printer going
  64. Glenn>        again, and
  65. Glenn>     3) logout of the remote machine and continue checking the
  66. Glenn>        directory.
  67.  
  68. I think your best bet would be to have TWO seperate programs to do all
  69. of the above.  The first program would wait for the file and then
  70. print it.  The second one would watch the printer queue, and do the
  71. appropriate stuff to restart it if needed.  This would close the LARGE
  72. security hole of having to embed a username and password into the
  73. first script.
  74.  
  75. This script will be a little hairier than the first, and pretty
  76. dependent on whether or not you are using BSD nad SYSV unix.  Let me
  77. know if you would like some more help.
  78.  
  79.                     John
  80.  
  81.  
  82. --
  83. Youth of today!  Join me in a mass rally for traditional mental attitudes!
  84. -------------------------------------------------------------------------------
  85. john@wpi.wpi.edu | Work Station Specialist | Worcester Polytechnic Institute
  86. John Stoffel     | 508-831-5512 (work)     | Worcester, MA  01609
  87.