Crontab: Difference between revisions
Jump to navigation
Jump to search
| Line 4: | Line 4: | ||
For every 5 min | For every 5 min | ||
<pre> | <pre> | ||
In $crontab -e | |||
5 * * * * /var/www/mysql_start.pl | 5 * * * * /var/www/mysql_start.pl | ||
</pre> | </pre> | ||
Latest revision as of 16:10, 12 March 2017
Crontab Example
For every 5 min
In $crontab -e 5 * * * * /var/www/mysql_start.pl
#!/usr/bin/perl -w
#----------------------------
# Description
# starts mysql incase it is stopped
#--------------------------------
# Use of functions
use strict;
# Variables
my $date = `date`;
chomp $date;
my $status = `service mysql status`;
my $logfile = "/var/log/mysql.restart.log";
my $log_fail = $date." -> Mysql restarted";
my $log_pass = "\tMysql works fine";
# Function
if ($status =~ m/.+stop.+/g)
{ `service mysql start`;
open (F, ">>".$logfile);
print F "$log_fail\n";
close F;
}
else {
open (F, ">>".$logfile);
print F "$log_pass\n";
close F;
}
#END