homepage Welcome to WebmasterWorld Guest from 54.237.197.160
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
cron job
Delete files if more that 100MB is used in a folder
oldgoat99




msg:3540520
 5:11 pm on Jan 4, 2008 (gmt 0)

I have a folder on my web site where pictures from my security cameras are sent when motion is detected. I need a cron entry to delete the the oldest files if the folder containing the files is greater than 100MB. When the space used becomes greater than 100MB the cron job would delete 1 days worth of the oldest files.

Unfortunately I have no information about the environment on the server where my web site resides and the ISP doesn't have any documentation available to the general hosting subscriber although I do have a control panel that allows me to set up a cron job.

I've tried using some standard Unix commands in a script but can't seem to make most things work and I don't have access to a Unix system to try things out. Things like #!/bin/sh give me an error so I guess I don't have access to the Bourne shell which is where most of my experience is.

I created the following file and made it executable:
-------------------
ls_count=`find $HOME/html/camera -name "Motion_*" -exec ls -1 "{}" ";"`
echo $ls_count
-------------------
It's giving me output so I know cron is working but when I try to use other commands such as grep or others I get errors. I'm assuming I need to know the path to these "other" commands. Or, maybe I'm just overlooking something.

I also know I could use the following:
-------------------
find $HOME/html/camera -name "Motion_*" -mtime +14 -exec /bin/rm -f "{}" ";"
-------------------
which would delete files that are more than 14 days old but I only want them deleted if more than 100MB is being used in the folder where the images are located

I know it isn' hard to do what I'm trying to do but it's been five years since I looked at Unix scripts and I don't have a system to even try things out on the command line.

I'm hoping someone out there with some experience can point me in the right direction.

 

jtara




msg:3540598
 6:36 pm on Jan 4, 2008 (gmt 0)

Unfortunately I have no information about the environment on the server where my web site resides and the ISP doesn't have any documentation available to the general hosting subscriber

Then, the solution is simple: you need a new host.

Maybe if you tell them that, they will cough-up the documentation.

You're not overlooking anything. You're just having to guess as to what kind of system you are running on.

If you really want to beat yourself up that way, you're going to have to do a bit of probing in your cron jobs (do you have access to a command shell?) to figure out what you've got. Do a "uname -a", which will at least give you the kernel version and architecture. Maybe a "ls /bin" and "ls /usr/bin" to see what programs you have available.

"grep" is part of the essential Unix toolkit and should be located in /bin. Without "grep", I'd question whether you are even running on a Linux or Unix system.

oldgoat99




msg:3540611
 6:58 pm on Jan 4, 2008 (gmt 0)

Well, I should've qualified that "I don't know about the environment" statement... I do know it's a Linux system, but there are an infinite number of ways to set up the "environment" on any Unix system and the standard things I have been used to don't seem to work. I can't even get "cd" to work on it (in a cron job). Of course I don't have any way of getting to a command line to execute commands. All I have is cron so I have to put the command in a file, make it execute in cron and look for the output which gets emailed to me. It's very time consuming to troubleshoot scripts that way, not to mention that the cron "environment" is usually totally different than a shell or command tool environment and commands run by a user from a cmd or shell tool may act differently than when they are executed by cron. I have a system in my garage that has Red Hat on it. I guess I'm going to have to resurrect it and play around with it a bit. I was hoping to not have to go that route.

Thanks....

jtara




msg:3540676
 9:03 pm on Jan 4, 2008 (gmt 0)

I can't even get "cd" to work on it

cd is built-in to the shell.

Sounds like you have some kind of restrictive shell.

At least do an "echo $SHELL" to see what shell you are running.

You might also run "set" with no arguments to see your environment variables.

oldgoat99




msg:3540737
 10:08 pm on Jan 4, 2008 (gmt 0)

Good idea! I'll be out for the weekend but will try that next week when I get a chance.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved