Managing print jobs in linux command line

Some useful commands to manage print jobs

lpstat -p -dTo get a list of available printers, along with their status
lpstat -aTo check the status of all connected printers, including job numbers
cancel job-id or lprm job-idTo cancel a print job
lpmove job-id newprinterTo move a print job to new printer

Taken from Introduction to Linux course (LFS101) from Linux Foundation here

ldapsearch on a json attribute.

Problem

You have an LDAP entry with an attribute that consists of json entries, and you would like to use ldapsearch to filter on a json item condition.

So having the attribute

mobileIDAuthenticator: {“creationDateTime”:”2023-08-28T14:53:29.061Z”,”state”:”ENABLED”,”mobileNumber”:”+411111111″,”mobileSerialNumber”:”AAAAAAAAAAAAA”}

you would like to filter on the state item.


Solution

you can use the following syntax:

ldapsearch -LLL -H "ldaps://domain.com:1636" -D "cn=Directory Manager" -w $LDP -o ldif_wrap=no -c -vvvv -b "ou=persons,dc=domain,dc=com" -s sub "(mobileIdAuthenticator=state eq 'ENABLED')"  uid mobileIDAuthenticator 

Return results from LDAP without a line wrap (attribute)

Problem

You have an attribute in LDAP that might be a long line (ie a json array that contains many records like logins for example)

loginHistory: [{"lastLoginDate":"20250107094531.782Z","loginModule":"1"},{"lastLoginDate":"20241202075005.298Z","loginModule":"1"},{"lastLoginDate":"20241129143412.785Z","loginModule":"1"},{"lastLoginDate":"20241129103347.029Z","loginModule":"1"},{"lastLoginDate":"20240920105718.171Z","loginModule":"2"}]

But you want to return it in one line for further processing (ie counting the number of times in a year).

Solution

You can use the -o ldif_wrap=no option in your ldapsearch like

ldapsearch -LLL -H "ldaps://ldap.com:1636" -o ldif_wrap=no -D "cn=User" -w $LDP -b "ou=people,dc=domain,dc=com" -s sub "(mail=usernname@domain.com)" uid loginHistory 

PITR recovery fails when there are no transactions (pgbackrest)

Prolem

You are trying to do PITR recovery for a specific time, but the restore fails with something similar to the following message

FATAL:  recovery ended before configured recovery target was reached

Solution

This seems to be caused by a feature/bug that causes this error when there are no transactions between the backups, as explained in more detail here

Producing a file C.txt that contains common lines between A.txt B.txt using grep

Problem

You have two files (A.txt, B.txt) that contain records (one line each), and you want to find out the common lines between the two.

For example you have the following two files.

A.txt

one
two
three

and B.txt

two
six
seven

and you want to find or produce a new file (C.txt) that contains only the common record (two) from the two files.

Solution

You can use grep with the -Fx options like

grep -Fxf A.txt B.txt > C.txt

that will produce file C.txt that contains the common line (two) from the two files.

The options for grep have the following meaning:

  • -F: Interpret the pattern as a list of fixed strings (instead of regular expressions).
  • -x: Only match whole lines.
  • -f fileA.txt: Read the patterns from fileA.txt.