scrap the shell script and recode in Python