Skip to content

Commit

Permalink
[ros_bridge][QNX log fetch] Add archive feature to save disk space.
Browse files Browse the repository at this point in the history
[ros_bridge][QNX log fetch] With 'archive' option, remove *.log files to save disk space.

[ros_bridge][QNX log fetch] Save the archived logs file to the same dir where raw log files are (/opt/jsk/var/log).
This way it'll be easier in the future to look for the older log file archives once their raw log files are removed.

[ros_bridge][QNX log fetch] Archive feature now can specify the period, instead of text matching.
  • Loading branch information
130s committed Jun 2, 2017
1 parent b87a73a commit 2a3143d
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions hironx_ros_bridge/robot/qnx_fetch_log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
function usage {
echo >&2 "usage: $1 [hostname (default:nextage)]"
echo >&2 " $2 [ossuser_qnx (default:tork)]"
echo >&2 " $3 [date_specifier (default:none. Format: yyyymmdd, or it can be partial, e.g. yyyymm. Searches the files whose name matches the given string.)]"
echo >&2 " $3 [do_archive (default:1): If a string 'archive' is passed, remove all raw log files to save the disk space (date specified in 'date_after' will be ignored). Existing zip archives will not be deleted.]"
echo >&2 " $4 [date_after (default:none. Format: yyyy-mm-dd or mmddyyyy): Do not operate on files modified prior to the specified date.]"
echo >&2 " [-h|--help] Print help message."
exit 0
}
Expand All @@ -28,29 +29,41 @@ hostname=$1
hostname=${hostname:="nextage"}
ossuser_qnx=$2
ossuser_qnx=${ossuser_qnx:="tork"}
date_specifier=$3
date_specifier=${date_specifier:=""} # By default this isn't set, so fetch files for all dates.
do_archive=$3
do_archive=${do_archive:="1"} # 1 is set by default. Actually anything other than "archive" is ignored.
date_after=$4
date_after=${date_after:="1970-01-01"}
OSS_FOLDER='/opt/jsk'
OSS_FOLDER_LOG=${OSS_FOLDER}/var/log
DATE=`date +"%Y%m%d-%H%M%S"`
TMP_FOLDER_ROOT=/tmp/HiroNXO_Log
NAME_LOGFILE=${TMP_FOLDER_ROOT}/qnx_fetch_log_${hostname}_${DATE}.log
NAME_LOGFILE_SCRIPT=${TMP_FOLDER_ROOT}/qnx_fetch_log_${hostname}_${DATE}.log
NAME_LOGARCHIVE_FILE=opt_jsk_var_logs_${DATE}.zip
NAME_LOGARCHIVE=/tmp/${NAME_LOGARCHIVE_FILE}

mkdir ${TMP_FOLDER_ROOT}

COMMAND_ARCHIVE=''
if [ ${do_archive} == "archive" ]; then
echo "* Log files will be archived.";
COMMAND_ARCHIVE="rm ${OSS_FOLDER_LOG}/*.log; mv ${NAME_LOGARCHIVE} ${OSS_FOLDER_LOG}";
NAME_LOGARCHIVE=${OSS_FOLDER_LOG}/${NAME_LOGARCHIVE_FILE}
fi

# Command that gets run on QNX.
# - (Assumes remotely logged in to qnx via ssh)
# - Create tarball of /opt/jsk/var/log/* at /home/tork
# - Create tarball of /opt/jsk/var/log/* at /home/tork>
# - Log out of QNX
# - scp the tarball
commands="
. ~/.profile || echo '~/.profile does not exist. Move on anyway.';
env;
trap 'exit 1' ERR;
set +x;
set -x;
echo '* Create tarball of ${OSS_FOLDER_LOG} *';
tar cfvz opt_jsk_var_logs_${DATE}.tgz ${OSS_FOLDER_LOG}/*${date_specifier}* || echo '* Failed to create tarball *';
zip -t ${date_after} ${NAME_LOGARCHIVE} ${OSS_FOLDER_LOG}/*.log;
eval ${COMMAND_ARCHIVE};
echo '* Exitting ssh session to QNX. *';
exit;
Expand All @@ -66,9 +79,9 @@ echo "** Report if there's any issue for this script at https://github.com/start

read -p "Run the command @ $hostname (y/n)? "
if [ "$REPLY" == "y" ]; then
ssh $ossuser_qnx@$hostname -t $commands 2>&1 | tee ${NAME_LOGFILE}
ssh $ossuser_qnx@$hostname -t $commands 2>&1 | tee ${NAME_LOGFILE_SCRIPT}
echo "====="
scp $ossuser_qnx@$hostname:/home/$ossuser_qnx/opt_jsk_var_logs_${DATE}.tgz . | tee ${NAME_LOGFILE}
scp $ossuser_qnx@$hostname:${NAME_LOGARCHIVE} . | tee ${NAME_LOGFILE_SCRIPT}

IS_SUCCESS=0
else
Expand All @@ -80,5 +93,5 @@ else
fi

if [ "${IS_SUCCESS}" -eq 1 ]; then
echo "Operation unsuccessful. Send back log file: ${NAME_LOGFILE}"
echo "Operation unsuccessful. Send back log file: ${NAME_LOGFILE_SCRIPT}"
fi

0 comments on commit 2a3143d

Please sign in to comment.