Created
March 21, 2019 21:47
-
-
Save marcsello/3ca98a5f0472d22d0b377eb45e56e681 to your computer and use it in GitHub Desktop.
Update /etc/motd with a quote downloaded using the QOTD protocol
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
| This is an example motd: | |
| The programs included with the Debian GNU/Linux system are free software; | |
| the exact distribution terms for each program are described in the | |
| individual files in /usr/share/doc/*/copyright. | |
| Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent | |
| permitted by applicable law. | |
| {} <-- This is where the Quote goes |
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 | |
| import socket | |
| HOST = "cygnus-x.net" | |
| MAX_LENGTH = 3000 | |
| def downloadQOTD(): | |
| sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) | |
| sock.connect((HOST,17)) | |
| sockf = sock.makefile() | |
| return sockf.read(MAX_LENGTH) | |
| with open("/etc/motd.template", 'r') as motd_templatef: | |
| motd_template = motd_templatef.read() | |
| with open("/etc/motd","w") as motdf: | |
| motdf.write(motd_template.format(downloadQOTD())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment