Workaround for non-unique print spool file names
Warren Smith
warren at cswnet.com
Thu Sep 28 13:49:38 GMT 2000
Several days ago, I posted a description of a problem I was having that I
thought was being caused by samba not generating unique print spool file
names. I have since confirmed that conclusion.
Since the only reply I got to that post was a post from Christian
Günsel saying that he was having the same problem and I couldn't wait for it
to be fixed in samba, it fell upon me to come up with a simple workaround.
I credit Christian for the idea of doing something with the file in the print
command. I wrote the program in python only because it is my scripting language
of choice. This could easily be done with a shell script, though it would
require more processes to be run to accomplish the same operations.
Here it is:
---------------
smb.conf:
print command = /usr/local/sbin/print_samba_job %u %p %f
----------------
/usr/local/sbin/print_samba_job:
#!/usr/local/bin/python
import sys
import os
import time
#
# Get Arguments
#
user = sys.argv[1]
printer = sys.argv[2]
oldfilename = sys.argv[3]
#
# Construct a unique filename from user, current time, and current pid.
# Our spool files are deleted every night, so date is not necessary in our
# filename.
newfilename = '%s.%s.%s' % (user,time.strftime('%H%M%S',time.localtime(time.time())),os.getpid())
#
# Rename (possibly) non-unique filename to filename just constructed
#
os.rename(oldfilename,newfilename)
#
# Execute print command
#
# FreeBSD will not remove spool files if the -s option is specified, so I left
# the -r option out on purpose. Other platforms may not have this affliction.
#
os.system('/usr/bin/lpr -s -P %s %s' % (printer,newfilename))
------------
PS: Christian, hope this helps. Thanks for the idea.
--
Warren Smith
Chief Engineer
CSW Net, Inc.
501-880-2230
warren at cswnet.com
More information about the samba
mailing list