Crontab: Difference between revisions

From RAJ INFO
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
==Crontab Example ==
==Crontab Example ==
For every 5 min
For every 5 min
<pre>
In $crontab -e
5 * * * * /var/www/mysql_start.pl
</pre>


<source lang=perl>
<source lang=perl>

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