3

I want to run this command:

free && sync && echo 3 > /proc/sys/vm/drop_caches && free -m

by cron. That way I can free my RAM and cache in an Ubuntu system.

I'm using these steps:

# crontab -e
2 * * * * my_user_name /usr/bin/free free && sync && echo 3 > /proc/sys/vm/drop_$

save & exit

# service cron restart

But, when I run free -m nothing changes.  For reference, it looks something like this:

# free -m
             total       used       free      shared    buffers     cached
Mem:          7976       5064       2911           5        169       3478
-/+ buffers/cache:       1416       6560
Swap:         8112       1264       6848
  • What is approachit ? – neuron Aug 12 '15 at 6:52
  • Dear Sir, this my user name – Chander Kant Aug 12 '15 at 7:01
  • BTW, you shouldn't need service cron restart after crontab -e.  crontab -e will automatically notify cron that something has changed.  If you found the crontab file, and manually went to it and edited it, you would need to do something to tell cron to reread the modified file (so don't do that — just use crontab -e). – G-Man Oct 16 '15 at 5:02
3

I'm not sure why you want to drop the caches every hour - that is going to kill performance.

There are a few problems with what you've done:

  1. You need to edit the crontab of root, as you cannot write to /proc/sys/vm/drop_caches as a non-root user.
  2. Your crontab entry is not correct. It should be:

    2 * * * * /usr/bin/free && sync && echo 3 > /proc/sys/vm/drop_caches
    

    The fields, in order, are: minute, hour, day of month, month, day of week, command. You don't need to restart cron after editing a crontab.

  • Isn't it 2 minutes after every full hour? Every 2 minutes would be */2 – chaos Aug 12 '15 at 7:36
  • @chaos Whoops, yes, you're right! Answer amended – mjturner Aug 12 '15 at 7:37
  • Dear sir, My system have 8 GB RAM and 128MB Graphic card but system goes to block screen. here i check that cpu usage are 60 -85 percent and RAM free space 130MB left. that way i drop cache for increase free space of RAM If i am wrong please suggestion me for this – Chander Kant Aug 12 '15 at 7:41
  • @ChanderKant The fact that the operating system is using all your RAM is a good thing - it will be caching frequently used files, etc. If you clear the caches all of that will be lost and what was previously cached will need to be loaded from disk. Rather let the operating system do what it does best - manage your system. See, for example this question. – mjturner Aug 12 '15 at 7:48
  • Dear Mjturnersir, need to upgrade hardware of my system and -/+ buffers/cache :- used 1909 free 6067 can you help me on this topic what is the use of it – Chander Kant Aug 12 '15 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.