def check_and_run() :
imap_conn = imapclient.IMAPClient (domain_name, ssl = True)
print (imap_conn)
try :
print (imap_conn.login (emailaddress, password))
except :
print ('Wrong username password combination! Please try again.')
sys.exit()
print (imap_conn.select_folder ('INBOX', readonly = False))
uids = imap_conn.gmail_search ('label:' + label + ' label:Inbox ' + emailaddress + ' subject:' + mysubject + ' label:unread')
print (uids)
messages = imap_conn.fetch (uids, ['BODY[]'])
for x in messages.keys() :
lstcomm = pyzmail.PyzMessage.factory (messages[x][b'BODY[]'])
commands.append (lstcomm.text_part.get_payload().decode (lstcomm.text_part.charset))
print (imap_conn.logout())
twilioClient = TwilioRestClient (twilioSID, twilioAuthToken)
for x in commands[::-1] :
newfile = open ('commandstorun.py', 'w')
newfile.write ('#! /usr/bin/python3\n')
newfile.write (x)
newfile.close()
os.system ('chmod +x commandstorun.py')
os.system ('./commandstorun.py')
print ('Executed script :\n' + x)
msg = twilioClient.messages.create (body = 'Your script has been executed! ' + x, from_ = sender, to = receiver)
print (msg.status)
Execute_Instructions_Remotely.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录