Email script to check mounted volumes at certain time

cwcampb
New Contributor II

I'm looking for either bash or python script to check mounted volumes at the end of the day. I found a python email script,  just need the volume check added into the script.

 

Thanks!

 


#!/usr/bin/python #################################################################################################### # # ABOUT # # Script to send plain-text email: # * Parameter 4: recipient # * Parameter 5: subject # * Parameter 6: message # #################################################################################################### # # HISTORY # # Version 1.0, 7-Dec-2015, Dan K. Snelson # #################################################################################################### # Import commands import commands, os, sys, smtplib, email from email import encoders SMTP_SERVER = 'smtp.company.com' SMTP_PORT = 25 SMTP_FROM = 'noreply@company.com' # Must be a complete email address SMTP_TO = str(sys.argv[4]) # Parameter 4: recipient SUBJECT = str(sys.argv[3]) + ", " + str(sys.argv[2]) + ": " + str(sys.argv[5]) # Parameter 5: subject MESSAGE = str(sys.argv[6]) # Parameter 6: message msg = email.MIMEMultipart.MIMEMultipart() body = email.MIMEText.MIMEText(MESSAGE) msg.attach(body) msg.add_header('From', SMTP_FROM) msg.add_header('To', SMTP_TO) msg.add_header('Subject', SUBJECT) # Now send the message mailer = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) mailer.sendmail(SMTP_FROM, [SMTP_TO], msg.as_string()) mailer.close() 


 

1 REPLY 1

sydowl
New Contributor II

Hi - I may not be understanding what you mean, but you can try

print(os.listdir("/Volumes"))

If you only want the email if there's other drives other than the HD mounted:
x = len(os.listdir("/Volumes"))
if x > 2:
 (command to send email with listdir array)