Apr-26-2023, 01:47 PM
I have a shell script that is as follows:
I was thinking of copying the whole command in a single python string cmd_str then run
Any suggestions?
LOAD_RRD=sysmon.rrd DISK_RRD=disk.rrd DISKTEMP_RRD=disktemp.rrd rrdtool graph load1h.png \ -Y -u 1.1 -l 0 -L 5 -v "Load" -w 700 -h 200 -t "Load stats - `/bin/date`" \ --start end-"1h" --x-grid MINUTE:1:MINUTE:5:MINUTE:10:0:%R \ -c ARROW\#000000 \ DEF:load1=$LOAD_RRD:load1:AVERAGE \ DEF:load5=$LOAD_RRD:load5:AVERAGE \ DEF:load15=$LOAD_RRD:load15:AVERAGE \ LINE1:load1\#ff0000:"Load average 1 min" \ LINE1:load5\#ff6600:"Load average 5 min" \ LINE2:load15\#ffaa00:"Load average 15 min" \ COMMENT:" \j" \ COMMENT:"\j" \ COMMENT:" " \ GPRINT:load15:MIN:"Load 15 min minimum\: %lf" \ GPRINT:load15:MAX:"Load 15 min maximum\: %lf" \ GPRINT:load15:AVERAGE:"Load 15 min average\: %lf" \ COMMENT:" \j" \ COMMENT:" " \ COMMENT:" \j" >/dev/null;I want to convert it to python using the subprocess module and run similar commands but with manipulating the internal variables and parameters.
I was thinking of copying the whole command in a single python string cmd_str then run
subprocess.run(cmd_str, shell=True)But I'm not on the best way to escape all those internal quotes and other special symbols.
Any suggestions?