I tried to create a log reproduction script at the time of apt install

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 atsudo 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

https://github.com/seigot/replay_log

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

Log

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
...

Reproduce the 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.

Remarks

I want to create a demo machine

reference

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

I tried to create a log reproduction script at the time of apt install
I tried to take a look at the flow of Android development environment construction with Android Studio
Set the time of LocalDateTime to a specific time
I tried to create a LINE clone app
What I tried when I wanted to get all the fields of a bean
I tried to summarize the state transition of docker
I tried to decorate the simple calendar a little
05. I tried to stub the source of Spring Boot
I tried to reduce the capacity of Spring Boot
I tried to create a Clova skill in Java
I tried to make a message function of Rails Tutorial extension (Part 1): Create a model
I tried to create a java8 development environment with Chocolatey
I took a peek at the contents of Java's HashMap
I tried to summarize the basics of kotlin and java
[Rails] I tried to create a mini app with FullCalendar
I want to change the log output settings of UtilLoggingJdbcLogger
[Swift] I tried to implement the function of the vending machine
I tried JAX-RS and made a note of the procedure
I want to create a form to select the [Rails] category
I tried to summarize the basic grammar of Ruby briefly
I tried to build the environment of WSL2 + Docker + VSCode
I tried to make a client of RESAS-API in Java
I tried to create a padrino development environment with Docker
I tried to make the sample application into a microservice according to the idea of the book "Microservice Architecture".
Since the reading of JdbcCodeList of TERASOLUNA is slow, I tried to register multiple at once.
[Rails 6.0, Docker] I tried to summarize the Docker environment construction and commands necessary to create a portfolio
I tried to make a message function of Rails Tutorial extension (Part 2): Create a screen to display
I tried to solve the problem of "multi-stage selection" with Ruby
I tried to summarize what was asked at the site-java edition-
I tried to illuminate the Christmas tree in a life game
A solution to the problem of blank spaces at the beginning of textarea
I tried to express the result of before and after of Date class with a number line
I tried to build the environment of PlantUML Server with Docker
I tried to create a Spring MVC development environment on Mac
I tried to explain the method
I made a gem to post the text of org-mode to qiita
I took a look at the resources of Azure Container Instance
I tried to check the operation of gRPC server with grpcurl
I tried to summarize the methods of Java String and StringBuilder
[Java] I tried to make a maze by the digging method ♪
I made a tool to output the difference of CSV file
I tried to solve the problem of Google Tech Dev Guide
I tried to make a sample program using the problem of database specialist in Domain Driven Design
I tried to make a parent class of a value object in Ruby
A memo when you want to clear the time part of the calendar
I tried to summarize the key points of gRPC design and development
How to change the value of a variable at a breakpoint in intelliJ
I thought about the best way to create a ValueObject in Ruby
I tried to make full use of the CPU core in Ruby
I tried to visualize the access of Lambda → Athena with AWS X-Ray
I translated the grammar of R and Java [Updated from time to time]
I tried to measure and compare the speed of GraalVM with JMH
How to implement the email authentication function at the time of user registration
I tried to summarize the methods used
I tried to implement the Iterator pattern
I tried to summarize the Stream API
I tried to create a method to apply multiple filters at once with Java Stream API. Is this okay?
I tried to create a portfolio with AWS, Docker, CircleCI, Laravel [with reference link]
I tried to implement a function equivalent to Felica Lite with HCE-F of Android
I tried to solve the tribonatch sequence problem in Ruby (time limit 10 minutes)
[Rails / JavaScript / Ajax] I tried to create a like function in two ways.