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.
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?
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 ----------
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.
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 \)
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?
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.
@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?