I am trying to record capacity utilization while running other (Python) processes with the following script:
#!/bin/bash
rm results/*
top -U $USER > results/test_utilization.txt &
# Give `top` enough time to record something
python3 -c 'import time;time.sleep(10)'
echo "JOB_1_COMPLETE" >> results/test_utilization.txt
python3 -c 'import time;time.sleep(10)'
echo "JOB_2_COMPLETE" >> results/test_utilization.txt
kill %1
My hope is that running something like echo "JOB_<N>_COMPLETE" >> results/test_utilization.txt
will enable me to more easily associate metrics from top
with each "job". However, when I do this: cat results/test_utilization.txt | grep JOB
all I get is this:
$ cat results/test_utilization.txt | grep JOB
JOB_2_COMPLETE
It seems test_utilization.txt
is being overwritten, or something. How can I fix this?