0

What's the reason lpadmin gives completely different results when running it as root and when running it inside a script and executing it as root? Looks like it is not having the same scopes for files access.

My script:

#!/bin/bash
lpadmin -p printer-x -E -v socket://192.168.0.111 -P /root/tm-ba-thermal-rastertotmt.ppd
lpadmin -p printer-x -m raw
cupsenable printer-x

Results when running as a script:

lpadmin: No such file or directory
lpadmin: Unable to copy PPD file!
cupsenable: Operation failed: client-error-not-found

Results when running the commands outside the script (no errors outputs are shown and the printer is added):

[root@localhost ~]# lpadmin -p printer-x -E -v socket://192.168.0.111 -P /root/tm-ba-thermal-rastertotmt.ppd
[root@localhost ~]# lpadmin -p printer-x -m raw
[root@localhost ~]# cupsenable printer-x 

I've given full permissions on the script and folders for testing, but it does not look like to be the issue. I've tried moving to other folders too.

I've also tried to isolate each command from the script, but all of the commands are answering the same errors on the output.

Tarcisio Júnior
  • 1,097
  • 1
  • 13
  • 25
  • 2
    Does your script have DOS/Windows-style line endings? You can check by printing it with `cat -v scriptname` and looking for `^M`s at the ends of the lines. If it has them, see ["Are shell scripts sensitive to encoding and line endings?"](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings) for info on how to fix it. If not, try adding `set -x` as the second line (after the shebang), and see if it shows anything weird in its execution trace. – Gordon Davisson Oct 21 '21 at 09:07
  • Wonderful Gordon, it looks like it solved the problem, I am doing more tests to ensure, but looks like it was the only issue, you can answer if you want so I can pick your answer. – Tarcisio Júnior Oct 21 '21 at 09:25
  • 1
    It's better to mark this as a duplicate. This problem shows up a lot, in many forms, so if someone else runs into a variant and finds your question while searching, it'll refer them to the place where *all* the relevant info is. – Gordon Davisson Oct 21 '21 at 09:38

0 Answers0