Gooday Note Scrap Source Android login
 
작성일 : 18-07-17 16:29
[Linux] 서버 시작 시 IP 메일 보내기
 글쓴이 : 최고관… (123.♡.195.38)
조회 : 824  

STEP 1

파일 생성 : startup_mailer.py

아래 내용 추가

import subprocess
import smtplib
import socket
import os
from email.mime.text import MIMEText
import datetime

# Change to your own account information
to = '보내 메일 주소'
gmail_user =  '구글 아이디@gmail.com'
gmail_password =  '구글 비밀번호'
smtpserver = smtplib.SMTP('smtp.gmail.com', 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_password)
today = datetime.date.today()

# Very Linux Specific
arg= 'ip route list'
p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE)
data = p.communicate()
split_data = data[0].split()
ipaddr = split_data[split_data.index('src')+1]

# Get the current CPU speed
f = os.popen('/opt/vc/bin/vcgencmd get_config arm_freq')
cpu = f.read()
mail_body = "CPU speed: " + cpu + "IP address: %s" % ipaddr
msg = MIMEText(mail_body)
msg['Subject'] = "RasPI @ "+ipaddr+" started up on %s" % today.strftime('%b %d %Y')
msg['From'] = gmail_user
msg['To'] = to
smtpserver.sendmail(gmail_user, [to], msg.as_string())
smtpserver.quit()


STEP 2

# vi /etc/rc.local 에서 바로 실행하기

아래 코드 삽입

# Print the IP address
_IP=$(hostname -I) || true
if ["$_IP" ]; then
 printf "My IP address is %s\n" "“$_IP"
 python /home/pi/code/startup_mailer.py
fi

python /home/pi/code/startup_mailer.py


 
 

Total 121
번호 제   목 글쓴이 날짜 조회
121 [Linux] 서버정보 안보이게 하기 기리 07-17 622
120 [Linux] Redis and phpredis (2) 기리 01-26 790
119 [Linux] Coin 거래소 기리 01-01 649
118 [JavaScript] ReactJS 기리 01-01 551
117 [CSS] 출력되는 글자의 줄 수를 CSS를 사용하여 표시 (1) 기리 10-05 514
116 [Linux] SSL 인증 의무화 최고관… 09-15 591
115 [Linux] HTTPS - SSL (1) 최고관… 09-14 616
114 [Linux] mod_ssl 로 보안 강화하기 최고관… 09-14 592
113 [Linux] AWS 아마존 웹 서비스 (3) 최고관… 09-10 653
112 [Linux] 서버 시작 시 IP 메일 보내기 최고관… 07-17 825
111 [Linux] CentOS 7 minimal network 설정 기리 12-22 984
110 [JavaScript] 브라우저 설정 언어 확인 기리 11-21 870
109 [MySql] database 생성 최고관… 05-20 1332
108 [RaspberryPi] 계정 관리(추가, 수정, 삭제) (1) 최고관… 05-19 5312
107 [Linux] 리눅스 APM 정의 및 설치(ubuntu, redhat) 기리 03-15 2109
 1  2  3  4  5  6  7  8  9