fixed error when script is called via sudo