Clear cache memory and set cronjob on Linux server

Below is the command to clear memory cache :-

[root@root~]#  sync; echo 3 > /proc/sys/vm/drop_caches

Use the above command in cronjob using screipt

Login your server as a root user.

Then use it in script at “/root/cleacrcache.sh” and enter folllowing contents

    #!/bin/sh
    sync; echo 3 > /proc/sys/vm/drop_caches

Make  the permission of ” /root/cleacrcache.sh” to 755

[root@root~]#  chmod 755  /root/cleacrcache.sh

Run the cronjob using  crontab file as below :-

  [root@root~]#  crontab -e  OR
    [root@root~]# Vi /var/spool/cron/root

Enter below  cron  to set cronjob for clearing cache in every hour

   0 * * * * /root/clearcache.sh

Restart crond service

[root@root~]#  /etc/init.d/crond restart

Thats it you have done :)

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *