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

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 42
번호 제   목 글쓴이 날짜 조회
42 [Linux] 서버정보 안보이게 하기 기리 07-17 641
41 [Linux] Redis and phpredis (2) 기리 01-26 809
40 [Linux] Coin 거래소 기리 01-01 662
39 [Linux] SSL 인증 의무화 최고관… 09-15 604
38 [Linux] HTTPS - SSL (1) 최고관… 09-14 628
37 [Linux] mod_ssl 로 보안 강화하기 최고관… 09-14 600
36 [Linux] AWS 아마존 웹 서비스 (3) 최고관… 09-10 663
35 [Linux] 서버 시작 시 IP 메일 보내기 최고관… 07-17 844
34 [Linux] CentOS 7 minimal network 설정 기리 12-22 998
33 [Linux] 리눅스 APM 정의 및 설치(ubuntu, redhat) 기리 03-15 2124
32 [Linux] apache 403 기리 06-16 1473
31 [Linux] 설치 및 설정 기리 06-15 1332
30 [Linux] IP 차단 (1) 기리 03-06 1983
29 [Linux] 자동응답메일 설정 기리 09-23 2112
28 [Linux] Subversion(SVN) 설치 및 사용법 기리 08-13 2900
 1  2  3