Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Log Script

Status
Not open for further replies.

heprox

IS-IT--Management
Dec 16, 2002
178
US
I'm working on a AIX 4.3.3 server running Oracle 8i. I need to create a script (preferably in Korn) that does the following:

1. Identifies files (log files and *.err files)in several directories, in a loop, that are older than 24 hours.

2. Places all of the identified files from step #1 and places them in a compressed tar file (with a file name in mmddyy format)in a specific directory.

3. Initiates an FTP session that moves the file to a remote server.

Step #3 is optional (I may do this in VB from the parent FTP server and just get the file in reverse).

Ideas:
Using "find $dirs -type f -name "*.err" -atime +1" or someting similar, but can't figure out how to designate what directories to look in (handled by a variable?) and how to move them through a loop. I'm thinking of just designating the directories and the filenames (to be looked for) by comma-deliminated variables? Any help would be appreciatted. Thanks.
 
There's no need for a loop as find accepts multiple directories. So you could use something like:

[tt]#!/bin/ksh
DATE=$(date +%d%m%y)
tar cvf - $(find /var/adm /other/logs /more/logs \( -name "*.err" -o -name "*.log" \) -atime +1 -print) | compress -c > /tmp/logs_${DATE}.tar.Z
ftp -nv logdrophost << HERE
user username password
bin
cd /somewhere
put /tmp/logs_${DATE}.tar.Z logs_${DATE}.tar.Z
HERE[/tt] Annihilannic.
 
I'm using:

#!/bin/ksh
DATE=$(date +%m%d%y)
DATADIR=<data directories>
FILENAME=<filenames>
tar cvf - $(find ${DATADIR} -type f -name $ -mtime +1 -print) | compress -c > /tmp/logs_${DATE}.tar.Z

...but I continue to get empty archives. I'd like to be able to have two variables DATADIR and FILENAME and be able to just edit the script to add different directories and/or filenames (i.e. comma delminated?). In addition when I create this archive I would like the original(s) (*.err) to be deleted from the DATADIR location(s). I intend to either have the script set up an FTP session and send the file to a remote server or create a second script that sends the files every few days to a remote server. Any help is appreciatted. Thanks.
 
&quot; -name $ &quot;? Isn't something missing there?

find won't understand -name filename1 filename2 etc. You need to use the brackets as per my example with -o -name between each filename.

Try getting the find command, i.e. the part between $( and ), to list the correct files on its own before getting the tar and compress parts working. Annihilannic.
 
Correct, I made a typo, sorry. I've got this working and it creates the archive correctly:

#!/bin/ksh
DATE=$(date +%m%d%y)
DATADIR=/gers/nurev/trc/temp
tar -cvf - $(find ${DATADIR} -type f -name &quot;*.err&quot; -mtime +1 -print) | compress -c > /tmp/DWMlogs_${DATE}.tar.Z

...now what I need is for it to be able to handle the filenames as a variable and then just define the variable as:

FILENAME=*.err:dwm*.* or sonething like that?

...then figure out how to delete the original files (*.err, etc) after it creates the archive.
 
OK this is working correctly:

#!/bin/ksh
DATE=$(date +%m%d%y)
DATADIR=/gers/nurev/trc/temp
FILENAME=&quot;dwm*.*&quot;
tar -cvf - $(find ${DATADIR} -type f -name ${FILENAME} -mtime +1 -print) | compress -c > /tmp/DWMlogs_${DATE}.tar.Z

...now how do you get the script to realize different directories nad filenames? I've tried:

FILENAME=&quot;dwm*.*&quot;:&quot;DWM*.*&quot;:&quot;log*.err&quot;

and

FILENAME=&quot;dwm*.*&quot;;&quot;DWM*.*&quot;;&quot;log*.err&quot;

and

FILENAME=&quot;dwm*.*&quot;,&quot;DWM*.*&quot;,&quot;log*.err&quot;

and

FILENAME=&quot;dwm*.*&quot; &quot;DWM*.*&quot; &quot;log*.err&quot;

...too no avail?

 
heprox,
Did you not read Annihilannic's post?
find won't understand -name filename1 filename2 etc. You need to use the brackets as per my example with -o -name between each filename. //Daniel
 
My fault, I didn't catch what he was trying to tell me. What I'm trying to accomplish is setting up a variable that I can add and subtract directories and filenames from at will without having to go and mess with the body of the script (easier that way...). Now I just have to find out how to remove the original files once they're archived. Thanks.

 
Well I settled on this:

#!/bin/ksh
DATE=$(date +%m%d%y)
tar cvf - $(find /gers/nurev/trc/temp /gers/genret/trc/temp \( -name &quot;dwm*.*&quot; -o -name &quot;DWM*.*&quot; \) -mtime +1 -print) | compress -c > /tmp/DWMlogs_${DATE}.tar.Z

...but I'm getting the following error:

/usr/bin/dwm_purge[3]: /usr/bin/tar: 0403-027 The parameter list is too long.

...any ideas?
 
You might have to do it in two steps then; do the find on its own and redirect the output into a file, and then use tar -I tempfilename. Annihilannic.
 
Do you mean split the operations of the script? Conduct two seperate finds? I'm having difficulty getting &quot;find&quot; to lookl in different directories:

#!/bin/ksh
DATE=$(date +%m%d%y)
find /gers/nurev/trc/temp /gers/genret/trc/temp \( -name dwm.* -o -name &quot;DWManager.*&quot; \) -type f -mtime +1 -print

...finds files with both the &quot;dwm.* and &quot;DWManager.*&quot; names, but DOES NOT look in both the &quot;/gers/nurev/trc/temp&quot; and the &quot;/gers/genret/trc/temp&quot; directories. It only looks in the last directory named? Any help?
 
Unfortunately I can't test on AIX as I don't have access to it anywhere.

I notice you're missing some quotes around &quot;dwm.*&quot;.

By two steps I mean something like this:

[tt]find a/ b/ \( -name &quot;dwm.*&quot; -o -name &quot;DWManager.*&quot; \) -type f -mtime +1 -print > /tmp/find.out.$$
tar cvf - -I /tmp/find.out.$$ | compress -c > /tmp/DWMlogs_${DATE}.tar.Z
rm /tmp/find.out.$$[/tt]

Specifying multiple directories like that works fine for me, maybe it's something peculiar to find on AIX?

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top