[geklärt]Rechteproblem / Druckersteckdose bei Druckauftrag über CUPS einschalten

Begonnen von TomLee, 11 Mai 2024, 14:38:23

Vorheriges Thema - Nächstes Thema

TomLee

Hallo,

mögen Basics sein, ich hab sie aber offenbar immer noch nicht verstanden.

Erstellt hab ich eine Verküpfung:

lrwxrwxrwx  1 fhem dialout     19 11. Mai 14:01 cupstmp -> /var/spool/cups/tmp

/var/spool/cups/tmp sieht so aus:
root@fhempi:/var/spool/cups# ls -l
insgesamt 284
...
drwxrwx--T 2 root lp  4096 11. Mai 12:34 tmp
(das mit dem T hab ich bisher noch nie gesehen)

fhem ist in der Gruppe lp:
root@fhempi:/var/spool/cups/tmp# cat /etc/group
...
lp:x:7:fhem
...

Gegeben ist ein inotify in Fhem:
defmod inot_print_queue inotify cupstmp
attr inot_print_queue mask IN_CREATE

und ein Logeintrag der auf ein Rechteproblem hinweist:
2024.05.11 14:02:09 2: inotify (inot_print_queue):Error: Permission denied for cupstmp
2024.05.11 14:02:09 3: inotify (inot_print_queue): startet watching cupstmp

Kann mir bitte wer aufzeigen wo genau mein Denkfehler liegt ?
Welche Rechte, gehören wo noch angepasst ?
Kann es daran liegen das ich eine Verknüpfung in <path> angebe ?
Geb ich mglw. <path> in inotify nicht korrekt an ?


Hintergrund des ganzen: So stell ich mir vor einen Aktor mit on-for-timer zu schalten, sobald ein Druckauftrag in dem tmp-Ordner registriert wird.

Gruß

Thomas

Wernieman

#1
1. Hast DU FHEM wirklich restartet? Also auf Betriebsystemebene?
2. Du gibst uns die Rechte vom  tmp-Ordner, wie sehen die der Höheren Ordnern aus?
3. Reicht wirklich "defmod inot_print_queue inotify cupstmp"? Ist das der Richtige Pfad?

Da der Symlink die Rechte 777 hat (Muß er wirklich??), sind dort die Rechte irrelevant.

Wegen 3. siehe Doku von inotify:
Define

    define <name> inotify <path> [<file-RegEx>]

        path: absolute path to watch
        file-RegEx: file-Pattern (only watch a group of files)
Vor allem das "absolute path"
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

TomLee

#2
Hi,

danke für die Unterstützung.
Zitat1. Hast DU FHEM wirklich restartet? Also auf Betriebsystemebene?
Schon. Hab einen Neustart des Fhem-Rechner gemacht gehabt und nicht bemerkt (erst eben) das die inotify-Definition jetzt ihren Dienst (mit der Verknüpfung) tut  ::)

Zitat2. Du gibst uns die Rechte vom  tmp-Ordner, wie sehen die der Höheren Ordnern aus?
drwx--x--- 3 root lp   4096 12. Mai 07:41 cupsdrwxr-xr-x  12 root root  4096  8. Nov 2023  vardrwxr-xr-x  4 root root       4096 13. Dez 08:05 spool
Zitat3. Reicht wirklich "defmod inot_print_queue inotify cupstmp"? Ist das der Richtige Pfad?
Offensichtlich.

defmod inot_print_queue inotify cupstmp
attr inot_print_queue mask IN_CREATE
attr inot_print_queue room Büro->Drucker

setstate inot_print_queue active
setstate inot_print_queue 2024-05-12 08:06:49 lastEventFile cupstmp/gs_0nWiGY
setstate inot_print_queue 2024-05-12 08:06:49 lastEventMask IN_CREATE
setstate inot_print_queue 2024-05-12 07:37:45 state active




Mit inotifywait hab ich gestern weiter gespielt und da schon bemerkt das nicht einfach nur eine Datei bei einem Druckauftrag in dem tmp-Ordner erstellt wird, sondern eine ganze Menge. Das ist natürlich in FHEM mit dem inotify-Modul nicht anders:

