shankar
shankar

Reputation: 441

I am trying to send mail in python using shell command . But variable does not get substituted in script

import subprocess
to ='[email protected]'
subject= 'hostname'
cmd= "cat /var/log | mailx -s 'swap is full on'+subject" +to
subprocess.Popen(cmd,shell=True)

if i place double quote before subject then mailx takes first character as subject and treat other as the recipient and try to send mail to them .

--------------------out put of cmd= "cat /var/log | mailx -s 'swap is full on'"+subject +to

Upvotes: 1

Views: 1231

Answers (1)

Vickrant
Vickrant

Reputation: 1303

Can you try this:

import subprocess
to ='[email protected]'
cmd= "cat /var/log | mailx -s 'test' " + to
subprocess.Popen(cmd,shell=True)

Upvotes: 1

Related Questions