#To define a particular parameter, replace the 'parameterName' inside itsm.getParameter('parameterName') with that parameter's name import subprocess as sp import os import sys bash=r''' #!/bin/sh filter='processImagePath contains "backupd" and subsystem beginswith "com.apple.TimeMachine"' # show the last 24 hours start="$(date -j -v-24H +'%Y-%m-%d %H:%M:%S')" log show --style syslog --info --start "$start" --predicate "$filter" | grep 'Copied|successfully' ''' import os path="/var/tmp/bashfile.sh" with open(path,"w") as f: f.write(bash) sp.call(['chmod', '0777', path]) obj=sp.Popen(path,stdin=sp.PIPE,stdout=sp.PIPE,shell=True) print obj.communicate()[0] if os.path.exists(path): try: os.remove(path) except: pass