From a99dd5da15201f03499a8d9d6dc0bb211a90508f Mon Sep 17 00:00:00 2001 From: Steven Baltakatei Sandoval Date: Sun, 28 Jun 2020 18:37:17 +0000 Subject: [PATCH] chore(unitproc):Move scripts to prvt submodule --- prvt | 2 +- unitproc/bkbtclog | 59 -------------------------------------------- unitproc/bkhashwatch | 43 -------------------------------- 3 files changed, 1 insertion(+), 103 deletions(-) delete mode 100755 unitproc/bkbtclog delete mode 100755 unitproc/bkhashwatch diff --git a/prvt b/prvt index 4c95471..43fe6c9 160000 --- a/prvt +++ b/prvt @@ -1 +1 @@ -Subproject commit 4c954717c286c85f491907c90822975c8f26d568 +Subproject commit 43fe6c9ac858abdb9e0be65177ab8ed7c45bafc7 diff --git a/unitproc/bkbtclog b/unitproc/bkbtclog deleted file mode 100755 index cd2353a..0000000 --- a/unitproc/bkbtclog +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -# Date: 2020-03-08T03:48Z; baltakatei> - -# Description: Log bitcoin block stats to file every minute for one -# hour. Also adds stats to PRNG. - -# Usage: bkbtclog [path] - - # [path]: Path to write log file. - -# Dependencies: jq - -# Modify PATH to include some non-standard executable directories. -PATH="/usr/local/bin/:$PATH" # for bitcoind and bitcoin-cli -PATH="/usr/bin/:$PATH" # for jq - -# Exit if jq is unavailable or bitcoin-cli getblockcount not available. -if ! ( ( command -v jq 1>/dev/null 2>&1 ) && ( bitcoin-cli getblockcount 1>/dev/null 2>&1 ) ) ; then echo "ERROR:Commands jq or bitcoin-cli not available." 1>&2; exit 1; fi - -# Set script time-to-live to 1 hour in seconds. See https://stackoverflow.com/a/11198713 . -SCRIPT_TTL=3600 -SECONDS_END=$(( SECONDS + SCRIPT_TTL )) - -# Set output log file path -LOG_PATH="$1" -LOG_DIR=$(dirname "$LOG_PATH" ) - -# Exit if LOG_DIR doesn't exist. -if [ ! -d "$LOG_DIR" ]; then echo "ERROR:Specified log directory doesn't exist." 1>&2; - echo "LOG_DIR is:""$LOG_DIR" 1>&2; exit 1; fi - -# Loop until script age exceeds SCRIPT_END. -while [ $SECONDS -lt $SECONDS_END ]; do - # Create log file and first line header if file at LOG_PATH doesn't exist. - if [ ! -f "$LOG_PATH" ]; then - echo "TIME","BTC_BESTBLOCKCOUNT","BTC_BESTBLOCKTIME","BTC_BESTBLOCKHASH","BTC_MEDIANFEE","BTC_TOTALOUTPUT","BTC_TXTOTALSIZE","BTC_TXCOUNT","BTC_TXIN","BTC_TXOUT","BTC_MAXTXFEERATE","BTC_MINTXFEERATE","BITCOINCORE_VERSION" >> "$LOG_PATH"; - fi - TIME="$(date +%Y%m%dT%H%M%S%z)" - BITCOINCORE_VERSION="$(bitcoin-cli -version)" - BTC_BESTBLOCKSTATS_JSON="$(bitcoin-cli getblockstats "$(bitcoin-cli getblockcount)" '["height","time","blockhash","medianfee","total_out","total_size","txs","ins","outs","maxfeerate","minfeerate"]')" - BTC_BESTBLOCKCOUNT=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .height' ) - BTC_BESTBLOCKTIME_UNIX=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .time' ) - BTC_BESTBLOCKTIME=$(date --date=@"$BTC_BESTBLOCKTIME_UNIX" +%Y%m%dT%H%M%S%z ) - BTC_BESTBLOCKHASH=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .blockhash' | tr -dc "[:xdigit:]" ) - BTC_MEDIANFEE=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .medianfee' ) - BTC_TOTALOUTPUT=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .total_out' ) - BTC_TXTOTALSIZE=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .total_size' ) - BTC_TXCOUNT=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .txs' ) - BTC_TXIN=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .ins' ) - BTC_TXOUT=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .outs' ) - BTC_MAXTXFEERATE=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .maxfeerate' ) - BTC_MINTXFEERATE=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .minfeerate' ) - OUTPUT=$(echo "$TIME","$BTC_BESTBLOCKCOUNT","$BTC_BESTBLOCKTIME","$BTC_BESTBLOCKHASH","$BTC_MEDIANFEE","$BTC_TOTALOUTPUT","$BTC_TXTOTALSIZE","$BTC_TXCOUNT","$BTC_TXIN","$BTC_TXOUT","$BTC_MAXTXFEERATE","$BTC_MINTXFEERATE","$BITCOINCORE_VERSION") - echo "$OUTPUT" >> "$LOG_PATH"; - echo "$OUTPUT" >> /dev/random; - sleep 60 -done -exit 0 diff --git a/unitproc/bkhashwatch b/unitproc/bkhashwatch deleted file mode 100755 index 63aeabc..0000000 --- a/unitproc/bkhashwatch +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -# Date: 2020-04-08T23:37Z - -# Description: A bash script that hashes files immediately after they -# are modified. Watches for 1 hour then exits. - -# Dependencies: inotifywait, timeout, awk, b2sum, date - -echoerr() { echo "$@" 1>&2; } - -DIR_TO_WATCH="/home/baltakatei/Sync" -DIR_LOG="/home/baltakatei/Sync/kodawkuori-07/2020/archive-PERS/logs/files" -DIGEST_ALGO="b2sum" -DIR_LOG_PATH=$DIR_LOG"/""$(date +%Y%m%d)""..""$(hostname)""_""$DIGEST_ALGO""_filewrites.log" # The .log extension is important for inotifywait "--exclude" option. -TIMEOUT="1h" # Limit inotifywait process to 1 hour. -MIN_FILE_SIZE=1 # smallest file size to log (in bytes) - -if ! command -v "$DIGEST_ALGO" 1>/dev/null 2>/dev/null; then echoerr "ERROR: $0 could not find command $DIGEST_ALGO ."; exit 1; fi - -if [ ! -d "$DIR_TO_WATCH" ]; then echoerr "ERROR: $0 could not parse $DIR_TO_WATCH as directory."; exit 1; fi - -timeout $TIMEOUT inotifywait -m -e close_write -e moved_to --exclude ".tmp$" --exclude ".log$" -r --format "%w%f" "$DIR_TO_WATCH" | - while read line; do - # note: make sure to exclude the $DIR_LOG_PATH via ".log$" (or equivalent means) to avoid endless logging of log writes. - EVENT_DATE="$(date +%Y%m%dT%H%M%S.%N%z )" - TARGET_FILEPATH="$(echo -n $line )" - TARGET_FILENAME="$(basename "$TARGET_FILEPATH" )" - TARGET_FILESIZE="$(du -b "$TARGET_FILEPATH" | awk '{print $1}' )" - TARGET_FILEMTIME="$(date -r "$TARGET_FILEPATH" +%Y%m%dT%H%M%S.%N%z)" - TARGET_DIGEST="$(cat "$TARGET_FILEPATH" | $DIGEST_ALGO | awk '{print $1}' )" - EVENT_LOG_ENTRY="$EVENT_DATE","$TARGET_FILEMTIME","$DIGEST_ALGO","$TARGET_DIGEST","$TARGET_FILESIZE","$TARGET_FILEPATH" - echo "$EVENT_LOG_ENTRY" >> /dev/random # Mix written file's digest with system PRNG. - if [ -d "$DIR_LOG" ] && [ $(( "$TARGET_FILESIZE" - "$MIN_FILE_SIZE" )) -ge 0 ]; then - if [ ! -f "$DIR_LOG_PATH" ]; then - echo "EVENT_DATE,TARGET_FILEMTIME,DIGEST_ALGO,TARGET_DIGEST,TARGET_FILESIZE,TARGET_FILEPATH" >> "$DIR_LOG_PATH" # print field names in first row - fi - echo "$EVENT_LOG_ENTRY" >> "$DIR_LOG_PATH"; # Log written file's digest if TARGET_FILESIZE greater or equal to MIN_FILE_SIZE (in bytes). - #echo "$EVENT_LOG_ENTRY" >> /tmp/bkhashwatch.log #debug - fi - done -echo "Timeout of $TIMEOUT elapsed. Exiting." -exit 0 -- 2.30.2