Crontab: Difference between revisions
Jump to navigation
Jump to search
Created page with "Category:Bioinformatics ==Crontab Example ==" |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
==Crontab Example == | ==Crontab Example == | ||
For every 5 min | |||
<pre> | |||
In $crontab -e | |||
5 * * * * /var/www/mysql_start.pl | |||
</pre> | |||
<source lang=perl> | |||
#!/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 | |||
</source> | |||
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