Created
October 12, 2020 20:24
-
-
Save terenty-rezman/201dc4a1ad94694f40ec92835d4b5bc7 to your computer and use it in GitHub Desktop.
linux 'logger' command in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
does the same as linux 'logger' command (on a basic level) | |
writes msg to rsyslog from current user | |
linux 'logger' command protocol can bee eavesdropped with: | |
$ (strace -v -s 512 logger msg from native logger) &> strace_log | |
""" | |
import sys | |
import socket | |
import getpass | |
SYSLOG_SOCKET = '/dev/log' | |
USER = getpass.getuser() | |
if len(sys.argv) == 1: | |
print('usage: log.py [message to log]') | |
sys.exit() | |
client = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) | |
client.connect(SYSLOG_SOCKET) | |
msg = "<13>" + USER + ": " + " ".join(sys.argv[1:]) | |
client.send(msg.encode()) | |
client.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment