daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Dec 29th, 2016 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import subprocess
  2. import os
  3. import stat
  4. dmi = subprocess.check_output('dmidecode', shell=True)
  5. #print(variable)
  6. #run program once as root then cron it as root
  7. try :
  8.     file = open("/var/log/serialcontrol/dmidecode.txt", "r")
  9.     file.close()
  10. except FileNotFoundError:
  11.     script = '/var/tmp/serialcontrol.bash'
  12.     with open(script, 'w') as file:
  13.         file.write("#!/bin/bash/nif [ ! -d /var/log/serialcontrol/ ]nthenntmkdir /var/log/serialcontrol/nfi");
  14.     #st = os.stat(script)
  15.  
  16.     #os.chmod(script, st.st_mode | stat.S_IEXEC)
  17.  
  18.     subprocess.call(["bash", script])
  19.     subprocess.call(["rm", script])
  20. #with open('/var/log/serialcontrol/dmidecode.txt' , 'w') as file:
  21. #        file.write(dmi);
  22. file = open("/var/log/serialcontrol/dmidecode.txt" , "w");
  23. dmi = str(dmi)
  24. dmi = dmi.replace('\n', 'n')
  25. dmi = dmi.replace('\t', 't')
  26. file.write(dmi)
  27. file.close()
  28. script2 = '/var/log/serialcontrol/serialcontro1.bash'
  29. #with open(script2, 'w') as file:
  30. #   file.write('#!/bin/bashnrecipients="archmachine9@gmail.com"nsubject="...Subject..."necho -e "to: $recipientsnsubject: $subjectn"| (cat - &&uuencode /var/log/serialcontrol/dmidecode.txt) | ssmtp archmachine9@gmail.com')
  31. import smtplib
  32. sender = 'archmachine9@gmail.com'
  33. receivers = 'archmachine9@gmail.com'
  34. message = "rn".join([
  35.     "From: archmachine9@gmail.com",
  36.     "To: archmachine9@gmail.com",
  37.     "Subject: SerialControl",
  38.     "",
  39.     dmi
  40.     ])
  41. username = 'archmachine9@gmail.com'
  42. password = ''
  43. server = smtplib.SMTP('smtp.gmail.com:587')
  44. server.ehlo()
  45. server.starttls()
  46. server.login(username,password)
  47. server.sendmail(sender, receivers, message)
  48. server.quit()
  49. #subprocess.call(["bash", script2])
  50. #this sub is supposed to /n with actual /n's
  51. #subprocess.run(["sed -i 's/\n/n/g' /var/log/serialcontrol/dmidecode.txt"], shell=True)
  52. #except FileNotFoundError:
  53. #file = open('/var/tmp/serialcontrol.bash', 'w')
  54. #file.write("#!/bin/bash/nif [ ! -d /var/log/serialcontrol/]nthenntmkdir /var/log/serialcontrol/nfi");
  55. #file.close()
  56. #st = os.stat("/var/tmp/serialcontrol.bash")
  57. #os.chmod("/var/tmp/serialcontrol.bash", st.st_mode | stat.S_IEXEC)
  58. #subprocess.call("/var/tmp/serialcontrol.bash")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top