1835202 Members
2490 Online
110077 Solutions
New Discussion

Erase file

 
SOLVED
Go to solution
peterchu
Super Advisor

Erase file

In my system, there is a file will be generated from our program , but the file is serious affect other processes in our system , so the file need to be erased once it is generated ( but I still don't know why the file will be generated in the program ) , I tried to add a batch ( eg. * * * * * rm -f file ) job to erase it , but this batch job will submit every minute , then our system will have so many that batch jobs , could suggest other way to fix it? thx
13 REPLIES 13
Sundar_7
Honored Contributor
Solution

Re: Erase file

Hi,

If there is a cron job that reads "rm -f file" which will be executed once in a minute, I dont understand why do you think you will have so many batch jobs running in the system.

Once it deleted the file (which should take not more than 2-3 secs), the process is going to vanish. Yes it is true that your cron log file is going to grow out of bounds.

Alternative way is to have a script running in the background that does this

# vi /root/rmfile.sh
while true
do
rm -f file
sleep 30
done
#

# nohup /root/rmfile.sh 1>/dev/null 2>&1 &

Sundar
Learn What to do ,How to do and more importantly When to do ?
Sundar_7
Honored Contributor

Re: Erase file


Wow, you have assigned points for 1 out of 121 replies !
Learn What to do ,How to do and more importantly When to do ?
Elmar P. Kolkman
Honored Contributor

Re: Erase file

But there is a problem with your solution... Removing the file will only remove the inode, not the file itself. So if the process opens the file and starts writing to it, it will still have the file open, though the inode is removed, and thus still consume filesystem space till the file is closed by the proces (usually when it ends), at which time it is removed immediately.

If you're not interested in the data, a better solution might be to create a symbolic link to /dev/null. But it depends on the program if that works (sometimes programs remove files before creating a new version of it, for instance).
Every problem has at least one solution. Only some solutions are harder to find.
peterchu
Super Advisor

Re: Erase file

thx all reply ,it is work , one more question , as my question , there are many many rm batch jobs in my system now , how to kill all these processes one time ? thx
Elmar P. Kolkman
Honored Contributor

Re: Erase file

ps -ef | awk '/rmbatchjob/ {print $2}' | xargs kill

(replace rmbatchjob with a string that will identify the rmbatchjob processes!)

If started from cron, you could also use the cron log to find the processes, but the above line is simpler.
Every problem has at least one solution. Only some solutions are harder to find.
Colin Topliss
Esteemed Contributor

Re: Erase file

There is a lot of missing information here.

I would be asking:
1) WHY generate this file if the first thing you want to do is delete it.
2) If you have to generate the file, can you affect WHERE it gets generated (say redirect it to /dev/null - but that depends on HOW it gets generated).
3) WHY does it cause problems with other processes?
4) WHEN does it get generated? Why run a job every few minutes if it gets generated within a 1 or two hour time window - just time the job to run during that window.

Personally, if no-one wants this file, I'd force the developers (or beat up the vendor) and get them to change their code.

Col.
Nicolas Dumeige
Esteemed Contributor

Re: Erase file

Sundar : "Wow, you have assigned points for 1 out of 121 replies !"

but this one was very good in deed ... ;D
All different, all Unix
Bruno Ganino
Honored Contributor

Re: Erase file

Peterchu, you want read the link "how to earn points" ?
It is in the left screen, down member Status.
Not obbligation, only if you want !
;-) Bye
Bruno
Torino (Turin) +2H
Geoff Wild
Honored Contributor

Re: Erase file

How does the file affect other processess?

Change the program - best way to resolve this - not find a "hack/bandaid" solution...

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Sundar_7
Honored Contributor

Re: Erase file

PeterChu, we are going to suggest forum administrators not to allow anyone with less than 80% point assigning rate to be able to post any new message. :-)

Learn What to do ,How to do and more importantly When to do ?
Paula J Frazer-Campbell
Honored Contributor

Re: Erase file

Hi

Your answer is here:-

http://forums1.itrc.hp.com/service/forums/pageList.do?userId=CA1084347&listType=unassigned&forumId=1


Paula
If you can spell SysAdmin then you is one - anon
Geoff Wild
Honored Contributor

Re: Erase file

Hey guys - remember - the purpose of the forums is to help each other - points are secondary.....yes it's nice to get points...but not mandatory...If there were no points at all, I'd still participate....

Yes, I agree everyone should read "Patrick Wallek's forums etiquette guideline"

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=140137

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Paula J Frazer-Campbell
Honored Contributor

Re: Erase file

Geoff

I fully agree -- help is happening - just some gentle prodding as well.


Paula
If you can spell SysAdmin then you is one - anon