I am trying to build a python script that I have run every day to fetch that days DNS requests from OpenDNS from the previous 2 days. This is what I have so far.
import subprocess
import datetime
two = datetime.date.today() - datetime.timedelta(2)
one = datetime.date.today() - datetime.timedelta(1)
path = '~/Downloads/opendns-fetchstats-master'
dateRange = str(two) + ' ' + str(one)
dateRange2 = str(two) + 'to' +str(one)
username = 'email@email.com'
password = 'password'
outputFile = dateRange2 + '.csv'
print dateRange2
subprocess.call(
['cd ' + str(path) + ' && echo '+ str(password) + ' | bash fetchstats ' +
str(username) + ' home ' + str(dateRange) + ' > ' + str(outputFile)],
shell=True
)
The problem is that after it runs:
bash fetchstats ' + str(username) + ' <network_id> ' + str(dateRange) + ' > ' + str(outputFile)
it then asks for the password to the account. I can not figure out how to input the password. My attempt at using
echo password |
works partially but the process returns the error below and the process ends before all the data can be downloaded
stty: standard input: Inappropriate ioctl for device stty: standard input: Inappropriate ioctl for device
Is there a way I can write this so the process enters the password when prompted and then waits until the download is complete before ending the process?