1

The intention of my script is to look for the usb printer and make sure the properties file is populated according to what's connected.

What I'm currently doing is:

ls -l /dev/usb | grep 'lp'

returns something like:

crw-rw---- 1 root lp   180, 1 Aug  5 11:32 lp1
crw-rw---- 1 root lp   180, 2 Aug  5 11:32 lp2

which I'd like to take the lp1 and lp2 values, and check my pos.properties file:

machine.printer=epson\:file,/dev/usb/lp2
machine.printer.3=epson\:file,/dev/usb/lp4
machine.printer.2=epson\:file,/dev/usb/lp1

for the strings '/dev/usb/lp1', '/dev/usb/lp2'. If both match, output 'OK, otherwise, output missing printer(s)

0

2 Answers 2

2
ok=1
for printer in /dev/usb/lp*; do
    if ! grep -wq "$printer" pos.properties; then
        ok=0
        echo "Missing $printer"
        break
    fi
done
(( ok )) && echo "OK"

Depending on the format of pos.properties, you may need a more specific command, for example,

if ! grep -wq "$printer" <(cut -d, -f2 pos.properties); then
Sign up to request clarification or add additional context in comments.

Comments

1

You can use this script:

cd /dev/usb/
arr=(lp*)

[[ $(grep -cFf <(printf "/dev/usb/%s\n" "${arr[@]}") pos.properties) -eq ${#arr[@]} ]] && 
    echo "OK" || echo "missing printer(s)"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.