[SOLVED] Can't remove temporary files using bash script
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.