Missing conjunction

Hi Gurus,

I have prepared a script to find the log file based on a date range defined in one of the environment files, archive the logs files and move them to a particular directory.

Below is the script:

. /home/.profile

. /home/.inf_env

logfile=$scripts_path/Logs/file_archive1.log

# Get the list of Integration Services

infacmd.sh listservices -dn $INFA_DOMAIN -un Administrator -st IS | sed '$d' > temp_fa.txt

echo "List of Integration Services:\n`cat temp_fa.txt`" >> $logfile

while read line

   do
           echo "Integration Service Name =\n" $line >> $logfile


         ISPath=$(grep $line < $scripts_path/integration_services.txt | awk '{print$2}')

              echo "Integration Service path:"$ISPath

   cd $ISPath/SessLogs

   counter=`find . -name "*.bin" -type f -mtime +$file_arch_st_time -mtime -$file_arch_end_time | wc -l`

     if [ ${counter} -eq 0 ]; then

        echo "Session Logs not found for the date range" >> $logfile

     else
       
    find . -name "*.bin" -type f -mtime +$file_arch_st_time -mtime -$file_arch_end_time -exec ls -l {} \; | gtar cvf SessLogs`date +%Y%m%d` SessLogs`date +%Y%m%d`| compress -
    v SessLogs`date +%Y%m%d`>> $logfile

        echo "Number of SessionLogs deleted:"`find . -name "*.bin" -type f +$file_arch_st_time -mtime -$file_arch_end_time -exec ls -l {} \; | wc -l` >> $logfile

       #find . -name "*.bin" -type f -mtime +$file_arch_st_time -mtime -$file_arch_end_time -exec rm {} \;

           mv -f SessLogs`date +%Y%m%d`.Z $ISPath/Archive

               RC=$?
                           if [ $RC != 0 ]; then
                                   echo "Failed to move the compressed file" >> $logfile
                           fi
     fi

    done < temp_fa.txt

But when I try to run this script, i am getting the following error:

gtar: SessLogs20101220: file is the archive; not dumped
find: missing conjunction

I am clueless about these 2 errors. Please let me know the issue with the script.

Regards,
Sam

echo "Number of SessionLogs deleted:"`find . -name "*.bin" -type f -mtime +$file_arch_st_time -mtime -$file_arch_end_time -exec ls -l {} \; | wc -l` >> $logfile

You missed -mtime in your code

The problem with your tar command is that

gtar cvf SessLogs`date +%Y%m%d` SessLogs`date +%Y%m%d`

Should just be

gtar cvf SessLogs`date +%Y%m%d`

However, I can't see what you want to achieve by piping a long directory listing into the standard input of tar. Perhaps you should be using cpio instead of tar and using 'find ... -print' instead of 'find ... -exec ls -l {} \;'

All three of these "find" make no sense even though they are not a syntax error (after syntax correction).
With respect to the values if $file_arch_st_time and $file_arch_end_time what (in words) are the commands intended to do?

Does not define the range.

Thanks Anurag for your suggestion. It fixed the problem. But now i run into a different issue. Somehow i am not able to uncompress/untar the compressed file.

It gives the below error.

file is the archive; not dumped

Kevin,

Is it because of the issue you highlighted?

Also I read in one of the article that the cpio has a limitation of max 2 GB for each file. But my files might be more than 2 GB in some scenarios.

Sam

---------- Post updated at 04:44 PM ---------- Previous update was at 04:40 PM ----------

@methyl

Suppose, I defined the values for below variables in my environment file as

file_arch_st_time=7
file_arch_end_time=14

then the script substitutes the above values and finds the files between 7 and 14 days. Please let me know if this incorrect way of writing the script

Regards,
Sam

Your gtar command says:

gtar cvf filename filename

Which means create a tar archive of the file called filename and store it in the file called filename, ie. the same file, so you get the error 'file is the archive.'

The 2GB file size limit is a limit of 32 bit versions of linux, not cpio, so you would get the same limit with tar. However, if you use compression, as you are trying to do, it would be the compressed file that would need to be less than 2GB. By the way, if you want to create a compressed tar file you would use:

gtar cvzf filename

You don't pipe tar to compress, you can pipe cpio to compress.

OK. Thanks. But when I use the below statement,

find . -name "*.bin" -type f -mtime +7 -mtime -14 | gtar cvzf SessLogs`date +%Y%m%d`.tar

I am getting the following error.

gtar: Cowardly refusing to create an empty archive
Try `gtar --help' or `gtar --usage' for more information.

It may be that this boolean version will produce the desired range. The specification is still ambiguous but I think that we are homing in on the solution!
The problem with the original "find" parameters is that the second "-mtime" takes precedent over the first "-mtime".

