简体   繁体   中英

Python Authlog Log File analysis

I recently started to play around with Python 3 which I enjoy a lot. I'm a sysadmin in apprenticeship so I have nearly no programming experience. I want to make a small program which is going to tell me everytime someone logs into my system via ssh. I'm going to use the espeak-python bindings. What is the best way to analys the log file in real time?

So everytime someone logs into the system via SSH I can hear it over my speakers :-). I don't want a complete Solution just a few points so I know where to start...

Should the program run in a terminal or as a service? If run as a service you should consider looking at a library like python-daemon . If you only want to run it in a terminal a usual endless loop (which will then be aborted by a ctrl+c) should do fine.

For playing sound to the speakers you could look at PyAudio . I used it for my sound-related projects. Its website (with good examples) can be found here

To parse the file you can open it (maybe after opening do a read() to discard any log entries that was made before starting the program). Then you can do a readline() in every run of the loop. The retrieved line may be empty. If that's the case no login was attempt. If you got a line you only need to check if there's the word 'sshd' in the line and if yes someone logged in via ssh.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM