|
|
|
Friday, 28 May 2010 15:49 |
#!/usr/bin/env bash
repeat_alert_interval=15 # minutes
lock_file=/tmp/slave_alert.lck
active=yes
## Check if alert is already sent ##
function check_alert_lock () {
if [ -f $lock_file ] ; then
current_file=`find $lock_file -cmin -$repeat_alert_interval`
if [ -n "$current_file" ] ; then
# echo "Current lock file found"
return 1
else
# echo "Expired lock file found"
return 2
fi
else
return 0
fi
}
## Find the location of the mysql.sock file ##
function check_for_socket () {
if [ -z $socket ] ; then
if [ -S /var/lib/mysql/mysql.sock ] ; then
socket=/var/lib/mysql/mysql.sock
elif [ -S /tmp/mysql.sock ] ; then
socket=/tmp/mysql.sock
else
ps_socket=`netstat -ln | egrep "mysql(d)?\.sock" | awk '{ print $9 }'`
if [ "$ps_socket" ] ; then
socket=$ps_socket
fi
fi
fi
if [ -S "$socket" ] ; then
echo UP > /dev/null
else
echo "No valid socket file "$socket" found!"
echo "mysqld is not running or it is installed in a custom location"
echo "Please set the $socket variable at the top of this script."
exit 1
fi
}
check_for_socket
Slave_IO_Running=`mysql -Bse "show slave status\G" | grep Slave_IO_Running | awk '{ print $2 }'`
Slave_SQL_Running=`mysql -Bse "show slave status\G" | grep Slave_SQL_Running | awk '{ print $2 }'`
Last_error=`mysql -Bse "show slave status\G" | grep Last_error | awk -F \: '{ print $2 }'`
if [ -z $Slave_IO_Running -o -z $Slave_SQL_Running ] ; then
echo "Replication is not configured or you do not have the required access to MySQL"
exit
fi
if [ $Slave_IO_Running == 'Yes' ] && [ $Slave_SQL_Running == 'Yes' ] ; then
if [ -f $lock_file ] ; then
rm $lock_file
echo "Replication slave is running"
echo "Removed Alert Lock"
fi
exit 0
elif [ $Slave_SQL_Running == 'No' ] ; then
if [ $active == 'yes' ] ; then
check_alert_lock
if [ $? = 1 ] ; then
## Current Lock ##
echo "up" > /dev/null
else
## Stale/No Lock ##
touch $lock_file
echo "SQL thread not running on server `hostname -s`!"
echo "Last Error:" $Last_error
fi
fi
exit 1
elif [ $Slave_IO_Running == 'No' ] ; then
if [ $active == 'yes' ] ; then
check_alert_lock
if [ $? = 1 ] ; then
## Current Lock ##
echo "up" > /dev/null
else
## Stale/No Lock ##
touch $lock_file
echo "LOG IO thread not running on server `hostname -s`!"
echo "Last Error:" $Last_error
fi
fi
exit 1
else
if [ $active == 'yes' ] ; then
check_alert_lock
if [ $? = 1 ] ; then
## Current Lock ##
echo "up" > /dev/null
else
## Stale/No Lock ##
touch $lock_file
echo "Unexpected Error!"
echo "Check Your permissions!"
fi
fi
exit 2
fi
 Read more: |
|
|
Tuesday, 04 May 2010 14:38 |
Source: Common Ruby Idioms [stackoverflow.com]
class Ticket
@remaining = 3
def self.new
if @remaining > 0
@remaining -= 1
super
else
"IOU"
end
end
end
Ticket.new #=> Ticket
Ticket.new #=> Ticket
Ticket.new #=> Ticket
Ticket.new #=> "IOU"
 Read more: |
|
Friday, 16 April 2010 01:08 |
// description of your code here
SELECT a.name as `Customer Number`,
o.name as `Name`,
c.oppor_home_phone_c as `Phone Number`,
o.sales_stage as `Sales Stage`,
o.lead_source as `Lead Source`,
u.user_name as `Assigned To`,
o.date_entered as `Date Created`
FROM opportunities o
LEFT JOIN opportunities_cstm c ON o.id = c.id_c
LEFT JOIN accounts_opportunities ao ON o.id = ao.opportunity_id
LEFT JOIN accounts a ON a.id = ao.account_id
LEFT JOIN users u ON o.assigned_user_id = u.id
WHERE o.sales_stage = CASE LENGTH('$SALES_STAGE')
WHEN 0 THEN o.sales_stage
ELSE '$SALES_STAGE'
END
AND o.lead_source = CASE LENGTH('$LEAD_SOURCE')
WHEN 0 THEN o.lead_source
ELSE '$LEAD_SOURCE'
END
AND o.date_entered BETWEEN (CASE LENGTH('$DATE_START')
WHEN 0 THEN DATE('1970-01-01')
ELSE DATE('$DATE_START')
END) AND (CASE LENGTH('$DATE_END')
WHEN 0 THEN DATE('2100-01-01')
ELSE DATE('$DATE_END')
END)
AND u.user_name = CASE '$USER_NAME'
WHEN '' THEN u.user_name
WHEN 'not_assigned' THEN ''
ELSE '$USER_NAME'
END
ORDER BY o.date_entered ASC Read more: |
|
|
Wednesday, 14 April 2010 04:12 |
#include
#include
#include
#include
/*
Grammer used is:-
E -> TE'
E'-> +TE'| e
T -> FT'
T'->*FT' | e
F -> (E) | id
*/
class Rec_parser
{
char input[20];
int i;
public:
Rec_parser()
{i=0;
printf("Enter the input string::");
gets(input);
E();
if(input[i]=='$')
printf("\ninput string accepted");
getch();
}
void E()
{
T();
EPRIME();
}
void EPRIME()
{
if(input[i]=='+')
{
advance();
T();
EPRIME();
}
}
void T()
{
F();
TPRIME();
}
void TPRIME()
{
if(input[i]=='*')
{
advance();
F();
TPRIME();
}
}
void F()
{
if(input[i]=='(')
{
advance();
E();
if(input[i]==')')
{
advance();
}
else
ERROR();
}
else
{
if(input[i]=='i')
advance();
else
ERROR();
}
}
void advance()
{
i++;
}
void ERROR()
{
printf("ERROR...!!!!!");
getch();
exit(0);
}
};
void main()
{
clrscr();
Rec_parser r;
getch();
}
 Read more: |
|
Sunday, 28 February 2010 23:22 |
// description of your code here
class OptParseSimple
def initialize(filename, args)
doc = Document.new(File.open('options.xml','r').read)
@options = XPath.match(doc.root, 'records/option[switch!=""]')
switches = @options.map do |option|
switch = option.text('switch')
switch[0] == '-' ? switch : nil
end
switches.compact!
# split the argument switches if grouped e.g. -ltr
args.map! do |arg|
if arg[/^\-[a-zA-Z]+$/] and switches.grep(/#{arg}/).empty? then
arg[1..-1].scan(/./).map {|x| '-' + x}
else
arg
end
end
args.flatten!
a1 = options_match(@options[0], args).flatten.each_slice(2).map {|x| x if x[0]}.compact
options_remaining = XPath.match(doc.root, 'records/option[switch=""]/name/text()')
a2 = args.zip(options_remaining).map(&:reverse)
if a2.map(&:first).all? then
@h = Hash[*(a1+a2).map{|x,y| [x.to_s.to_sym, y]}.flatten]
else
invalid_option = a2.detect {|x,y| x.nil? }.last
raise "invalid option: %s not recognised" % invalid_option
end
end
def to_h()
@h
end
private
def options_match(option, args)
switch, switch_alias = option.text('switch'), option.text('alias')
switch_pattern = switch_alias ? "(%s|%s)" % [switch, switch_alias] : switch
switch_matched, arg_index = args.each_with_index.detect {|x,j| x[/^#{switch_pattern}/]}
key, value = nil
if switch_matched then
value_pattern = option.text('value')
if value_pattern then
# check for equal sign
value = switch_matched[/\=(#{value_pattern})/,1]
# check the next arg
if value.nil? and args.length > 0 then
next_arg = args[arg_index + 1]
# check to make sure it's not the next switch
next_option = @options[1] if @options.length > 1
if next_arg != next_option then
# validate using the regex
value = next_arg[/#{value_pattern}/]
if value then
args.delete_at(arg_index + 1)
else
raise option.text('errors/records/error[last()]')
end
end
else
args.delete_at(arg_index)
end
else
args.delete_at(arg_index)
end
key = option.text('name')
elsif option.text('mandatory').downcase == 'true' then
raise option.text('errors/records/error')
end
pair = [key, value]
@options.shift
next_pair = options_match(@options[0], args) if @options.length > 0
[pair, next_pair]
end
end
 Read more: |
|
|
|
|
|
|
Page 2 of 2 |