I am trying to get a domain name from a cpanel user in python.
Here is my code:
import subprocess
user = "testuser"
getuserdata = 'cat /var/cpanel/users/' + user
getdnsline = 'grep "DNS="'
test = 'wc -l'
userdataprocess = subprocess.Popen(getuserdata.split(), stdout=subprocess.PIPE)
testprocess = subprocess.Popen(test.split(), stdin=userdataprocess.stdout, stdout=subprocess.PIPE)
test, error = testprocess.communicate()
print(test)
dnslineprocess = subprocess.Popen(getdnsline.split(), stdin=userdataprocess.stdout, stdout=subprocess.PIPE)
website, error = dnslineprocess.communicate()
print(website.decode('utf-8').splitlines())
my output is:
b'60\n'
[]
So this means, that the wc -l command gives back 60 lines. So passing the output of the first getuserdata command to the wc -l command works.
However, the grep command always return blank. No matter it I put in "DNS=" or "=" or even "a". The file is the normal cpanel user file, and I have verified that DNS is in the file.
When I just output the data from the first process userdataprocess I can manually check for the DNS entry.
Do I have to do anything different when using the grep command in this fashion?