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 #!/bin/sh
set -e
# Small wait script based on watch_activities scripts. # Small wait script based on watch_activities scripts.
# The goal is keep running until the activities. # The goal is keep running until the activities.
show_help()
function show_help ( )
{ {
script_name=`basename $0` script_name=`basename "$0"`
echo """ echo "
Usage: Usage:
$script_name <mysql_opt> [interval seconds] [timeout in seconds] $script_name <mysql_opt> [interval seconds] [timeout in seconds]
Interval is default 5. Interval is default 5.
...@@ -18,47 +18,38 @@ function show_help ( ) ...@@ -18,47 +18,38 @@ function show_help ( )
Typical usage: Typical usage:
$script_name erp5 $script_name erp5
$script_name \"-h remotehost -u user erp5remote\" 3 $script_name \"-h remotehost -u user erp5remote\" 3
""" "
} }
MYSQL_OPT=$1 MYSQL_OPT=$1
INTERVAL=$2 INTERVAL=$2
TIMEOUT=$3 TIMEOUT=$3
MYSQL_BIN=$MYSQL
if [ "$MYSQL_BIN" == "" ] ; then [ "$MYSQL" ] || MYSQL=mysql
MYSQL_BIN='mysql'
fi
if [ "$MYSQL_OPT" == "" ] ; then [ "$MYSQL_OPT" ] || {
show_help show_help
exit 1 exit 1
fi }
if [ "$INTERVAL" == "" ] ; then [ "$INTERVAL" ] || INTERVAL=5
INTERVAL=5 [ "$TIMEOUT" ] || TIMEOUT=600
fi
if [ "$TIMEOUT" == "" ] ; then
TIMEOUT=600
fi
TIME=0 TIME=0
while true while true
do do
MESSAGE_VALUE=`echo "SELECT count(*) AS message_count FROM message;" | $MYSQL_BIN $MYSQL_OPT | grep -v message` 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_BIN $MYSQL_OPT | grep -v message` MESSAGE_QUEUE_VALUE=`echo "SELECT count(*) AS message_count FROM message_queue;" | $MYSQL $MYSQL_OPT | grep -v message`
if [ "$MESSAGE_VALUE" == "0" -a "$MESSAGE_QUEUE_VALUE" == 0 ] ; then [ "$MESSAGE_VALUE" = 0 ] && [ "$MESSAGE_QUEUE_VALUE" = 0 ] && break
exit 0
fi
sleep $INTERVAL; sleep $INTERVAL;
TIME="`expr $TIME + $INTERVAL`" TIME=`expr $TIME + $INTERVAL`
if [ $TIME -gt $TIMEOUT ] if [ $TIME -gt $TIMEOUT ]
then then
echo "Messages" 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 "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" echo "Timeout"
exit 1 exit 1
fi fi
......
#!/bin/sh #!/bin/sh
set -e
# Small watching script based on Sébastien idea. # Small watching script based on Sébastien idea.
# ideas: # ideas:
...@@ -7,10 +8,10 @@ ...@@ -7,10 +8,10 @@
# - somehow done, use shell variable text_group # - somehow done, use shell variable text_group
# - use python with curses to have runtime control # - use python with curses to have runtime control
function show_help ( ) show_help()
{ {
script_name=`basename $0` script_name=`basename "$0"`
echo """ echo "
Usage: Usage:
$script_name <mysql_opt> [interval seconds] $script_name <mysql_opt> [interval seconds]
Interval is default 5. Interval is default 5.
...@@ -20,20 +21,16 @@ function show_help ( ) ...@@ -20,20 +21,16 @@ function show_help ( )
Typical usage: Typical usage:
$script_name erp5 $script_name erp5
$script_name \"-h remotehost -u user erp5remote\" 3 $script_name \"-h remotehost -u user erp5remote\" 3
""" "
} }
MYSQL_OPT=$1 MYSQL_OPT=$1
INTERVAL=$2 INTERVAL=$2
if [ "$MYSQL_OPT" == "" ] ; then [ "$MYSQL_OPT" ] || {
show_help show_help
exit 1 exit 1
fi }
if [ "$INTERVAL" == "" ] ; then
INTERVAL=5
fi
SELECT="" SELECT=""
for t in message message_queue ; do for t in message message_queue ; do
...@@ -44,4 +41,4 @@ 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; SELECT count(*) AS ${t}_count FROM $t;
""" """
done 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 #!/bin/sh
set -e
if [ $# -ne 2 ]; then [ $# = 2 ] || {
echo -e "Usage:\n $0 db_name table_name" echo "Usage:
`basename "$0"` db_name table_name"
exit 1 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