Use python to automate the operation and maintenance

  Today saw the resulting file on a linux server itself is not deleted before, and now want to delete. Characteristics of the file: uuid as a folder name, a lot of 30+. So wanted to write a script to delete, shell scripts are not familiar with, and linux comes with python2.7. So I decided to write python is a batch script to delete the file.

  However, in preparing local, there has been a problem \\ escape, reflecting you are unfamiliar with python syntax. Then the local test, os.remove function error, no premission. I thought it was really no authority, unfortunately, os.remove method can only be used to delete files instead of folders, here I suspect that their traversal is not right. In fact, python has been widely used in the field of operation and maintenance, which is shutil package instead of shell, this should be basic knowledge python developer, shutil.rmtree () method directly delete a folder, rather than write your own recursive delete function, very much in line python style, you usually can not see the accumulation of these things. Then run linux python script is not very skilled, so their present their work is still quite inefficient. Urgent need to learn to broaden their skills.

Guess you like

Origin www.cnblogs.com/Robin008/p/11403113.html