LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-09-2010, 11:13 AM   #1
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 272Reputation: 272Reputation: 272
Can't remove temporary files using bash script


A little background - I've got Mythtv running on a Debian Lenny box right now. I also have a Roku frontend setup for streaming to my living room. Part of the setup requires me to use ffmpeg to convert the video from mpeg2 to H264/acc. That all works great.

However, the ffmpeg command generates a temporary file blahblah.mpg.tmp of about 1GB per hour of transcoded video. My issue is that I can't seem to delete these files automatically from any bash script.

Now from the command line, I can cd to the directory and just rm -f *.tmp and they get deleted. However, from my script, that same command doesn't remove those files. I thought maybe the file was in use, so I put a sleep command in for like an hour before the delete happens, but it still fails. I also put rm -f /mnt/mythtv/*.tmp in a root cronjob and it still doesn't delete the files.

If I just rm *.tmp I do get a prompt about "Are you sure you want to delete this write protected file?". But the -f switch seems to work fine as a normal user from the command line and just delete them.

Does anyone have an idea how to troubleshoot this problem? The particular filesystem that the tmp files get generated on is on it's own xfs partition mounted as /mnt/mythtv.

Last edited by pljvaldez; 11-09-2010 at 11:17 AM.
 
Old 11-09-2010, 11:29 AM   #2
udaman
Member
 
Registered: Oct 2010
Location: New England, USA
Distribution: OpenSUSE/Slackware64/RHEL/Mythbuntu
Posts: 189

Rep: Reputation: 39
When I write a script using a command I always use the full path to the binary, on my system it's /bin/rm. A script doesn't hold the same environment as a user, so it doesn't know where 'rm' is. Give that a try and see if it works out. HTH.
 
Old 11-09-2010, 11:55 AM   #3
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Original Poster
Rep: Reputation: 272Reputation: 272Reputation: 272
Doh! That's a great idea. I'll give it a try when I get home and see what happens.
 
Old 11-10-2010, 10:59 AM   #4
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Original Poster
Rep: Reputation: 272Reputation: 272Reputation: 272
It ended up being a combination of things: I did need the whole path to rm for the cronjob. Once that worked, I went back to my other script and added it. That's when I noticed I had also prefixed the variable for the filename (path included) with the path, so it was trying to delete a file that wasn't there. Thanks again for your help.
 
Old 11-10-2010, 01:30 PM   #5
udaman
Member
 
Registered: Oct 2010
Location: New England, USA
Distribution: OpenSUSE/Slackware64/RHEL/Mythbuntu
Posts: 189

Rep: Reputation: 39
Good job! Usually, when I can't make something work correctly, I sleep on it overnight and the answer comes to me next day.
 
Old 11-10-2010, 01:32 PM   #6
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 553Reputation: 553Reputation: 553Reputation: 553Reputation: 553Reputation: 553
Quote:
Originally Posted by udaman View Post
Good job! Usually, when I can't make something work correctly, I sleep on it overnight and the answer comes to me next day.
Good to know I am not the only one who has snippets of code and scripts going through my head when I'm going to sleep. Is that bad? LOL. :/
 
Old 11-10-2010, 02:43 PM   #7
udaman
Member
 
Registered: Oct 2010
Location: New England, USA
Distribution: OpenSUSE/Slackware64/RHEL/Mythbuntu
Posts: 189

Rep: Reputation: 39
Quote:
Originally Posted by GrapefruiTgirl View Post
Good to know I am not the only one who has snippets of code and scripts going through my head when I'm going to sleep. Is that bad? LOL. :/
Bad? I would expect no less from a true programmer.
 
Old 11-11-2010, 02:44 AM   #8
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,897

Rep: Reputation: 578Reputation: 578Reputation: 578Reputation: 578Reputation: 578Reputation: 578
I wake up with snippets in my head...
 
Old 11-11-2010, 11:10 AM   #9
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Original Poster
Rep: Reputation: 272Reputation: 272Reputation: 272
I'm not a programmer by trade, but I have done quite a bit programming PLC's with ladder logic. There's nothing worse than endless lines of ladder logic infiltrating your dreams...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to remove files older than 3 days rust8y Linux - General 26 10-04-2012 08:26 AM
Bash script to find and remove similar lines from multiple files linuxquestion1 Programming 9 07-13-2011 01:45 AM
help with bash remove files script heropage Linux - Server 2 11-04-2010 08:23 AM
Remove temporary files Venkata Linux - Newbie 9 04-13-2010 07:04 AM
iptables bash script to add offending ip's to temporary chain NinjaGuru Programming 1 01-08-2008 10:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration