- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script to print to printer + file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-10-2001 01:11 PM
тАО07-10-2001 01:11 PM
We have printers that go down and we then have a hard
time figuring out what printed and what did not. We are running warehousing software, and when an order is printed it changes the order status. But sometimes the printer fails to print, yet the computer thinks it did. To find the lost order I have to run a database query that brings all jobs printed company wide, then take the list and figure out which did not print. There is no way of knowing what printer a job went to.
So I am trying to make a script that will first print to a file, then afterwards print the job to a printer. Then when the printer fails I can look in the file for that printer and know what should have printed and compare it to what actually did print. That way the search is limited to the jobs for that problem printer, instead of every job printed company wide.
Here is the script - with someone else's help.
# /rd/bin/printreports
DA=`date +"%m%d%M%H%S"`
cat $1 > /tmp/printername.$DA
lp -dprintername -s -c /tmp/printername.$DA
Then in the software I change the print comand to run this script instead. It works great! But one problem.
If a job is sent to the same printer as another job within the same second, then the file is overwritten and the other job is lost to the filesystem. It does print out, but no record if it is in the filesystem. I need the record for opening it to read the contents, in the case of a printer failure.
The man pages on 'date' show seconds as the smallest unit. I need a smaller unit.
Or a way to add to the script to have it test to see if a file has already been made that second, if so then to make a file with a different name. This would keep print jobs that happen in the same second to have unique names and not be over written.
I am not very knowledgeable about how to use Unix commands to write scripts. Can anyone suggest a solution this problem? Maybe a way to add to the script so a file is created every time, and not overwriting a previous one sometimes?
Thanks,
Troy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-10-2001 01:23 PM
тАО07-10-2001 01:23 PM
Re: Script to print to printer + file
You could use the $RANDOM environmental variable (which returns an integer between 0 and 32767) and append it to your filename, along with the timestamp, if you wish.
You could also use the "$$" variable which returns the PID of the current process. Append this to the filename as you see fit.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-10-2001 01:24 PM
тАО07-10-2001 01:24 PM
SolutionThat was a pretty good effort for a novice script writer. I would instead use the process ID of your script.
PID=$$
FNAME=/tmp/printername.${PID}
The PID's do repeat but over very long internals. This is the standard UNIX idiom for creating temp file names.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-10-2001 01:33 PM
тАО07-10-2001 01:33 PM
Re: Script to print to printer + file
That is exactly the kind of help I was hoping for. Again, since I am lame at writing scripts - I have one more request.
How do I append the {PID} to the filename plus the time stamp? Just for curiosity.
Unix gives time and date of file creation, so that is good enough without the timestamp - so long as I use the PID trick you guys gave me. This should work well.
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-10-2001 01:52 PM
тАО07-10-2001 01:52 PM
Re: Script to print to printer + file
You can use time stamp plus PID
as
DA=`date +"%m%d%M%H%S"`
PID=$$
FILENAME=/tmp/printername-${DA}.${PID}
The file /var/adm/lp/log also keeps log of all files printed on printers on machine.
Thanks.
Prashant.