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())
精彩评论