[Tutor] Simple Linux Admin1, New guy looking for some tips.

Sean 'Shaleh' Perry shaleh at speakeasy.net
Sat Feb 7 13:24:09 EST 2004


On Friday 06 February 2004 22:21, Joshua Banks wrote:
> Example:........(And I know that this can be done very simply using
> other means besides Python)
>

like maybe logrotate (-:  But hey, learning by reimplementing *CAN* be useful.

>
> Specifically, I would like to accomplish the following with a Python
> script.
>
> 1) Compress all files located in "/var/log/portage/" (not sure which
> compression utility is the best for this case)
>

standard gzip is the answer here.  bzip2 might give you slightly higher 
compression but it also uses more cpu and for this case is not really worth 
it.

> 2) Create a subdirectory located within the Parnet "portage" directory
> called "LogArchive", and place the compressed files from the "portage"
> directory into newly created subdirectory "LogArchive".
>
> #My Mental note: I would preferably like to compress all files together
> if possible instead of individually. Not sure how that is best done
> though. Maybe thats directory compression... Hmmmm.. never done that
> before.
>
> How do I do this with Python considering "#My Mental note:"? I will use
> this example as a building point instead of jumping into the wxPython
> stuff that my brother keeps trying to push on me.. I just don't want to
> learn the GUI stuff until I feel alot more comfortable with Python
> basic's. Concepts and Symantics.
>

why put them in one archive?  That means if you ever do need the file you have 
to go hunting for it.

Ok, let's say you do want to store them in one archive.  The standard tool to 
use is called 'tar' which stands for 'tape archive'.  But most people use it 
to put lots of files into one file for easier network moving.

So as the other commented on this thread says, first look at the problem and 
try to write it out completely in just English.  "I want a script 
which ....".  Then try to write an outline for the code, again in English.  
Just like you were going to write an essay.

For this task, you probably want to look at the sys and os modules in Python.




More information about the Tutor mailing list