1715492454.43284 inotify inot_print_queue IN_CREATE: cupstmp/gs_qFYH4E
2024-05-12 07:51:47 inotify inot_print_queue lastEventFile: cupstmp/664058f36fef9
2024-05-12 07:51:47 inotify inot_print_queue lastEventMask: IN_CREATE
1715493107.47522 inotify inot_print_queue IN_CREATE: cupstmp/664058f36fef9
2024-05-12 07:51:47 inotify inot_print_queue lastEventFile: cupstmp/foomatic-J02AwF
2024-05-12 07:51:47 inotify inot_print_queue lastEventMask: IN_CREATE
1715493107.48506 inotify inot_print_queue IN_CREATE: cupstmp/foomatic-J02AwF
2024-05-12 07:51:47 inotify inot_print_queue lastEventFile: cupstmp/gs_9xh5oI
2024-05-12 07:51:47 inotify inot_print_queue lastEventMask: IN_CREATE
1715493107.7733 inotify inot_print_queue IN_CREATE: cupstmp/gs_9xh5oI
2024-05-12 07:51:47 inotify inot_print_queue lastEventFile: cupstmp/gs_1byavX
2024-05-12 07:51:47 inotify inot_print_queue lastEventMask: IN_CREATE
1715493107.78087 inotify inot_print_queue IN_CREATE: cupstmp/gs_1byavX
2024-05-12 07:51:47 inotify inot_print_queue lastEventFile: cupstmp/gs_HJMvZQ
2024-05-12 07:51:47 inotify inot_print_queue lastEventMask: IN_CREATE
1715493107.81876 inotify inot_print_queue IN_CREATE: cupstmp/gs_HJMvZQ
2024-05-12 07:51:47 inotify inot_print_queue lastEventFile: cupstmp/gs_ZqMb43
2024-05-12 07:51:47 inotify inot_print_queue lastEventMask: IN_CREATE
1715493107.82644 inotify inot_print_queue IN_CREATE: cupstmp/gs_ZqMb43
2024-05-12 07:51:47 inotify inot_print_queue lastEventFile: cupstmp/gs_KpSsTf
2024-05-12 07:51:47 inotify inot_print_queue lastEventMask: IN_CREATE
1715493107.85658 inotify inot_print_queue IN_CREATE: cupstmp/gs_KpSsTf
2024-05-12 07:51:47 inotify inot_print_queue lastEventFile: cupstmp/gs_VrkHba
2024-05-12 07:51:47 inotify inot_print_queue lastEventMask: IN_CREATE
1715493107.86462 inotify inot_print_queue IN_CREATE: cupstmp/gs_VrkHba
2024-05-12 07:51:47 inotify inot_print_queue lastEventFile: cupstmp/gs_aYcm3Q
2024-05-12 07:51:47 inotify inot_print_queue lastEventMask: IN_CREATE
1715493107.95628 inotify inot_print_queue IN_CREATE: cupstmp/gs_aYcm3Q
2024-05-12 07:51:47 inotify inot_print_queue lastEventFile: cupstmp/gs_8c7KEK
2024-05-12 07:51:47 inotify inot_print_queue lastEventMask: IN_CREATE
1715493107.96579 inotify inot_print_queue IN_CREATE: cupstmp/gs_8c7KEK
2024-05-12 07:51:47 inotify inot_print_queue lastEventFile: cupstmp/gs_R7VU3A
2024-05-12 07:51:47 inotify inot_print_queue lastEventMask: IN_CREATE
1715493107.99471 inotify inot_print_queue IN_CREATE: cupstmp/gs_R7VU3A
2024-05-12 07:51:48 inotify inot_print_queue lastEventFile: cupstmp/gs_hg2kAj
2024-05-12 07:51:48 inotify inot_print_queue lastEventMask: IN_CREATE

Das beschäftigt mich jetzt, wie ich das löse, das ich nur ein Event bekomme. Denke werde nicht mehr das ganze Verzeichnis überwachen, sondern nur eine Datei, wsl. die foomatic-XXXXXX . Da komme ich aber erst heute Mittag dazu.

Wernieman

Da es jetzt funktioniert, bitte ein [gelöst] im Titel setzen. Editiere Deinen ersten Post und dort kannst DU auch das Subjekt ändern.

Wenn Du die Gruppen eines Uers änderst, wird dieses erst beim Neueinloggen des Users durchgeführt. Entsprechend konnte der "User" FHEM nicht zugreifen, da er die Gruppe noch nicht kannte. Du hast den Pi neugestartet, weshalb das eben neu geladen wurde. Es hätte ansonsten eben auch gereicht, wenn Du den Dienst fhem neustartest, da auch damit diese Änderung durchgeführt werden.

Bin selber etwas gegen z häufigem Neustart, da dadurch auch Informationen über Fehler etc. verloren gehen können .....
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

TomLee

Thx.

