1

So I've made a basic .sh file to clear my cache using the

sync; echo < 3 /proc/sys/vm/drop_caches

command. Then I saved it to my username in

/home/marc 

Then I came across the crontab so I decided to use this sh file with crontab to run every hour as I noticed that my RAM is eaten up extremely quickly on my laptop. using crontab -e, I edited the file to this:

0 * * * * /root/clearcache.sh 

My question is, have I done everything right? Have I editied the crontab file correctly and if so, how can I check that this job runs as it should do?

5
  • 3
    That's not how memory allocation works on Linux, if you flush your filesystem cache every hour, you're going to have a bad time. Read linuxatemyram.com before proceeding :-)
    – Chris Down
    Apr 14, 2016 at 21:54
  • So are you suggesting that I get rid of this cron job? I've just quickly skimmed through this and I'm definitely a victim of thinking my RAM is being eaten haha! Apr 14, 2016 at 22:05
  • Your crontab works. What your cronjob is stupid unless you want to reduce performance based on a timer for some reason (public computer that you want to discourage people from using?), but you're set up to run it correctly. Apr 14, 2016 at 22:42
  • 1
    unix.stackexchange.com/a/176232 points to /var/log/cron if you have permission to read it (typically root)
    – Jeff Schaller
    Apr 14, 2016 at 22:52
  • Yeah I've just read into the risks of constantly dropping the cache and decided to deleted the cron job. It was just bugging me as to why so much RAM was being eaten up haha but honestly, you guys have been really helpful! Thanks for this. Apr 15, 2016 at 9:04

2 Answers 2

2

The simplest answer to check if a cronjob works when you expect it to (short of reading the man page) would be to add a simple cronjob that will report the date to a particular file:

0 * * * * date >> /tmp/cronjob.test

Then check it the next day (or whenever) and ensure it's triggering when you expected it to.

I personally would recommend reading the man page instead—it's faster—but the above is the longer lazier way. ;)

0

So it looks like cron doesn't have any logging or debug option.

To check that your short script is run as expected, you could watch strace -f -p $(pgrep cron) in a terminal window. Run strace -f my-basic.sh in advance so you know what it should look like.

If a cron script generates any output, it should be mailed to your user. When you open a terminal it will tell you you have mail, and the mail command will show it to you... I'm afraid that command may be another "learning opportunity" :).

You can expect that any errors will cause your script to generate output, and hence mail. That's the unix convention. "No news is good news".

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .