Twitter
RSS

Bash Scripting for squid and Cron job autmation in linux


CRON has several options but we’ll discuss it generally by assuming you are root user. The default root script of cron can be found in /var/spool/cron/root where “root” is the user and the file contains command or scripts to execute at a given time.

CRON has the follow syntax:

[root@server01 ~]# vi /var/spool/cron/root

30 15 * * * sh /root/scripts/clear_squid.sh

This means every on 3:30pm, it will run clear_squid.sh. if you want to add more scripts, simply add it under the last schedule.

[root@server01 ~]# mkdir scripts
[root@server01 ~]# cd scripts
[root@scripts ]# vi clear_squid.sh

Bash scripting:
#!/bin/bash
rm /var/log/squid/* -Rf
rm /var/spool/squid/* -RF
/sbin/service squid restart
exit 0

The first line tells the script is bash and it tells where to find the interpreter / second line tells the command to delete all squid logs / third line tells the command to delete all squid cache / fourth line tells the command to restart squid / fifth line tells the command to exit properly with status 0 After making the script you have to change the file properties so it will be executable

[root@scripts ]# chmod 744 clear_squid.sh

You can either run the file manual or have it scheduled will do the same.
U needs to restart Crond:
[root@scripts ]# service crond restart

You can list active cron task with the following command:
[root@scripts ]# crontab –u root –l


Credits: nsharif.blogspot.com

Comments (2)

Good Day,

How about to clear squid log under OpenBSD it's same like linux or etc. Can you give guide to handle this case. Cheer...

Zamri.

Dear Nagur Sharif
How to create Squid 3.0 source RPM installation script please?

Post a Comment