Eu tenho o seguinte script para monitorar alguns processos em execução:
$ cat ./print_running.sh
#!/bin/bash
ps aux | grep 'python energydata.py' | sed -r 's/\{"spectral": 0//;s/, "pp_enable.*y": 0.9,//;s/ "consumer.*ressure": 0.15,//; s/ "gamma.*//'
Quando eu o executo no terminal, recebo a saída abaixo:
user 27994 37.6 1.0 706712 125148 pts/19 R 15:46 0:46 python energydata.py , "l_max": 0.25 "level_flexibility": 5, "pi": 0.6489865, "z_input": 0.4450386,
user 28138 37.9 1.0 706716 124852 pts/19 R 15:47 0:32 python energydata.py , "l_max": 0.75 "level_flexibility": 5, "pi": 0.3928358, "z_input": 0.4836933,
user 28255 38.2 1.0 706716 125004 pts/19 R 15:47 0:12 python energydata.py , "l_max": 0.5 "level_flexibility": 5, "pi": 0.4088101, "z_input": 0.5011101,
user 28267 38.5 1.0 706712 125152 pts/19 R 15:47 0:13 python energydata.py , "l_max": 0.75 "level_flexibility": 5, "pi": 0.5223562, "z_input": 0.4416432,
user 28287 39.3 1.0 706712 125084 pts/19 R 15:48 0:10 python energydata.py , "l_max": 0.5 "level_flexibility": 5, "pi": 0.1073945, "z_input": 0.6377535,
user 28291 39.1 1.0 706708 124824 pts/19 R 15:48 0:10 python energydata.py , "l_max": 0.5 "level_flexibility": 5, "pi": -0.0572559, "z_input": 0.746638,
user 28305 38.9 1.0 706708 124812 pts/19 R 15:48 0:07 python energydata.py , "l_max": 0.5 "level_flexibility": 5, "pi": 0.2459162, "z_input": 0.5575399,
user 28328 38.9 1.0 706716 124836 pts/19 R 15:48 0:03 python energydata.py , "l_max": 0.5 "level_flexibility": 5, "pi": 0.7709965, "z_input": 0.3985181,
user 28329 41.1 1.0 706712 125020 pts/19 R 15:48 0:04 python energydata.py , "l_max": 0.75 "level_flexibility": 5, "pi": 0.6900067, "z_input": 0.3973544,
user 28365 0.0 0.0 14232 1092 pts/2 S+ 15:48 0:00 grep python energydata.py
Mas quando eu executo o comando através de watch
para monitorar a saída em tempo real, o fildering não parece estar funcionando corretamente. A saída é como abaixo:
$ watch ./print_running.sh
user 28427 38.2 1.0 706712 125128 pts/19 R 15:49 0:38 python energydata.py , "l_max": 0.75, "pp_enable": 0.0, "number_of_runs": 1, "profit": 0.0, "consumers_data": {"24": [[63,
user 28445 37.7 1.0 706716 124844 pts/19 R 15:49 0:35 python energydata.py , "l_max": 0.5, "pp_enable": 0.0, "number_of_runs": 1, "profit": 0.0, "consumers_data": {"24": [[63, 7
user 28511 38.0 1.0 706712 124820 pts/19 R 15:50 0:18 python energydata.py , "l_max": 0.5, "pp_enable": 0.0, "number_of_runs": 1, "profit": 0.0, "consumers_data": {"24": [[63, 7
user 28519 38.5 1.0 706716 124528 pts/19 R 15:50 0:18 python energydata.py , "l_max": 0.75, "pp_enable": 0.0, "number_of_runs": 1, "profit": 0.0, "consumers_data": {"24": [[63,
user 28533 39.2 1.0 706712 125348 pts/19 R 15:50 0:15 python energydata.py , "l_max": 0.5, "pp_enable": 0.0, "number_of_runs": 1, "profit": 0.0, "consumers_data": {"24": [[63, 7
user 28546 38.0 1.0 706708 125392 pts/19 R 15:50 0:14 python energydata.py , "l_max": 0.5, "pp_enable": 0.0, "number_of_runs": 1, "profit": 0.0, "consumers_data": {"24": [[63, 7
user 28576 38.4 1.0 706716 125100 pts/19 R 15:50 0:09 python energydata.py , "l_max": 0.5, "pp_enable": 0.0, "number_of_runs": 1, "profit": 0.0, "consumers_data": {"24": [[63, 7
user 28605 39.4 1.0 706712 125152 pts/19 R 15:50 0:07 python energydata.py , "l_max": 0.75, "pp_enable": 0.0, "number_of_runs": 1, "profit": 0.0, "consumers_data": {"24": [[63,
user 28609 37.4 1.0 706716 124868 pts/19 R 15:50 0:07 python energydata.py , "l_max": 0.5, "pp_enable": 0.0, "number_of_runs": 1, "profit": 0.0, "consumers_data": {"24": [[63, 7
user 28675 40.2 1.0 706456 124760 pts/19 R 15:50 0:01 python energydata.py , "l_max": 0.25, "pp_enable": 0.0, "number_of_runs": 1, "profit": 0.0, "consumers_data": {"24": [[63,
user 28689 0.0 0.0 14232 972 pts/2 S+ 15:50 0:00 grep python energydata.py
O problema é quando usamos watch
a lista de argumentos não aparece filtrada, então não posso monitorar os parâmetros que são interessantes para mim.
Perguntas:
- O que causa a diferença na saída quando o script é executado diretamente ou através de
watch
?
- Como posso atualizar o script para que tenha a saída desejada em todos os casos?
Atualização:
A saída completa de ps aux
sem o comando sed é uma das seguintes linhas:
user 32381 24.5 0.7 523028 90816 pts/19 R 16:19 0:00 python energydata.py {"spectral": 0, "l_max": 0.75, "pp_enable": 0.0, "number_of_runs": 1, "profit": 0.0, "consumers_data": {"24": [[63, 73]], "25": [[64, 74]], "26": [[65, 75]], "27": [[66, 76]], "20": [[59, 69]], "21": [[60, 70]], "22": [[61, 71]], "23": [[62, 72]], "28": [[67, 77]], "29": [[68, 78]], "4": [[43, 53]], "8": [[47, 57]], "59": [[66, 76]], "58": [[65, 75]], "55": [[62, 72]], "54": [[61, 71]], "57": [[64, 74]], "56": [[63, 73]], "51": [[58, 68]], "50": [[57, 67]], "53": [[60, 70]], "52": [[59, 69]], "88": [[64, 74]], "89": [[65, 75]], "82": [[57, 67]], "83": [[58, 68]], "80": [[55, 65]], "81": [[56, 66]], "86": [[61, 71]], "87": [[63, 73]], "84": [[59, 69]], "85": [[60, 70]], "3": [[42, 52]], "7": [[46, 56]], "100": [[62, 72]], "39": [[46, 56]], "38": [[45, 55]], "33": [[40, 50]], "32": [[71, 81]], "31": [[70, 80]], "30": [[69, 79]], "37": [[44, 54]], "36": [[43, 53]], "35": [[42, 52]], "34": [[41, 51]], "60": [[67, 77]], "61": [[68, 78]], "62": [[69, 79]], "63": [[70, 80]], "64": [[71, 81]], "65": [[40, 50]], "66": [[41, 51]], "67": [[42, 52]], "68": [[43, 53]], "69": [[44, 54]], "2": [[41, 51]], "6": [[45, 55]], "99": [[43, 53]], "98": [[42, 52]], "91": [[67, 77]], "90": [[66, 76]], "93": [[69, 79]], "92": [[68, 78]], "95": [[71, 81]], "94": [[70, 80]], "97": [[41, 51]], "96": [[40, 50]], "11": [[50, 60]], "10": [[49, 59]], "13": [[52, 62]], "12": [[51, 61]], "15": [[54, 64]], "14": [[53, 63]], "17": [[56, 66]], "16": [[55, 65]], "19": [[58, 68]], "18": [[57, 67]], "48": [[55, 65]], "49": [[56, 66]], "46": [[53, 63]], "47": [[54, 64]], "44": [[51, 61]], "45": [[52, 62]], "42": [[49, 59]], "43": [[50, 60]], "40": [[47, 57]], "41": [[48, 58]], "1": [[40, 50]], "5": [[44, 54]], "9": [[48, 58]], "77": [[52, 62]], "76": [[51, 61]], "75": [[50, 60]], "74": [[49, 59]], "73": [[48, 58]], "72": [[47, 57]], "71": [[46, 56]], "70": [[45, 55]], "79": [[54, 64]], "78": [[53, 63]]}, "weight_flexibility": 0.9, "level_flexibility": 5, "consumer_ids": ["100", "99", "98", "97", "96", "95", "94", "93", "92", "91", "90", "89", "88", "87", "86", "85", "84", "83", "82", "81", "80", "79", "78", "77", "76", "75", "74", "73", "72", "71", "70", "69", "68", "67", "66", "65", "64", "63", "62", "61", "60", "59", "58", "57", "56", "55", "54", "53", "52", "51", "50", "49", "48", "47", "46", "45", "44", "43", "42", "41", "40", "39", "38", "37", "36", "35", "34", "33", "32", "31", "30", "29", "28", "27", "26", "25", "24", "23", "22", "21", "20", "19", "18", "17", "16", "15", "14", "13", "12", "11", "10", "9", "8", "7", "6", "5", "4", "3", "2", "1"], "weight_friendship": 0.1, "select_algorithm": [4], "number_of_clusters": 100, "max_pressure": 0.15, "pi": 0.3606668, "z_input": 0.4976814, "gamma": 1.0, "cost": 0.02} {"nodes_dictionary":[{"24":["4","8","13","23","27","29","54","65","66","86","88","99"],"25":["3","8","15","19","21","23","28","33","41","58","64","71","73","75","80","84","87","90","100"],"26":["2","4","9","18","19","38","39","45","52","59","64","69","72","73","74","80","83","91","92","100"],"27":["14","24","30","43","48","61","72","77","78","89"],"20":["16","31","33","38","45","48","49","55","61","62","66","73","86","98"],"21":["11","12","25","33","35","36","40","49","53","71","84","87","88","98"],"22":["16","18","39","40","43","46","51","62","63","86","94"],"23":["1","4","8","9","15","18","24","25","34","35","51","52","61","70","72","78","86","87","97"],"28":["1","14","25","30","33","38","41","48","63","64","65","67","89","92"],"29":["2","8","16","24","39","40","46","56","59","63","73","81","99"],"4":["11","15","23","24","26","38","55","76","81","83","85","86","92"],"8":["1","2","17","23","24","25","29","36","51","69","78","87","95","96"],"59":["5","15","26","29","38","48","54","57","61","62","63","74","79","83","85","89","90","92"],"58":["9","11","12","18","25","44","47","51","86","93"],"55":["4","6","14","18","20","31","32","38","44","47","60","61","62","66","68","84","94","96"],"54":["3","17","24","30","40","42","45","48","52","57","59","65","68","73","74","80","81"],"57":["14","15","34","36","37","54","59","62","67","86","93","94","95","96","98"],"56":["2","14","17","18","29","46","53","60","64","74","82","85","97","98"],"51":["8","13","15","16","17","22","23","30","36","37","40","47","58","62","63","68","70","79"],"50":["7","10","17","18","85","93"],"53":["12","21","37","47","56","60","61","62","67","73","74","78","81","90","97"],"52":["11","18","23","26","36","44","47","54","69","71","74","76","78","84","100"],"88":["6","7","18","21","24","32","61","62","82","87","94"],"89":["13","15","18","27","28","31","33","46","59","60","65","66","78","87","97"],"82":["9","11","13","14","32","35","36","47","56","64","67","72","76","84","88","92"],"83":["4","6","26","30","32","37","44","49","59","62","74","90"],"80":["3","25","26","36","54","61","62","73","84","99"],"81":["4","11","15","19","29","35","38","47","53","54","61","72","73","78","79","91"],"86":["2","4","11","19","20","22","23","24","34","37","47","57","58","60","68","75","97","99"],"87":["1","8","12","15","21","23","25","34","37","47","61","62","66","75","88","89","98"],"84":["2","7","13","21","25","32","40","48","49","52","55","61","62","63","64","71","80","82","94","100"],"85":["4","5","7","9","36","38","47","49","50","56","59","93","98"],"3":["6","14","17","25","43","48","54","62","63","73","80","94"],"7":["46","50","67","72","84","85","88","100"],"100":["7","9","13","25","26","39","40","42","44","47","48","52","77","79","84"],"39":["2","5","6","12","22","26","29","31","35","38","43","46","49","65","98","100"],"38":["4","20","26","28","39","41","42","45","55","59","66","68","74","81","85","90","97","99"],"33":["5","10","14","20","21","25","28","32","35","40","64","66","89","96","98"],"32":["9","10","16","17","18","33","42","55","73","76","82","83","84","88","91"],"31":["9","20","39","42","48","55","66","72","73","89","98","99"],"30":["9","17","27","28","43","46","51","54","60","62","71","83"],"37":["14","51","53","57","65","66","68","83","86","87","93","94","96","97"],"36":["8","11","16","18","21","34","51","52","57","67","68","80","82","85","99"],"35":["1","9","13","19","21","23","33","39","60","65","66","68","69","73","76","81","82","94","98"],"34":["19","23","36","42","43","57","64","75","86","87"],"60":["6","9","11","13","17","30","35","42","45","47","49","53","55","56","72","86","89"],"61":["15","20","23","27","53","55","59","71","76","79","80","81","84","87","88"],"62":["3","20","22","30","51","53","55","57","59","77","80","83","84","87","88","93","96","97"],"63":["3","5","10","16","18","22","28","29","47","49","51","59","70","72","75","84","91","92","94","95"],"64":["6","11","13","19","25","26","28","33","34","41","46","56","69","79","82","84","90","91","92"],"65":["9","12","14","24","28","35","37","39","54","89"],"66":["1","6","13","20","24","31","33","35","37","38","40","55","67","79","87","89"],"67":["7","13","14","15","17","19","28","36","41","44","45","48","53","57","66","74","82","90","92","95","97"],"68":["10","15","35","36","37","38","44","47","48","51","54","55","70","75","86","91","95"],"69":["2","8","9","11","26","35","43","46","48","52","64","97","98"],"2":["5","8","10","19","26","29","39","56","69","73","84","86","98"],"6":["3","5","12","15","17","39","43","45","55","60","64","66","73","83","88","92"],"99":["13","24","29","31","36","38","72","80","86","97","98"],"98":["2","9","20","21","31","33","35","39","42","44","45","56","57","69","73","85","87","97","99"],"91":["12","13","18","19","26","32","49","63","64","68","72","81"],"90":["10","15","25","38","48","53","59","64","67","79","83","94","95"],"93":["18","37","50","57","58","62","78","85"],"92":["4","6","10","15","26","28","59","63","64","67","73","79","82"],"95":["8","15","40","44","46","57","63","67","68","70","90"],"94":["3","5","11","22","35","37","40","55","57","63","71","72","75","77","84","88","90"],"97":["14","17","19","23","37","38","47","53","56","62","67","69","78","86","89","98","99"],"96":["5","8","33","37","46","55","57","62","79"],"11":["4","9","10","19","21","36","44","46","48","52","58","60","64","69","72","76","78","81","82","86","94"],"10":["2","11","32","33","44","50","63","68","71","75","77","78","90","92"],"13":["18","24","35","40","51","60","64","66","67","76","78","82","84","89","91","99","100"],"12":["6","17","21","39","41","43","53","58","65","76","78","79","87","91"],"15":["4","6","23","25","40","44","51","57","59","61","67","68","70","71","81","87","89","90","92","95"],"14":["1","3","17","18","27","28","33","37","45","48","55","56","57","65","67","73","75","82","97"],"17":["3","6","8","9","12","14","30","32","50","51","54","56","60","67","72","75","76","97"],"16":["20","22","29","32","36","43","48","51","63"],"19":["2","9","11","25","26","34","35","64","67","79","81","86","91","97"],"18":["13","14","22","23","26","32","36","50","52","55","56","58","63","79","88","89","91","93"],"48":["1","3","11","14","16","20","27","28","31","44","54","59","67","68","69","72","76","84","90","100"],"49":["5","20","21","39","42","60","63","83","84","85","91"],"46":["1","7","11","22","29","30","39","40","41","47","56","64","69","73","89","95","96"],"47":["5","9","40","44","45","46","51","52","53","55","58","60","63","68","78","81","82","85","86","87","97","100"],"44":["10","11","15","47","48","52","55","58","67","68","74","78","83","95","98","100"],"45":["6","14","20","26","38","47","54","60","67","79","98"],"42":["31","32","34","38","41","49","54","60","98","100"],"43":["3","6","12","16","22","27","30","34","39","40","69","79"],"40":["13","15","21","22","29","33","43","46","47","51","54","66","76","84","94","95","100"],"41":["12","25","28","38","42","46","64","67","73"],"1":["8","14","23","28","35","46","48","66","87"],"5":["2","6","33","39","47","49","59","63","76","85","94","96"],"9":["11","17","19","23","26","30","31","32","35","47","58","60","65","69","82","85","98","100"],"77":["10","27","62","94","100"],"76":["4","5","11","12","13","17","32","35","40","48","52","61","82"],"75":["10","14","17","25","34","63","68","71","73","74","86","87","94"],"74":["26","38","44","52","53","54","56","59","67","75","83"],"73":["2","3","6","14","20","25","26","29","31","32","35","41","46","53","54","75","80","81","92","98"],"72":["7","11","17","23","26","27","31","48","60","63","78","81","82","91","94","99"],"71":["10","15","21","25","30","52","61","75","84","94"],"70":["15","23","51","63","68","95"],"79":["12","18","19","43","45","51","59","61","64","66","81","90","92","96","100"],"78":["8","10","11","12","13","23","27","44","47","52","53","72","81","89","93","97"]}]}