python linux
-
[Python] Linux에서 간단한 Web 모니터링 하기Python/Python for Linux 2019. 4. 15. 19:31
Python Version : 2.7.5 #!/usr/bin/python import requests as req from datetime import datetime import time sites = ('http://192.168.x.77','http://192.168.x.77/xxxx.php') for site in sites: try: r = req.get(site) print site, 'return_code :', r.status_code except Exception as e: print site, 'fail' time.sleep(10) ★ 웹 페이지가 기동 중 일 때, 아래와 같이 응답코드 값을 리턴 받을 수 있습니다. http://192.168.x.77 return_code : 200 (..
-
[Python] Linux Sendmail을 이용한 메일 보내기Python/Python for Linux 2019. 4. 13. 22:12
- OS : CentOS 7 - Python 2.7 #!/usr/bin/python from email.mine.text import MIMEText from subprocess import Popen, PIPE msg = MIMEText('Body Text') msg['Subject'] = 'Subject Text' msg['From'] = 'From Email Address' msg['To'] = 'To Email Address' p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE) p.communicate(msg.as_string()) Step 1. sendmail install # yum install sendmailyum install sendmail se..