I have this in my bash script
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
asked May 16, 2011 at 12:49
Mahakaal
2,1859 gold badges29 silver badges38 bronze badges
-
1Step by step is the easiest way.johnsyweb– johnsyweb2011年05月16日 12:59:25 +00:00Commented May 16, 2011 at 12:59
-
Show us what you've written thus far and any errors you are getting and we will help with that. We can't just 'do it for you'tMC– tMC2011年05月16日 13:31:18 +00:00Commented May 16, 2011 at 13:31
-
i am reading the os module and i will post back when done . thanksMahakaal– Mahakaal2011年05月16日 13:50:48 +00:00Commented May 16, 2011 at 13:50
2 Answers 2
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.
answered May 16, 2011 at 12:55
Bruce
7,1421 gold badge27 silver badges42 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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())
answered May 16, 2011 at 14:57
Noctis Skytower
22.1k16 gold badges87 silver badges123 bronze badges
Comments
default