Not able to make the file size 0 with the mentioned script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not able to make the file size 0 with the mentioned script
# 1  
Old 10-01-2010
Not able to make the file size 0 with the mentioned script

Code:
#!/bin/sh
##########################################################################################################
#This script is being used for AOK application for cleaning up the .out files and zip it under logs directory. 
# IBM
# Created 
#For pdocap201/pdoca202 .out files for AOK
#1. Send and zip the files from /usr/filenet/p8/domains/wlsdomain/
#2. Remove the copied files in /usr/filenet-out/archive
#3. Remove the .out file more than 750 MB
#
#
###########################################################################################################
# Define all date variables
###########################################################################################################
#
tempY=`date '+%Y'`
tempm=`date '+%m'`
tempb=`date '+%b'`
tempd=`date '+%d'`
tempH=`date '+%H'`
tempM=`date '+%M'`
tempS=`date '+%S'`
dt="Date${tempY}${tempm}${tempd}_Time${tempH}${tempM}${tempS}"
###########################################################################################################
# The destination file locations are variable so that it can be changed according to the file system provide.
###########################################################################################################
host_file_location1="/usr/filenet/p8/domains/wlsdomain/fnetServer1.out"
host_file_location2="/usr/filenet/p8/domains/wlsdomain/fnetServer3.out"
destination_file_location="/usr/filenet-out/archive"
logFile="/usr/filenet-out/logs"
 
 
report_filesize1=`ls -l ${host_file_location1} |awk '{print $5}'`
report_filesize2=`ls -l ${host_file_location2} |awk '{print $5}'`
cat ${logFile}/output.log_${dt}
##chmod 777 ${logFile}/output.log_${dt}
echo "filesize1_${report_filesize1}" >> ${logFile}/output.log_${dt} 
echo "filesize3_${report_filesize2}" >> ${logFile}/output.log_${dt}
flag_filesize=768000
echo "print file limit ${flag_filesize}" >> ${logFile}/output.log_${dt}
if [ $report_filesize1 -ge $flag_filesize ]
then
echo "inside if when fnetServer1.out is greater" >> ${logFile}/output.log_${dt}
echo "Coping the fnetServer1.out file to the ${destination_file_location}" >> ${logFile}/output.log_${dt}
cp -p ${host_file_location1} ${destination_file_location}/fnetServer1.out_${dt}
echo "Zip the old fnetServer1.out file to ${destination_file_location}" >> ${logFile}/output.log_${dt}
gzip ${destination_file_location}/fnetServer1.out_${dt}
echo "creating the fnetServer1.out file" >> ${logFile}/output.log_${dt}
cat /dev/null > ${host_file_location1}
echo "Archive of fnetServer1.out complete" >>${logFile}/output.log_${dt}
fi
if [ $report_filesize2 -ge $flag_filesize ]
then
echo "inside if when fnetServer3.out is greater" >> ${logFile}/output.log_${dt}
echo "Coping fnetServer3.out the file to the ${destination_file_location}" >> ${logFile}/output.log_${dt}
cp -p ${host_file_location2} ${destination_file_location}/fnetServer3.out_${dt}
echo "Zip the old fnetServer3.out file to ${destination_file_location}" >> ${logFile}/output.log_${dt}
gzip ${destination_file_location}/fnetServer3.out_${dt}
echo "creating the fnetServer3.out file" >> ${logFile}/output.log_${dt}
cat /dev/null > ${host_file_location2}
echo "Archive of fnetServer3.out complete" >>${logFile}/output.log_${dt}
fi 
#####################################################################################################
# Remove all files from the archive directory that are over 365 days old.
#####################################################################################################
#####################################################################################################
# remove the out files
#####################################################################################################
echo "Removing the out files older than 365 days" >> ${logFile}/output.log_${dt}
find ${destination_file_location}/*.gz -mtime +364 -exec rm -f {} \;
#####################################################################################################
# Removing the log files
#####################################################################################################
find ${destination_file_location}/logs/output.log_* -mtime +90 -exec rm -f {} \;
echo "End LogRemover.sh - `date`" >> ${logFile}/output.log_${dt}
echo "Console Logs have been redirected to output.log_${dt}" >> ${logFile}/output.log_${dt}

=================>>>>>>>>>>>>>>>>>>>>>>>
the file return back to its previous state after executing the file. e.g-- if the current file size is 1 GB and after executing the scriptthe file size is 0. but after some time again it return back to 1 GB. Need help.Smilie

Moderator's Comments:
Mod Comment Use code tags and maybe indention, thanks.

Last edited by zaxxon; 10-01-2010 at 02:34 AM..
# 2  
Old 10-03-2010
If the file is open to write, those file positions remain at 1G when they append to the file, and the I/O system fills in with nulls. It is like how to make a file of N nulls: open(), seek to N-1, and write one null byte.

It is a pain to write logging routines that create a new file daily, or to shut down servers just to control log file sizes. You could write a logging filter that changes file periodically, and put a named pipe between the logging program and the logging filter process. The trick is to get the time in seconds of the next day, and not write any new entries to the old log after that time(0). Of course, you have to write the filter so nothing gets delayed in the stream.

Last edited by DGPickett; 10-03-2010 at 06:32 PM..
# 3  
Old 10-07-2010
Hi,
Thanks for your suggesition. if you can elaborate your suggesion that it will help or with any example. it will help me lot.
# 4  
Old 10-07-2010
On the file that is refusing to truncate, run fuser and look for pids, especially those indicating output 'o'. A process with a fd open pointing to a 1 G offset will write there. The file length will expand, although I was recently corrected that the pages below the written page are not reallocated, they read as nulls and are unallocated until written. The file looks big, but somewhere the allocated size is smaller. This theme of moving logs is a frequently recurrent one. You need a way to turn off the logging, so the file can be moved and compressed or discarded. Some servers can take a SIGINT or SIGHUP from kill as a command to close all output, reread all config, and continue.

http://www.velocityreviews.com/forum...t-the-eof.html

Last edited by DGPickett; 10-07-2010 at 01:10 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I retrieve the matching records from data file mentioned?

XYZNA0000778800Z 16123000012300321000000008000000000000000 16124000012300322000000007000000000000000 17234000012300323000000005000000000000000 17345000012300324000000004000000000000000 17456000012300325000000003000000000000000 9 XYZNA0000778900Z 16123000012300321000000008000000000000000... (8 Replies)
Discussion started by: later_troy
8 Replies

2. Shell Programming and Scripting

How to make script for file transfer?

Hi All, Please suggest me how to make script for file transfer from server X to another server Y. I have some directory path in server X as below: /home/directory_1/ . . /home/directory_n/ where some text files are available in each directory where some files records zero and some files... (6 Replies)
Discussion started by: aaditya321
6 Replies

3. UNIX for Dummies Questions & Answers

How to modify the file mentioned in the Message details ?

i have a below file state : CONNECTED ; state : CONNECTED ; state : CONNECTED ; Rno : 5554f1d2-6f1b Rno : 10587563-4181 Rno : be6312f7-b4df the entire content in the fileis obtained by making two seperate Curl calls( one curl call gives me state when i grep the... (3 Replies)
Discussion started by: Vaibhav H
3 Replies

4. Shell Programming and Scripting

Extract data according to keys from filename mentioned in file

Hello experts, I want to join a file with files whosE names are mentioned in one of the columns of the same file. File 1 t1,a,b,file number 1 t1,a,c,file number 1 t2,c,d,file number 2 t2,c,e,file number 2 t2,c,f,file number 2 t2,c,g,file number 2 t3,e,f,file number 3 file number 1... (3 Replies)
Discussion started by: ritakadm
3 Replies

5. Shell Programming and Scripting

How to write bash shell script for mentioned requirement?

Hi All, I am unable to write the script for the below requirement. Requirement: Main table dir_ancillary table contain three column "dir_ancillary.table_name"," dir_ancillary.text_file_name ", "dir_ancillary.Include" . This dir_ancillary contain undefined tables in the column... (2 Replies)
Discussion started by: Vineeta Nigam
2 Replies

6. Shell Programming and Scripting

shell_script showing errors in the below mentioned script while executing in linux

code: IMAGE=$imgvalue; if then echo DO=ABC; elif then echo DO=ETC; elif then echo DO=XYZ; else echo "$imgvalue is unsupported"; exit 1; fi in above script IMAGE=1 , IMAGE=2, IMAGE=3 whatever may be the value i have assigned it's showing only DO=ABC other conditions... (7 Replies)
Discussion started by: saku
7 Replies

7. Shell Programming and Scripting

Script to read file size and send email only if size > 0.

Hi Experts, I have a script like $ORACLE_HOME/bin/sqlplus username/password # << ENDSQL set pagesize 0 trim on feedback off verify off echo off newp none timing off set serveroutput on set heading off spool Schemaerrtmp.txt select ' TIMESTAMP COMPUTER NAME ... (5 Replies)
Discussion started by: welldone
5 Replies

8. Shell Programming and Scripting

How to write a script for the below mentioned issue

hello Forum members, I have a encrypted file which consist Unames and Pwd in the encrypted form and i have to write a script the PWD from the file and redirect into a log file.please find below the file and please help write a script. _config.id_dbs is the file which will open with a... (0 Replies)
Discussion started by: rajkumar_g
0 Replies

9. Shell Programming and Scripting

The scripts not able to make the file to size 0, every times it go back to its original size

#!/bin/sh ########################################################################################################## #This script is being used for AOK application for cleaning up the .out files and zip it under logs directory. # IBM # Created #For pdocap201/pdoca202 .out files for AOK #1.... (0 Replies)
Discussion started by: mridul10_crj
0 Replies
Login or Register to Ask a Question