Commit 1753f7b2 authored by Julien Muchembled's avatar Julien Muchembled

CMFActivity: clean up console scripts, mainly to make them work when /bin/sh is dash

parent 5169f193
#!/bin/sh
set -e
# Small wait script based on watch_activities scripts.
# The goal is keep running until the activities.
function show_help ( )
show_help()
{
script_name=`basename $0`
echo """
script_name=`basename "$0"`
echo "
Usage:
$script_name <mysql_opt> [interval seconds] [timeout in seconds]
Interval is default 5.
......@@ -18,47 +18,38 @@ function show_help ( )
Typical usage:
$script_name erp5
$script_name \"-h remotehost -u user erp5remote\" 3
"""
"
}
MYSQL_OPT=$1
INTERVAL=$2
TIMEOUT=$3
MYSQL_BIN=$MYSQL
if [ "$MYSQL_BIN" == "" ] ; then
MYSQL_BIN='mysql'
fi
[ "$MYSQL" ] || MYSQL=mysql
if [ "$MYSQL_OPT" == "" ] ; then
[ "$MYSQL_OPT" ] || {
show_help
exit 1
fi
}
if [ "$INTERVAL" == "" ] ; then
INTERVAL=5
fi
if [ "$TIMEOUT" == "" ] ; then
TIMEOUT=600
fi
[ "$INTERVAL" ] || INTERVAL=5
[ "$TIMEOUT" ] || TIMEOUT=600
TIME=0
while true
do
MESSAGE_VALUE=`echo "SELECT count(*) AS message_count FROM message;" | $MYSQL_BIN $MYSQL_OPT | grep -v message`
MESSAGE_QUEUE_VALUE=`echo "SELECT count(*) AS message_count FROM message_queue;" | $MYSQL_BIN $MYSQL_OPT | grep -v message`
if [ "$MESSAGE_VALUE" == "0" -a "$MESSAGE_QUEUE_VALUE" == 0 ] ; then
exit 0
fi
MESSAGE_VALUE=`echo "SELECT count(*) AS message_count FROM message;" | $MYSQL $MYSQL_OPT | grep -v message`
MESSAGE_QUEUE_VALUE=`echo "SELECT count(*) AS message_count FROM message_queue;" | $MYSQL $MYSQL_OPT | grep -v message`
[ "$MESSAGE_VALUE" = 0 ] && [ "$MESSAGE_QUEUE_VALUE" = 0 ] && break
sleep $INTERVAL;
TIME="`expr $TIME + $INTERVAL`"
TIME=`expr $TIME + $INTERVAL`
if [ $TIME -gt $TIMEOUT ]
then
echo "Messages"
echo "SELECT path, processing_node, method_id AS message_count FROM message;" | $MYSQL_BIN $MYSQL_OPT
echo "SELECT path, processing_node, method_id AS message_count FROM message;" | $MYSQL $MYSQL_OPT
echo "Messages Queue"
echo "SELECT path, processing_node, method_id AS message_count FROM message_queue;" | $MYSQL_BIN $MYSQL_OPT
echo "SELECT path, processing_node, method_id AS message_count FROM message_queue;" | $MYSQL $MYSQL_OPT
echo "Timeout"
exit 1
fi
......
#!/bin/sh
set -e
# Small watching script based on Sébastien idea.
# ideas:
......@@ -7,10 +8,10 @@
# - somehow done, use shell variable text_group
# - use python with curses to have runtime control
function show_help ( )
show_help()
{
script_name=`basename $0`
echo """
script_name=`basename "$0"`
echo "
Usage:
$script_name <mysql_opt> [interval seconds]
Interval is default 5.
......@@ -20,20 +21,16 @@ function show_help ( )
Typical usage:
$script_name erp5
$script_name \"-h remotehost -u user erp5remote\" 3
"""
"
}
MYSQL_OPT=$1
INTERVAL=$2
if [ "$MYSQL_OPT" == "" ] ; then
[ "$MYSQL_OPT" ] || {
show_help
exit 1
fi
if [ "$INTERVAL" == "" ] ; then
INTERVAL=5
fi
}
SELECT=""
for t in message message_queue ; do
......@@ -44,4 +41,4 @@ for t in message message_queue ; do
SELECT count(*) AS ${t}_count FROM $t;
"""
done
watch -n $INTERVAL "mysql $MYSQL_OPT --disable-pager -t -e '$SELECT' "
exec watch -n ${INTERVAL:-5} "${MYSQL:-mysql} $MYSQL_OPT --disable-pager -t -e '$SELECT' "
#!/bin/sh
if [ $# -ne 2 ]; then
echo -e "Usage:\n $0 db_name table_name"
set -e
[ $# = 2 ] || {
echo "Usage:
`basename "$0"` db_name table_name"
exit 1
fi
}
watch -n 1 "mysql -u root -t '$1' --disable-pager -t -e ' SELECT count(*) as NEW FROM \`$2\` WHERE processing_node = -1; SELECT count(*) as VALID FROM \`$2\` WHERE processing_node = 0; SELECT count(*) as ASSIGNED FROM \`$2\` WHERE processing_node > 0; SELECT count(*) as PROCESSING FROM \`$2\` WHERE processing = 1; SELECT count(*) as ASSIGNED, processing_node as node FROM \`$2\` WHERE processing_node > 0 GROUP BY processing_node; SELECT count(*) as PROCESSING, processing_node as node FROM \`$2\` WHERE processing_node > 0 AND processing = 1 GROUP BY processing_node; SELECT count(*) as FAILURE FROM \`$2\` WHERE processing_node = -2; SELECT count(*) as ERROR FROM \`$2\` WHERE processing_node = -3;'"
exec watch -n 1 "${MYSQL:-mysql} -u root -t '$1' --disable-pager -t -e ' SELECT count(*) as NEW FROM \`$2\` WHERE processing_node = -1; SELECT count(*) as VALID FROM \`$2\` WHERE processing_node = 0; SELECT count(*) as ASSIGNED FROM \`$2\` WHERE processing_node > 0; SELECT count(*) as PROCESSING FROM \`$2\` WHERE processing = 1; SELECT count(*) as ASSIGNED, processing_node as node FROM \`$2\` WHERE processing_node > 0 GROUP BY processing_node; SELECT count(*) as PROCESSING, processing_node as node FROM \`$2\` WHERE processing_node > 0 AND processing = 1 GROUP BY processing_node; SELECT count(*) as FAILURE FROM \`$2\` WHERE processing_node = -2; SELECT count(*) as ERROR FROM \`$2\` WHERE processing_node = -3;'"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment