pybackive/backive/backive_udev

24 lines
595 B
Plaintext
Raw Permalink Normal View History

2019-02-22 21:26:01 +01:00
#!/usr/bin/env python3
"""
Callable script for udev rules.
"""
2019-02-24 22:42:36 +01:00
import socket
import os
import json
2019-02-24 22:42:36 +01:00
with open("/tmp/backive/udev.log", "a") as stream:
stream.write("udev run...")
for k, v in os.environ.items():
stream.write("{k}: {v}\n".format(k=k, v=v))
unix_socket = "/tmp/backive/backive.sock"
try:
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(unix_socket)
sock.send(json.dumps(dict(os.environ)).encode())
sock.close()
except Exception as e:
stream.write("Exception occurred: {}".format(str(e)))