mags jetzt aber nicht mehr mit inotify, sondern mit einem incron iVm. einem Bash-Skript umsetzen.

  • sudo apt-get install incron
  • User fhem in /etc/incron.allow hab ich eingetragen
  • Als User fhem mit incrontab -e das eingetragen:
    /var/spool/cups/tmp/foomatic-.* IN_CREATE       /opt/fhem/www/scripts/printer.sh
  • Bashskript unter /opt/fhem/www/scripts/printer.sh erstellt (das tut hab ich getestet aus FHEM):
    #!/bin/bash

    /usr/bin/perl /opt/fhem/fhem.pl 7072 "set MQTT2_Tradfri_Plug_3 on-for-timer 5"
        err=$?
        echo "$(date +"%Y.%m.%d %T") $err: fhem command"


Zitat<OrdnerOderDatei> <Ereignismaske> <Script> <Parameter>

<Parameter> ist optional hab ich gelesen (mag ja auch nix übergeben), das ist das einzige Fragezeichen das ich habe, die Pfade mein ich eigentlich korrekt angegeben zu haben.

Es tut noch nicht und ich weiß nicht wo nachschauen was schief läuft  8)

Kann da bitte wer was zu sagen ?



In FHEM klappt das jetzt natürlich auch ohne Verknüpfung:

defmod inot_print_queue inotify /var/spool/cups/tmp/ foomatic-.*
attr inot_print_queue mask IN_CREATE
attr inot_print_queue room Büro->Drucker

setstate inot_print_queue active
setstate inot_print_queue 2024-05-12 13:04:39 lastEventFile /var/spool/cups/tmp//foomatic-Z2rZ7U
setstate inot_print_queue 2024-05-12 13:04:39 lastEventMask IN_CREATE
setstate inot_print_queue 2024-05-12 12:56:44 state active

TomLee

Ob es an den Leerzeichen zw. <Ereignismaske> <Script> in liegt?

/var/spool/cups/tmp/foomatic-.* IN_CREATE       /opt/fhem/www/scripts/printer.sh
Wenn ich incrontab -e ausführe wird die Datei in nano geöffnet. Speichere und  schliesse ich die Datei entstehen diese Leerzeichen, gemacht hab ich nur eines.

Warum ist das so ?

TomLee

Reguläre Ausdrücke können wohl doch nicht im ersten Parameter verwendet werden ?

Wenn ich zum Test das ganze Verzeichnis überwache wird mein Skript ausgeführt:

fhem@fhempi:~$ incrontab -l
/var/spool/cups/tmp     IN_CREATE       /opt/fhem/www/scripts/printer.sh

TomLee

Damit kann ich leben: (edit: klappt doch nicht zuverlässig)
fhem@fhempi:~$ incrontab -l
/var/spool/cups/tmp     IN_CREATE,IN_ONESHOT    /opt/fhem/www/scripts/printer.sh

TomLee

In der Dokumentation (man 5 incrontab) steht:
Zitat... Please not that the * wildcard is allowed to observe a range of files.

Sollte foomatic-* dann nicht auch foomatic-J02AwF überwachen ?
Tut es nämlich nicht.
fhem@fhempi:~$ incrontab -l
/var/spool/cups/tmp/foomatic-*  IN_CREATE             /opt/fhem/www/scripts/printer.sh

Das ganze Verzeichnis überwachen klappt:
fhem@fhempi:~$ incrontab -l
/var/spool/cups/tmp     IN_CREATE,recursive=false       /opt/fhem/www/scripts/printer.sh

Bloß zeigt zeigt sich hier mit meinem Versuch mit recursive=false die Unterordner auszuschliessen, das auch dies nicht greift (bekomme auch die Events der in den Unterordnern erstellten Dateien, s. #2), obwohl das in der Doku steht (zumindest versteh ich es so):
Also, there is the symbol recursive=false. This symbol limits the observation on the specified directory and does not include subdirectories.
Hätte aber gerne nur ein Event, so wie es in FHEM mit inotify iVm. regexp tut:
defmod inot_print_queue inotify /var/spool/cups/tmp/ foomatic-.*
attr inot_print_queue mask IN_CREATE

setstate inot_print_queue active
setstate inot_print_queue 2024-05-13 15:57:57 lastEventFile /var/spool/cups/tmp//foomatic-vmXPvv
setstate inot_print_queue 2024-05-13 15:57:57 lastEventMask IN_CREATE
setstate inot_print_queue 2024-05-12 14:50:55 state active

Wernieman

Da ich mit incrontab noch nie gearbeitet habe, kann ich Dir da nicht helfen ...
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html