find . -name "*.bin" -type f \( -mtime +$file_arch_st_time -a -mtime -$file_arch_end_time \)
gtar cvzf SessLogs`date +%Y%m%d`.tar SessLogs`date +%Y%m%d`

I guess you need to do this. This will move content of SessLogs`date +%Y%m%d` into SessLogs`date +%Y%m%d`.tar

1 Like

You either use something like:

find . -print | cpio -ov | compress > backupfile

or you use:

tar cvzf backupfile file1 file2 file3 ...

so you would have something like:

find . -print > tempfile
tar cvzf backupfile.tgz `cat tempfile`
or
tar cvzf backupfile.tgz --file=tempfile

You can't mix the methods up.

You need to test these individual lines of your script one at a time.

@Kevin,

Great thanks. It now creates the file. I used the command like this.

find . -name "*.bin" -type f -mtime +7 -mtime -60 | cpio -ov | compress -v > SessLogs`date +%Y%m%d`.Z

It creates a file called SessLogs20101220.Z.

I uncompress this file using the command

uncompress -f SessLogs20101220.Z

it uncompresses the file and creates an uncompressed file

SessLogs20101220

Now how to extract contents from the uncompressed file?

-Sam

---------- Post updated at 05:59 PM ---------- Previous update was at 05:56 PM ----------

Thanks Kevin.

I used the following command as you suggested.

find . -name "*.bin" -type f -mtime +7 -mtime -60 | cpio -ov | compress -v > SessLogs`date +%Y%m%d`.Z

Now it creates a file called

SessLogs20101220.Z

I uncompress the above file using

uncompress -f SessLogs20101220.Z

It creates a uncompressed file

SessLogs20101220

Now how to extract the contents from an uncompressed file?

Thanks much

Sam

Note I still think you need to use -print with cpio.

You would be better not to uncompress your file in case you hit the 2GB file size limit.

To list what is in the file use:

zcat SessLogs20101220.Z | cpio -itv

To extract it I would use something like:

zcat SessLogs20101220.Z | cpio -iduv

Please check the man page for cpio to see what the best options for you are.

If zcat isn't on your system try gzcat.

1 Like

You cannot have two "-mtime" parameters on the same "find" command line without using brackets. It will not give you a syntax error but it will not work.

1 Like

Thanks Kevin, Methyl and Anurag Singh. Let me try the options suggested by you.

Thanks much.

Sam

---------- Post updated at 11:35 AM ---------- Previous update was at 10:31 AM ----------

Methyl -- Can you pl explain the above statement in detail?

Also I have changed the find command per your suggestions.

find . -name "*.bin" -type f \( -mtime +$file_arch_st_time -a -mtime -$file_arch_end_time \) | cpio -ov | compress -v > SessLogs`date +%Y%m%d`.Z

But it gives the following error:

w_test.bin not archived: uid greater than 65535.
1 blocks

It creates the compressed file with 0 bytes

Regards
Sam

If you run the find command on its own does it give you a list of files? What I mean is just run:

find . -name "*.bin" -type f \( -mtime +$file_arch_st_time -a -mtime -$file_arch_end_time \)

See what it outputs.

Hey Kevin,

Yes it i am able to run it.

dev09:/Tst/SessLogs>cat test.ksh

#!/bin/ksh

. /home/.infa_env

find . -name "*.bin" -type f \( -mtime +$file_arch_st_time -a -mtime -$file_arch_end_time \)


dev09:/Tst/SessLogs>test.ksh
./s_LIMIT.log.bin
./s_OUT.log.bin
./s_TEST.log.bin
./s_ff.log.bin
dev09:/Tst/SessLogs>

@Kevin, Anurag -- tar cvzf option seems to be not working in our servers. We have AIX machine and i am getting the following error. Is there any other option to tar and zip the file in one go?

Usage: tar -{c|r|t|u|x} [ -BdDEFhilmopRsUvwZ ] [ -Number ] [ -f TarFile ]
           [ -b Blocks ] [ -S [ Feet ] | [ Feet@Density ] | [ Blocksb ] ]
           [ -L InputList ] [-X ExcludeFile] [ -N Blocks ] [ -C Directory ] File ...
Usage: tar {c|r|t|u|x} [ bBdDEfFhilLXmNopRsSUvwZ[0-9] ]
           [ Blocks ] [ TarFile ] [ InputList ] [ ExcludeFile ]
           [ [ Feet ] | [ Feet@Density ] | [ Blocksb ] ] [-C Directory ] File ...

You would need to get hold of a copy of GNU Tar (gtar) for AIX, or download the source and compile it. Try the tar package from here: IBM AIX Toolbox for Linux Applications - Alphabetical Listing