Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

clean up file content

Posted on 2003-03-25
8
Medium Priority
?
245 Views
Last Modified: 2013-12-27
Hi all

I have prepared a shell script such that:
    apple.sh > apple.log

The log file will grow unless the apple.sh is stopped and delete the apple.log.
During runtime, I try to run "cat /dev/null > apple.log" to the file so that the file resume to 0 byte. But the disk space will still occupy the space unless the apple.sh is stopped.

Is there any solution to delete the cleanup the file without stopping the apple.sh ?

Thanks
0
Comment
Question by:glogin
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 2

Expert Comment

by:soupdragon
ID: 8201644
If you have written apple.sh yourself you might try to utilise a signal within your script.

for instance near the start of the apple.sh script

trap '> apple.log' INT

then from outside your program kill -INT apple.sh to clear the logfile.

Can't say I've ever tried this myself ;)

SD
0
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 8201769
Test with:
apple.sh >> apple.log


0
 

Author Comment

by:glogin
ID: 8201834
sorry for my misleading question.

the question should be: Is there any solution to cleanup the apple.log without stopping/shutting down the apple.sh?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:Otetelisanu
ID: 8202469
Test with:
apple.sh >> apple.log
and

echo "" >apple.log
0
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 8202485
with
echo "" >apple.log
the file is 1 Byte big
and
the program apple.sh write on the apple.log
0
 
LVL 38

Accepted Solution

by:
yuzh earned 200 total points
ID: 8207238
Here's your problem:

the command line:

apple.sh > apple.log
open the apple.log file, inside the "apple.sh" script, the statement:
cat /dev/null > apple.log

try to write to an OPEN file !!!

Here's the simple answer:

keep "cat /dev/null > apple.log" in the script, run the script in commandline:
apple.sh

as soon as it run "cat /dev/null > apple.log" the log file should be empty.






0
 

Author Comment

by:glogin
ID: 8208345
1. at the beginnng, apple.log = 100MB
2. after running "cat /dev/null > apple.log", the file size is resumed to 0 byte

Question:
will 100MB disk space still be occupied by apple.log if apple.sh does not stop? (as the instance of apple.sh does not stop)
0
 
LVL 38

Expert Comment

by:yuzh
ID: 8208655
When the file size down to 0 byte, the disk space should free up, and it should have nothing to do with the statments after :
cat /dev/null > apple.log



0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question