Forum Moderators: coopster & phranque

Message Too Old, No Replies

Cron

         

BoneHeadicus

3:38 am on May 2, 2001 (gmt 0)

10+ Year Member



Hey SK, I am trying to do a little automation with the cron thing again.

I would like to be able to tar (zip) the contents of a folder containing multiple log files from a tracking script at 12:01 am on the 1st of every month and place the archived files in a different folder out of the way.

Can you help?

sugarkane

6:23 pm on May 2, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sure,

Your basic shell script would be something like:


#!/bin/bash

cd /path/to/logs/folder
tar cv * > logs.tar
mv logs.tar /out/of/the/way

You might want to add in a 'rm *' as the last line to get rid of the old log files.

Then create a text file containing:
1 0 1 * * nameofscript

and issue 'crontab nameoftextfile'

BoneHeadicus

7:06 pm on May 2, 2001 (gmt 0)

10+ Year Member



Thanks SK...you're alright.

You know I'm starting to catch on to "penguinese". I understand everything you did there except for the "tar cv * > logs.tar" line.

sugarkane

7:33 pm on May 2, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, you know what tar does - sort of an equivalent to zip, it archives a group of files into a single file along with the information needed to split it back up again. It doesn't do compression by default, but you can turn it on with a 'z' option.

The 'cv' option means create & verbose - create is for a new archive (another option is 'a' for append onto an existing archive), and do it verbosely (ie show as much information as possible).

The * just means add every file to the archive.

The default destination for tar's output is the screen, so the > tells *nix that you want to redirect the output to somewhere else - in this case 'logs.tar'

Keep on with the penguinese - you'll be thinking in heiroglyphics in no time :)