I am printing some files from a remote computer to a network printer with the lpr command. It apparently worked, but some minutes later when I typed lpstat or lpq, the job had already disappeared, it had probably already printed the file. Is there a way to check the history or the log of my successfully completed jobs in the printer queue?
-
Of course I have no access to the printer right now, and therefore I cannot check if the file was printed or not.– SantiagoApr 7, 2014 at 22:09
-
Via the web interface it is easy.– Faheem MithaApr 7, 2014 at 22:11
-
What is that, could you explain a bit more?– SantiagoApr 7, 2014 at 22:13
-
localhost:631.– Faheem MithaApr 7, 2014 at 22:22
6 Answers
Yes a program exists: lpstat
- print cups status information
$ lpstat -W completed
-W which-jobs Specifies which jobs to show, completed or not-completed (the default). This option must appear before the -o option and/or any printer names, otherwise the default (not-completed) value will be used in the request to the scheduler.
Or if you prefer via the following web pages:
https://localhost:631/printers/[NameOfPrinter]?which_jobs=completed
http://localhost:631/jobs?which_jobs=completed
Kind regards
-
3This will only show the completed for your userid. You can give a list of users like this:
lpstat -W completed -u user1,user2
.– slm ♦Oct 8, 2014 at 1:41 -
Does lpstat have a rolling window for the completed print job history, or does it show all jobs that were ever completed? Jan 9, 2020 at 21:01
The other answer when tried produced the following:
$ sudo lpstat -W completed
mfc-8480dn-1652 root 1024 Tue 28 Jan 2014 01:19:34 AM EST
Adding a user, saml
gives you that user's history:
$ sudo lpstat -W completed -u saml | head -2
mfc-8480dn-1524 saml 23552 Thu 28 Nov 2013 10:45:44 AM EST
mfc-8480dn-1526 saml 699392 Sat 30 Nov 2013 10:34:34 AM EST
But the -u all
mentioned in this U&L Q&A titled: View all user's printing jobs from the command line did nothing for me.
$ sudo lpstat -W completed -u all | head -2
$
Curiously I could do this:
$ sudo lpstat -W completed -u saml,root | head -3
mfc-8480dn-1524 saml 23552 Thu 28 Nov 2013 10:45:44 AM EST
mfc-8480dn-1526 saml 699392 Sat 30 Nov 2013 10:34:34 AM EST
mfc-8480dn-1652 root 1024 Tue 28 Jan 2014 01:19:34 AM EST
So one hackish way to do this would be to formalize a list of the users on your system and then add that as a subcommand to the -u
argument like so:
$ sudo lpstat -W completed -u $(getent passwd | \
awk -F: '{print $1}' | paste -sd ',')
Just to show that this sees all the users locally you can get a unique list of your users like so:
$ sudo lpstat -W completed -u $(getent passwd | \
awk -F: '{print $1}' | paste -sd ',') | awk '{print $2}' | sort -u
ethan
root
sam
tammy
Issues?
One problem with this is if the user printing to CUPS does not have an account locally then they won't get displayed.
But if you have a directory that contains your LPD control files, typically it's /var/spool/cups, you'll notice a bunch of control files in there. These files are kept as a result of the
MaxJobs` setting, which defaults to 500 when unset.
$ sudo ls -l /var/spool/cups/ | wc -l
502
Another source of usernames?
If you look through these files you'll notice that they contain usernames, and not just ones for accounts that are present on the system.
$ strings /var/spool/cups/* | grep -A 1 job-originating-user-name | head -5
job-originating-user-name
tammyB
--
job-originating-user-name
tammyB
So we could select all the entries that contain the username followed by the B.
$ sudo strings /var/spool/cups/* | grep -A 1 job-originating-user-name | \
grep -oP '.*(?=B)' | sort -u
ethan
guest-AO22e7
root
sam
saml
slm
tammy
This list can then be adapted in the same way as we were originally using to take the list of users from getent passwd
, like so:
$ sudo lpstat -W completed -u $(strings /var/spool/cups/* | \
grep -A 1 job-originating-user-name | \
grep -oP '.*(?=B)' |sort -u | paste -sd ',')
mfc-8480dn-1525 tammy 545792 Thu 28 Nov 2013 01:36:59 PM EST
mfc-8480dn-1526 saml 699392 Sat 30 Nov 2013 10:34:34 AM EST
mfc-8480dn-1652 root 1024 Tue 28 Jan 2014 01:19:34 AM EST
mfc-8480dn-1672 saml 1024 Sun 09 Feb 2014 01:56:26 PM EST
References
I think /var/log/cups/page_log
etc. has the history of completed jobs.
An alternative is the web interface
http://localhost:631/
which also shows completed jobs. I'm not sure where the web interface gets its information from.
Every answer above seems to be only interested in completed jobs...
What if you are also interested in jobs which were canceled by the user or an admin? What if you want to know how many jobs were aborted by the print system itself, due to driver or other problems?
For these cases use:
lpstat -W all -o
Also, you may want to know more details about each job. In this case add -l
for a long output format:
lpstat -l -W all -o
If you want to see jobs of other users, than for some reason specifying -u
without value works (at least on my system):
lpstat -W completed -u
This command appears to clear history as well as any active jobs:
sudo cancel -a -x