I tried to create a log reproduction device at the time of apt install (I don't know if it will be useful, but you should feel the exhilaration of a successful installation ...)
For example, create `` test-update.shto reproduce the log at
sudo apt-get update -y` as follows.
test-update.sh
#!/bin/bash
sudo apt-get update -y
The script for logging/reproducing is as replay.sh
replay.sh
#!/bin/bash -x
set -e
set -u
IS_RECORD="n"
IS_REPLAY="n"
OUTPUT_LOG_FNAME="output.log"
TMP_LOG_FNAME="tmp.log"
# option
while getopts rp OPT
do
case $OPT in
"r" ) IS_RECORD="y"
shift;;
"p" ) IS_REPLAY="y"
shift;;
esac
done
if [ $IS_RECORD != "n" ];then
############
## ##
## record ##
## ##
############
echo "RECORD command:[$*], see $OUTPUT_LOG_FNAME"
echo "$*" | xargs bash -c 'printf "%s %s\n" "$(date +%Y%m%d%H%M%S%N)" "$*"' bash 2>&1 | tee $OUTPUT_LOG_FNAME
$* | xargs -L 1 bash -c 'printf "%s %s\n" "$(date +%Y%m%d%H%M%S%N)" "$*"' bash 2>&1 | tee $TMP_LOG_FNAME
cat $TMP_LOG_FNAME >> $OUTPUT_LOG_FNAME
rm $TMP_LOG_FNAME
echo "record replay log: $OUTPUT_LOG_FNAME"
elif [ $IS_REPLAY != "n" ];then
############
## ##
## replay ##
## ##
############
echo "REPLAY command:[`head -1 $OUTPUT_LOG_FNAME`]"
PREV_TIME=`head -1 $OUTPUT_LOG_FNAME | cut -d' ' -f1`
while read line; do
CURRENT_TIME=`echo $line | cut -d' ' -f1`
TMP=`echo $((CURRENT_TIME-PREV_TIME))`
TIME_DIFF=`echo "scale=5; $TMP / 1000000000.0" | bc`
PREV_TIME=$CURRENT_TIME
COMMAND_LOG=`echo $line | cut -d' ' -f2-`
#echo "$TIME_DIFF $COMMAND_LOG"
echo "$COMMAND_LOG"
sleep $TIME_DIFF
done < $OUTPUT_LOG_FNAME
fi
Specify the execution command with -r
(example: bash test-update.sh
)
$ bash replay.sh -r "bash test-update.sh"
RECORD command:[bash test-update.sh], see output.log
...
If you specify the -p
option in bash replay.sh
, the recorded log will be reproduced.
$ bash replay.sh -p
REPLAY command:[20201230225127118529673 bash test-update.sh]
0 bash test-update.sh
.03175 acquisition:1 file:/var/cuda-repo-10-2-local-10.2.89 InRelease
.00096 Ignore:1 file:/var/cuda-repo-10-2-local-10.2.89 InRelease
.00106 acquisition:2 file:/var/visionworks-repo InRelease
.00097 Ignore:2 file:/var/visionworks-repo InRelease
.00099 Get:3 file:/var/visionworks-sfm-repo InRelease
.00095 Ignore:3 file:/var/visionworks-sfm-repo InRelease
.Get 00090:4 file:/var/visionworks-tracking-repo InRelease
.00121 Ignore:4 file:/var/visionworks-tracking-repo InRelease
.00145 acquisition:5 file:/var/cuda-repo-10-2-local-10.2.89 Release [574 B]
.00106 acquisition:6 file:/var/visionworks-repo Release [2,001 B]
.00097 Acquired:7 file:/var/visionworks-sfm-repo Release [2,005 B]
.Get 00101:5 file:/var/cuda-repo-10-2-local-10.2.89 Release [574 B]
.Get 00090:8 file:/var/visionworks-tracking-repo Release [2,010 B]
.Get 00111:6 file:/var/visionworks-repo Release [2,001 B]
.00094 Acquired:7 file:/var/visionworks-sfm-repo Release [2,005 B]
.00088 Get:8 file:/var/visionworks-tracking-repo Release [2,010 B]
.02595 hit:10 http://packages.osrfoundation.org/gazebo/ubuntu-stable bionic InRelease
.00495 hit:11 http://packages.ros.org/ros/ubuntu bionic InRelease
.00751 hit:12 https://repo.download.nvidia.com/jetson/common r32.4 InRelease
.00474 hit:14 http://ports.ubuntu.com/ubuntu-ports bionic InRelease
.02960 hit:16 http://ports.ubuntu.com/ubuntu-ports bionic-updates InRelease
.17503 hit:18 http://ports.ubuntu.com/ubuntu-ports bionic-backports InRelease
.03971 hit:19 http://ports.ubuntu.com/ubuntu-ports bionic-security InRelease
.02077 hit:20 https://repo.download.nvidia.com/jetson/t210 r32.4 InRelease
.37960 Loading package list...
I would appreciate it if you could teach me if there is anything useful.
I want to create a demo machine
Location and confirmation method of operation log of apt command Display history done by apt [bash] File output with time added to error content Prepend output date and time to standard output How to time stamp each standard output without changing the program and sample in Python I want to take the full date to milliseconds with the date command! Optional analysis with bash bash: standard output and standard error are output to log
Recommended Posts