开发者

Need help to convert the bash code to python equivalent

I have this in my bash s开发者_StackOverflow社区cript

for FOLDERNAME in `\ls -1 /home/`
do
if [ ! -d /backups/home/${date} ]; then
mkdir /backups/home/${date}
chmod 777 /backups/home/${date}
/bin/chgrp ${FOLDERNAME} /backups/home/${FOLDERNAME}
usermod -a -G ${FOLDERNAME} john
fi

how can i convert that to python code


Most of it can be done using the "os" module : I advise you to have a look at the doc of this module, try, and if you have issue, ask for relevant questions.


While not being very familiar with Linux commands, this code should help you in attaining your final goal.

import shutil, datetime
shutil.copytree('/home/', '/backups/home/' + datetime.date.today().isoformat())
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