mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-18 17:58:55 +00:00
pt-mysql-summary for 2.1
This commit is contained in:
232
lib/bash/collect_mysql_info.sh
Normal file
232
lib/bash/collect_mysql_info.sh
Normal file
@@ -0,0 +1,232 @@
|
||||
# This program is copyright 2011-2012 Percona Inc.
|
||||
# Feedback and improvements are welcome.
|
||||
#
|
||||
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
|
||||
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
|
||||
# licenses.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
# Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||
# ###########################################################################
|
||||
# collect_mysql_info package
|
||||
# ###########################################################################
|
||||
|
||||
# Package: collect_mysql_info
|
||||
# collect collects mysql information.
|
||||
|
||||
# XXX
|
||||
# THIS LIB REQUIRES log_warn_die.sh, summary_common.sh, and alt_cmds.sh!
|
||||
# XXX
|
||||
|
||||
# Simply looks for instances of mysqld in the outof of ps.
|
||||
collect_mysqld_instances () {
|
||||
local file="$1"
|
||||
ps auxww 2>/dev/null | grep mysqld > "$file"
|
||||
}
|
||||
|
||||
# Tries to find the my.cnf file by examining 'ps' output.
|
||||
# You have to specify the port for the instance you are
|
||||
# interested in, in case there are multiple instances.
|
||||
find_my_cnf_file() {
|
||||
local file="$1"
|
||||
local port=${2:-""}
|
||||
|
||||
local cnf_file=""
|
||||
if test -n "$port" && grep -- "/mysqld.*--port=$port" "${file}" >/dev/null 2>&1 ; then
|
||||
cnf_file="$(grep -- "/mysqld.*--port=$port" "${file}" \
|
||||
| awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \
|
||||
| head -n1)"
|
||||
else
|
||||
cnf_file="$(grep '/mysqld' "${file}" \
|
||||
| awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \
|
||||
| head -n1)"
|
||||
fi
|
||||
|
||||
if [ ! -n "${cnf_file}" ]; then
|
||||
_d "Cannot autodetect config file, trying common locations"
|
||||
cnf_file="/etc/my.cnf";
|
||||
if [ ! -e "${cnf_file}" ]; then
|
||||
cnf_file="/etc/mysql/my.cnf";
|
||||
fi
|
||||
if [ ! -e "${cnf_file}" ]; then
|
||||
cnf_file="/var/db/mysql/my.cnf";
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$cnf_file"
|
||||
}
|
||||
|
||||
collect_mysql_variables () {
|
||||
local file="$1"
|
||||
$CMD_MYSQL $EXT_ARGV -ss -e 'SHOW /*!40100 GLOBAL*/ VARIABLES' > "$file"
|
||||
}
|
||||
|
||||
collect_mysql_status () {
|
||||
local file="$1"
|
||||
$CMD_MYSQL $EXT_ARGV -ss -e 'SHOW /*!50000 GLOBAL*/ STATUS' > "$file"
|
||||
}
|
||||
|
||||
collect_mysql_databases () {
|
||||
local file="$1"
|
||||
$CMD_MYSQL $EXT_ARGV -ss -e 'SHOW DATABASES' > "$file" 2>/dev/null
|
||||
}
|
||||
|
||||
collect_mysql_plugins () {
|
||||
local file="$1"
|
||||
$CMD_MYSQL $EXT_ARGV -ss -e 'SHOW PLUGINS' > "$file" 2>/dev/null
|
||||
}
|
||||
|
||||
collect_mysql_slave_status () {
|
||||
local file="$1"
|
||||
$CMD_MYSQL $EXT_ARGV -ssE -e 'SHOW SLAVE STATUS' > "$file" 2>/dev/null
|
||||
}
|
||||
|
||||
collect_mysql_innodb_status () {
|
||||
local file="$1"
|
||||
$CMD_MYSQL $EXT_ARGV -ssE -e 'SHOW /*!50000 ENGINE*/ INNODB STATUS' > "$file" 2>/dev/null
|
||||
}
|
||||
|
||||
collect_mysql_processlist () {
|
||||
local file="$1"
|
||||
$CMD_MYSQL $EXT_ARGV -ssE -e 'SHOW FULL PROCESSLIST' > "$file" 2>/dev/null
|
||||
}
|
||||
|
||||
collect_mysql_users () {
|
||||
local file="$1"
|
||||
$CMD_MYSQL $EXT_ARGV -ssE -e 'SELECT COUNT(*), SUM(user=""), SUM(password=""), SUM(password NOT LIKE "*%") FROM mysql.user' > "$file" 2>/dev/null
|
||||
}
|
||||
|
||||
collect_master_logs_status () {
|
||||
local master_logs_file="$1"
|
||||
local master_status_file="$2"
|
||||
$CMD_MYSQL $EXT_ARGV -ss -e 'SHOW MASTER LOGS' > "$master_logs_file" 2>/dev/null
|
||||
$CMD_MYSQL $EXT_ARGV -ss -e 'SHOW MASTER STATUS' > "$master_status_file" 2>/dev/null
|
||||
}
|
||||
|
||||
# Somewhat different from the others, this one joins the status we got earlier
|
||||
collect_mysql_deferred_status () {
|
||||
local status_file="$1"
|
||||
local defer_file="$2"
|
||||
collect_mysql_status "$TMPDIR/defer_gatherer"
|
||||
cat "$TMPDIR/defer_gatherer" | join "$status_file" - > "$defer_file"
|
||||
}
|
||||
|
||||
collect_internal_vars () {
|
||||
local file="$1"
|
||||
|
||||
local FNV_64=""
|
||||
if $CMD_MYSQL $EXT_ARGV -e 'SELECT FNV_64("a")' >/dev/null 2>&1; then
|
||||
FNV_64="Enabled";
|
||||
else
|
||||
FNV_64="Unknown";
|
||||
fi
|
||||
|
||||
local now="$($CMD_MYSQL $EXT_ARGV -ss -e 'SELECT NOW()')"
|
||||
local user="$($CMD_MYSQL $EXT_ARGV -ss -e 'SELECT CURRENT_USER()')"
|
||||
local trigger_count=$($CMD_MYSQL $EXT_ARGV -ss -e "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TRIGGERS" 2>/dev/null)
|
||||
local has_symbols="$(has_symbols "${CMD_MYSQL}")"
|
||||
|
||||
echo "pt-summary-internal-now $now" >> "$file"
|
||||
echo "pt-summary-internal-user $user" >> "$file"
|
||||
echo "pt-summary-internal-FNV_64 $FNV_64" >> "$file"
|
||||
echo "pt-summary-internal-trigger_count $trigger_count" >> "$file"
|
||||
echo "pt-summary-internal-symbols $has_symbols" >> "$file"
|
||||
}
|
||||
|
||||
# Uses mysqldump and dumps the results to FILE.
|
||||
# args and dbtodump are passed to mysqldump.
|
||||
get_mysqldump_for () {
|
||||
local file="$1"
|
||||
local args="$2"
|
||||
local dbtodump="${3:---all-databases}"
|
||||
|
||||
$CMD_MYSQLDUMP $EXT_ARGV --no-data --skip-comments \
|
||||
--skip-add-locks --skip-add-drop-table --compact \
|
||||
--skip-lock-all-tables --skip-lock-tables --skip-set-charset \
|
||||
${args} "${dbtodump}" > "$file"
|
||||
}
|
||||
|
||||
# Returns a string with arguments to pass to mysqldump.
|
||||
# Takes one argument, which should be a
|
||||
get_mysqldump_args () {
|
||||
local file="$1"
|
||||
local trg_arg=""
|
||||
|
||||
# If mysqldump supports triggers, then add options for routines.
|
||||
if $CMD_MYSQLDUMP --help --verbose 2>&1 | grep triggers >/dev/null; then
|
||||
_d "mysqldump supports triggers"
|
||||
trg_arg="--routines"
|
||||
fi
|
||||
|
||||
if [ "${trg_arg}" ]; then
|
||||
# Find out if there are any triggers. If there are none, we will skip
|
||||
# that option to mysqldump, because when mysqldump checks for them, it
|
||||
# can take a long time, one table at a time.
|
||||
local triggers="--skip-triggers"
|
||||
local trg=$(get_var "pt-summary-internal-trigger_count" "$file" )
|
||||
if [ -n "${trg}" ] && [ "${trg}" -gt 0 ]; then
|
||||
_d "We have triggers to dump"
|
||||
triggers="--triggers"
|
||||
fi
|
||||
trg_arg="${trg_arg} ${triggers}";
|
||||
fi
|
||||
echo "${trg_arg}"
|
||||
}
|
||||
|
||||
collect_mysql_info () {
|
||||
local dir="$1"
|
||||
local prefix="${2:-percona-toolkit}"
|
||||
|
||||
collect_mysqld_instances "$dir/${prefix}-mysqld-instances"
|
||||
|
||||
collect_mysql_variables "$dir/${prefix}-mysql-variables"
|
||||
collect_mysql_status "$dir/${prefix}-mysql-status"
|
||||
collect_mysql_databases "$dir/${prefix}-mysql-databases"
|
||||
collect_mysql_plugins "$dir/${prefix}-mysql-plugins"
|
||||
collect_mysql_slave_status "$dir/${prefix}-mysql-slave"
|
||||
collect_mysql_innodb_status "$dir/${prefix}-innodb-status"
|
||||
collect_mysql_processlist "$dir/${prefix}-mysql-processlist"
|
||||
collect_mysql_users "$dir/${prefix}-mysql-users"
|
||||
|
||||
local binlog="$(get_var log_bin "$dir/${prefix}-mysql-variables")"
|
||||
if [ "${binlog}" ]; then
|
||||
_d "Got a binlog, going to get MASTER LOGS and MASTER STATUS"
|
||||
collect_master_logs_status "$dir/${prefix}-mysql-master-logs" "$dir/${prefix}-mysql-master-status"
|
||||
fi
|
||||
|
||||
local uptime="$(get_var Uptime "$dir/${prefix}-mysql-status")"
|
||||
local current_time="$($CMD_MYSQL $EXT_ARGV -ss -e \
|
||||
"SELECT LEFT(NOW() - INTERVAL ${uptime} SECOND, 16)")"
|
||||
|
||||
local port="$(get_var port "$dir/${prefix}-mysql-variables")"
|
||||
local cnf_file=$(find_my_cnf_file "$dir/${prefix}-mysqld-instances" ${port});
|
||||
|
||||
# TODO: Do these require a file of their own?
|
||||
echo "pt-summary-internal-current_time $current_time" >> "$dir/${prefix}-mysql-variables"
|
||||
echo "pt-summary-internal-Config_File $cnf_file" >> "$dir/${prefix}-mysql-variables"
|
||||
collect_internal_vars "$dir/${prefix}-mysql-variables"
|
||||
|
||||
if [ -n "${OPT_DUMP_SCHEMAS}" ]; then
|
||||
_d "--dump-schemas passed in, dumping early"
|
||||
local trg_arg="$( get_mysqldump_args "$dir/${prefix}-mysql-variables" )"
|
||||
get_mysqldump_for "$dir/${prefix}-mysqldump" "${trg_arg}" "${OPT_DUMP_SCHEMAS}"
|
||||
fi
|
||||
|
||||
# TODO: gather this data in the same format as normal: TS line, stats
|
||||
(
|
||||
sleep $OPT_SLEEP
|
||||
collect_mysql_deferred_status "$dir/${prefix}-mysql-status" "$dir/${prefix}-mysql-status-defer"
|
||||
) &
|
||||
_d "Forked child is $!"
|
||||
}
|
||||
|
||||
# ###########################################################################
|
||||
# End collect_mysql_info package
|
||||
# ###########################################################################
|
@@ -24,6 +24,7 @@
|
||||
set -u
|
||||
|
||||
# Global variables.
|
||||
PTDEBUG="${PTDEBUG:-""}"
|
||||
EXIT_STATUS=0
|
||||
|
||||
log() {
|
||||
@@ -41,6 +42,10 @@ die() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
_d () {
|
||||
[ "$PTDEBUG" ] && echo "# $(log "$@")" >&2
|
||||
}
|
||||
|
||||
# ###########################################################################
|
||||
# End log_warn_die package
|
||||
# ###########################################################################
|
||||
|
112
lib/bash/report_formatting.sh
Normal file
112
lib/bash/report_formatting.sh
Normal file
@@ -0,0 +1,112 @@
|
||||
# This program is copyright 2011 Percona Inc.
|
||||
# Feedback and improvements are welcome.
|
||||
#
|
||||
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
|
||||
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
|
||||
# licenses.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
# Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||
# ###########################################################################
|
||||
# report_formatting package
|
||||
# ###########################################################################
|
||||
|
||||
# Package: report_formatting
|
||||
# Common report formatting functions for the summary tools.
|
||||
|
||||
set -u
|
||||
|
||||
POSIXLY_CORRECT=1
|
||||
export POSIXLY_CORRECT
|
||||
|
||||
fuzzy_formula='
|
||||
rounded = 0;
|
||||
if (fuzzy_var <= 10 ) {
|
||||
rounded = 1;
|
||||
}
|
||||
factor = 1;
|
||||
while ( rounded == 0 ) {
|
||||
if ( fuzzy_var <= 50 * factor ) {
|
||||
fuzzy_var = sprintf("%.0f", fuzzy_var / (5 * factor)) * 5 * factor;
|
||||
rounded = 1;
|
||||
}
|
||||
else if ( fuzzy_var <= 100 * factor) {
|
||||
fuzzy_var = sprintf("%.0f", fuzzy_var / (10 * factor)) * 10 * factor;
|
||||
rounded = 1;
|
||||
}
|
||||
else if ( fuzzy_var <= 250 * factor) {
|
||||
fuzzy_var = sprintf("%.0f", fuzzy_var / (25 * factor)) * 25 * factor;
|
||||
rounded = 1;
|
||||
}
|
||||
factor = factor * 10;
|
||||
}'
|
||||
|
||||
# Does fuzzy rounding: rounds to nearest interval, but the interval gets larger
|
||||
# as the number gets larger. This is to make things easier to diff.
|
||||
fuzz () {
|
||||
echo $1 | awk "{fuzzy_var=\$1; ${fuzzy_formula} print fuzzy_var;}"
|
||||
}
|
||||
|
||||
# Fuzzy computes the percent that $1 is of $2
|
||||
fuzzy_pct () {
|
||||
local pct="$(echo $1 $2 | awk '{ if ($2 > 0) { printf "%d", $1/$2*100; } else {print 0} }')";
|
||||
echo "$(fuzz "${pct}")%"
|
||||
}
|
||||
|
||||
# Prints a section header. All spaces in the string passed in are replaced
|
||||
# with #'s and all underscores with spaces.
|
||||
section () {
|
||||
local str="$1"
|
||||
local line="$(printf '#_%-60s' "${str}_" | sed -e 's/[[:space:]]/#/g' -e 's/_/ /g')"
|
||||
printf "%s\n" "${line}"
|
||||
}
|
||||
|
||||
NAME_VAL_LEN=12
|
||||
name_val () {
|
||||
# We use $NAME_VAL_LEN here because the two summary tools, as well as
|
||||
# the tests, use diffent widths.
|
||||
printf "%+*s | %s\n" "${NAME_VAL_LEN}" "$1" "$2"
|
||||
}
|
||||
|
||||
# Sub: shorten
|
||||
# Shorten a value in bytes to another representation.
|
||||
#
|
||||
shorten() {
|
||||
local num="$1"
|
||||
local prec="${2:-2}"
|
||||
local div="${3:-1024}"
|
||||
|
||||
echo "$num" | awk -v prec="$prec" -v div="$div" '
|
||||
{
|
||||
size = 4;
|
||||
val = $1;
|
||||
|
||||
unit = val >= 1099511627776 ? "T" : val >= 1073741824 ? "G" : val >= 1048576 ? "M" : val >= 1024 ? "k" : "";
|
||||
|
||||
while ( int(val) && !(val % 1024) ) {
|
||||
val /= 1024;
|
||||
}
|
||||
|
||||
while ( val > 1000 ) {
|
||||
val /= div;
|
||||
}
|
||||
|
||||
printf "%.*f%s", prec, val, unit;
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
group_concat () {
|
||||
sed -e '{H; $!d;}' -e 'x' -e 's/\n[[:space:]]*\([[:digit:]]*\)[[:space:]]*/, \1x/g' -e 's/[[:space:]][[:space:]]*/ /g' -e 's/, //' "${1}"
|
||||
}
|
||||
|
||||
# ###########################################################################
|
||||
# End report_formatting package
|
||||
# ###########################################################################
|
1291
lib/bash/report_mysql_info.sh
Normal file
1291
lib/bash/report_mysql_info.sh
Normal file
File diff suppressed because it is too large
Load Diff
157
lib/bash/summary_common.sh
Normal file
157
lib/bash/summary_common.sh
Normal file
@@ -0,0 +1,157 @@
|
||||
# This program is copyright 2011-2012 Percona Inc.
|
||||
# Feedback and improvements are welcome.
|
||||
#
|
||||
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
|
||||
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
|
||||
# licenses.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
# Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||
# ###########################################################################
|
||||
# summary_common package
|
||||
# ###########################################################################
|
||||
|
||||
# Package: summary_common
|
||||
# Common functions between the summary packages.
|
||||
|
||||
set -u
|
||||
|
||||
# Tries to find the niceness of the passed in PID. First with ps, and
|
||||
# failing that, with a bit of C, using getpriority().
|
||||
# Returns the nice for the pid, or "?" if it can't find any.
|
||||
get_nice_of_pid () {
|
||||
local pid="$1"
|
||||
local niceness=$(ps -p $pid -o nice | tail -n+2 | awk '{print $1; exit;}')
|
||||
|
||||
if [ -n "${niceness}" ]; then
|
||||
echo $niceness
|
||||
else
|
||||
local tmpfile="$TMPDIR/nice_through_c.tmp.c"
|
||||
_d "Getting the niceness from ps failed, somehow. We are about to try this:"
|
||||
cat <<EOC > "$tmpfile"
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int priority = getpriority(PRIO_PROCESS, $pid);
|
||||
if ( priority == -1 && errno == ESRCH ) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
printf("%d\\n", priority);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
EOC
|
||||
local c_comp=$(_which gcc)
|
||||
if [ -z "${c_comp}" ]; then
|
||||
c_comp=$(_which cc)
|
||||
fi
|
||||
_d "$tmpfile: $( cat "$tmpfile" )"
|
||||
_d "$c_comp -xc \"$tmpfile\" -o \"$tmpfile\" && eval \"$tmpfile\""
|
||||
$c_comp -xc "$tmpfile" -o "$tmpfile" 2>/dev/null && eval "$tmpfile" 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "?"
|
||||
_d "Failed to get a niceness value for $pid"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Fetches the oom value for a given pid.
|
||||
# To avoi deprecation warnings, tries /proc/PID/oom_score_adj first.
|
||||
# Will only work if /proc/cpuinfo is available.
|
||||
get_oom_of_pid () {
|
||||
local pid="$1"
|
||||
local oom_adj=""
|
||||
|
||||
if [ -n "${pid}" ] && [ -e /proc/cpuinfo ]; then
|
||||
if [ -s "/proc/$pid/oom_score_adj" ]; then
|
||||
oom_adj=$(cat "/proc/$pid/oom_score_adj" 2>/dev/null)
|
||||
_d "For $pid, the oom value is $oom_adj, retreived from oom_score_adj"
|
||||
else
|
||||
oom_adj=$(cat "/proc/$pid/oom_adj" 2>/dev/null)
|
||||
_d "For $pid, the oom value is $oom_adj, retreived from oom_adj"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "${oom_adj}" ]; then
|
||||
echo "${oom_adj}"
|
||||
else
|
||||
echo "?"
|
||||
_d "Can't find the oom value for $pid"
|
||||
fi
|
||||
}
|
||||
|
||||
CMD_FILE="$( _which file 2>/dev/null )"
|
||||
CMD_NM="$( _which nm 2>/dev/null )"
|
||||
CMD_OBJDUMP="$( _which objdump 2>/dev/null )"
|
||||
|
||||
has_symbols () {
|
||||
local executable="$(_which "$1")"
|
||||
local has_symbols=""
|
||||
|
||||
if [ "${CMD_FILE}" ] \
|
||||
&& [ "$($CMD_FILE "${executable}" | grep 'not stripped' )" ]; then
|
||||
has_symbols=1
|
||||
elif [ "${CMD_NM}" ] \
|
||||
|| [ "${CMD_OBJDMP}" ]; then
|
||||
if [ "${CMD_NM}" ] \
|
||||
&& [ !"$("${CMD_NM}" -- "${executable}" 2>&1 | grep 'File format not recognized' )" ]; then
|
||||
if [ -z "$( $CMD_NM -- "${executable}" 2>&1 | grep ': no symbols' )" ]; then
|
||||
has_symbols=1
|
||||
fi
|
||||
elif [ -z "$("${CMD_OBJDUMP}" -t -- "${executable}" | grep '^no symbols$' )" ]; then
|
||||
has_symbols=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${has_symbols}" ]; then
|
||||
echo "Yes"
|
||||
return 0
|
||||
else
|
||||
echo "No"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
setup_data_dir () {
|
||||
local data_dir=""
|
||||
if [ -z "$OPT_SAVE_DATA" ]; then
|
||||
# User didn't specify a --save-data dir, so use a sub-dir in our tmpdir.
|
||||
mkdir "$TMPDIR/data" || die "Cannot mkdir $TMPDIR/data"
|
||||
data_dir="$TMPDIR/data"
|
||||
else
|
||||
# Check the user's --save-data dir.
|
||||
if [ ! -d "$OPT_SAVE_DATA" ]; then
|
||||
mkdir "$OPT_SAVE_DATA" || die "Cannot mkdir $OPT_SAVE_DATA"
|
||||
fi
|
||||
touch "$OPT_SAVE_DATA/test" || die "Cannot write to $OPT_SAVE_DATA"
|
||||
rm "$OPT_SAVE_DATA/test" || die "Cannot rm $OPT_SAVE_DATA/test"
|
||||
data_dir="$OPT_SAVE_DATA"
|
||||
fi
|
||||
echo "$data_dir"
|
||||
}
|
||||
|
||||
# gets a value from the passed in file. Returns _GET_VAR_DEFAULT if it doesn't
|
||||
# exist, which unless changed is 0.
|
||||
_GET_VAR_DEFAULT=0
|
||||
get_var () {
|
||||
local varname="$1"
|
||||
local file="$2"
|
||||
local v="$(awk "\$1 ~ /^${varname}$/ { print \$2 }" "${file}")"
|
||||
echo "${v:-$_GET_VAR_DEFAULT}"
|
||||
}
|
||||
|
||||
# ###########################################################################
|
||||
# End summary_common package
|
||||
# ###########################################################################
|
Reference in New Issue
Block a user