|
Home > Archive > Unix Shell > January 2006 > Problem in Log file movement
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Problem in Log file movement
|
|
| SMuthuvel@gmail.com 2006-01-09, 2:56 am |
| Dear Techies,
I am a newbie to this shell scripting. My problem is to make datewise
backup of log files which are generated by C programs. For I need to
develop a script which has to move all the log files from a directory
to another directory. This seems to be a novice question.
I am facing the following problem while moving the logs from the source
to destination. After moving the log file to the destination directory,
the script file is not creating a new log file in source directory. It
keeps on updating the log which has been moved to the destination
directory. I dont know how to solve this.
It will be a great help for a solution to this issue. Kindly let me
know how to solve this problem.
writer.c
-----------
#include<stdio.h>
main()
{
while(1)
{
printf("\nHai");
}
}
writer is the C executable file. Its output is redirected to a log file
output.log. You can understand easily by seeing this.
../writer 1>>/home/user/smvel/log/output.log 2>&1 &
I made the following script to move the log.
mov_log.sh
------------------
LOG_DIR="/home/user/smvel/log/"
dir=`date +%d-%m-%Y`
cd $LOG_DIR
mkdir $dir
mv hai2.log $dir
touch hai2.log
While executing the above script, the log file is moved to datewise
directory. But the data is appended to the file in datewise directory
only. Can you help me out in this. What could be the solution to move
the files?
Regards,
S.M.Vel
| |
| Thobias Vakayil 2006-01-09, 7:51 am |
| SMuthuvel@gmail.com wrote:
>Dear Techies,
>
>I am a newbie to this shell scripting. My problem is to make datewise
>backup of log files which are generated by C programs. For I need to
>develop a script which has to move all the log files from a directory
>to another directory. This seems to be a novice question.
>
>I am facing the following problem while moving the logs from the source
>to destination. After moving the log file to the destination directory,
>the script file is not creating a new log file in source directory. It
>keeps on updating the log which has been moved to the destination
>directory. I dont know how to solve this.
>It will be a great help for a solution to this issue. Kindly let me
>know how to solve this problem.
>
>writer.c
>-----------
>#include<stdio.h>
>main()
>{
> while(1)
> {
> printf("\nHai");
> }
>}
>
>writer is the C executable file. Its output is redirected to a log file
>output.log. You can understand easily by seeing this.
>./writer 1>>/home/user/smvel/log/output.log 2>&1 &
>
>I made the following script to move the log.
>
>mov_log.sh
>------------------
>LOG_DIR="/home/user/smvel/log/"
>dir=`date +%d-%m-%Y`
>cd $LOG_DIR
>mkdir $dir
>mv hai2.log $dir
>touch hai2.log
>
>While executing the above script, the log file is moved to datewise
>directory. But the data is appended to the file in datewise directory
>only. Can you help me out in this. What could be the solution to move
>the files?
>
>Regards,
>S.M.Vel
>
>
>
Is it ok for you?
LOG_DIR="/home/user/smvel/log/"
dir=`date +%d-%m-%Y`
cd $LOG_DIR
mkdir -p $dir
mv hai2.log $dir
>hai2.log
Regards,
Thobias Vakayil
| |
|
| Hai,
The log file has been moved to newly created directory
(/home/user/smvel/log/09-01-2006).
Still the log file is getting appended over there.
For me, new file has to be created in"/home/user/smvel/log/ directory.
I have found out a reason for this. While we are moving the log the
inode is also moved.
Therefore filepointer is writing only on the previous inode. Am I
correct?
But I need a solution for solving this problem.
Regards,
smvel
| |
| Bruce Barnett 2006-01-09, 7:51 am |
| "smvel" <SMuthuvel@gmail.com> writes:
> The log file has been moved to newly created directory
> (/home/user/smvel/log/09-01-2006).
> Still the log file is getting appended over there.
> For me, new file has to be created in"/home/user/smvel/log/ directory.
>
> I have found out a reason for this. While we are moving the log the
> inode is also moved.
> Therefore filepointer is writing only on the previous inode. Am I
> correct?
> But I need a solution for solving this problem.
Well, if the program is still writing to the new inode, yes - the file
will continue to grow.
Sometimes the program generating the log file will automatically (say
- once a job) close the log file and open the new one, and solve your
problem. But I think in your case this isn't happening.
Sometimes you can send the program a signal (typically kill -1) which will
cause it to "restart" - closing existing files, and reopening them.
Worst comes to worse, shut down the program and start it up again.
If you have access to the source code, adding a signal handler to
close/reopen log files would be best.
--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
| |
|
| Yes Bruce. I am also thinking to change the C code. But the problem is,
developer has deleted the code and nobody knows the logic.
Is there any way to recover the code from the executable file?
Regards,
Muthu
| |
| Bruce Barnett 2006-01-09, 6:02 pm |
| "smvel" <SMuthuvel@gmail.com> writes:
> Yes Bruce. I am also thinking to change the C code. But the problem is,
> developer has deleted the code and nobody knows the logic.
> Is there any way to recover the code from the executable file?
It's not my area. Maintaining C code converted into assembler is not
something I would like to experience. But I haven't look at this
technology in years.
Hmm. I did see
http://www.google.com/Top/Computers.../Disassemblers/
and in this page is
http://www.backerstreet.com/rec/rec.htm
which produces "C-like" code.
IMHO It's easier to re-write the code, or to find the disk
drives/backups with the source on it. I'd rather recover a lost source
code from a disk that recover source code from binary.
Unless it's written in Java.
Can you kill and restart the program without losing data?
P.s. Don't use kill -9, use kill -1 or kill -15
--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
| |
| smvel 2006-01-13, 10:39 pm |
| Ok Bruce. Also i need to discuss with my friends for killing the
process.
Anyhow thanks for helping me out from this.
Regards,
smvel
|
|
|
|
|