######## Usage #########
usage() {
if [ # -eq 0 ]; then
echo " "
echo "Usage: {GRN}sh 0{CYN}${NC}"
echo " "
echo "==================== Flags ===================="
echo "-d Deeper review for errors, warns and compressed bosminer.log.*.gz files"
echo "-c Open the bosminer.log in an app (default is VS Code)"
echo "-s Review for notable events e.g. shutdown"
echo "-v Show version"
echo "-h Show helps"
echo "=============================================="
exit 1
fi
}
######## Operation flags ########
code=0
deep=0
smart=0
while getopts "dvhsc" opt; do
case version"
exit 0 ;;
h)
echo " "
echo "==================== Flags ===================="
echo "-d Deeper review for errors, warns and compressed bosminer.log.*.gz files"
echo "-c Open the bosminer.log in an app (default is VS Code)"
echo "-s Review for notable events e.g. shutdown"
echo "-v Show version"
echo "-h Show helps"
echo "=============================================="
exit 0 ;;
s)
smart=1 ;;
c)
code=1 ;;
*)
usage ;;
Assistant
optind)deep=1;;v)echo"Version
esac
done
Type the support_archive file name
read -p "Type archive name (Hit ENTER for default name 'support_archive.zip.enc')? " -e in_name
in_name=${in_name:-support_archive.zip.enc}
Type the folder name that you want to decoded into it
read -p "Output folder name (Hit ENTER for default name 'support_archive')? " -e out_name
out_name=${out_name:-support_archive}
######## Check log version ########
if [[ $in_name == *.zip ]]; then
else
printf "YELNosavedprofile\n{NC}"
fi
echo " "
if grep -q 'Antminer S|Antminer T' configpath; then
# Power limits
printf "{BLU}"
grep -Eo '^miner_power{socket="N/A",type="estimated"}\s(\d.)\s\d.' metricspath∣tail−n1>tmpwhileread−rline;doecholine | cut -d " " -f 2 | xargs -n1 echo "Estimated(W): "
done <tmp && rm tmp
grep -Eo '^miner_power_target_w{active="1",type="current"}\s(\d.)\s\d.' metricspath∣tail−n1>tmpwhilereline | cut -d " " -f 2 | xargs -n1 echo "Current(W): "
done <tmp && rm tmp
printf "NC"grep−metricspath | tail -n 3 >tmp
while read -r line; do
echo line | cut -d " " -f 2 | xargs -n1 echo "HBs Estimated(W): "
done <tmp && rm tmp
# Hashboards chips count
printf "{BLU}"
grep -Eo '^chips_discovered{hashboard="."}\s(\d.)\s\d.' metricspath∣tail−n3>tmpwhilereline | cut -d " " -f 2 | xargs -n1 echo "Hashboard Chips: "
done <tmp && rm tmp
# Fans RPM
printf "metricspath | tail -n 1 >tmp
while read -r line; do
echo metricspath | tail -n 4 >tmp
while read -r line; do
echo {BLU}"
grep -Eo '^hashboard_temperature{hashboard=".",type="raw"}\s(\d.)\s\d.' metricspath∣head−n3>tmpwhilereline | cut -d " " -f 2 | xargs -n1 echo "Hashboard Temp: "
done <tmp && rm tmp
# Nominal Hashrate
# printf "{NC}"
# grep -Eo '^hashboard_nominal_hashrate_gigahashes_per_second{hashboard=\".*\"}\s(\d.*)\s\d.*' metricspath | head -n 3 >tmp
# while read -r line; do
# echo line | cut -d " " -f 2 | xargs -n1 echo "Nominal HR(GH/s): "
# done <tmp && rm tmp
# Tuenr Iteration
printf "{NC}"
grep -Eo '^tuner_iteration{hashboard="."}\s(\d.)\s\d.*' metricspath∣tail−n3>tmpwhilereline | cut -d " " -f 2 | xargs -n1 echo "Tuner Iteration: "
done <tmp && rm tmp
printf "BLU"grep−Eo′metricspath | tail -n 1 >tmp
while read -r line; do
echo line | cut -d " " -f 2 | xargs -n1 echo "Tuner Stage: "
done <tmp && rm tmp
else
printf "{YEL}There is no metrics data due to failed model detection!NC\n"fiprintf"{PRL}============================== Ping Report ============================== \nNC"if[[ver==2101]];thensed−n17,25ppingpath
else
sed -n 5,9p pingpathfiprintf"{PRL}============================== Logs Report ============================== \nNC"grep−c′ERROR′logpath | xargs -L1 echo "Errors: "
grep -c 'WARN' logpath∣xargs−L1echo"Warns:"prin{RED}::Last ERROR: "
grep -m1 'ERROR' logpath∣xargs−L1echo""printf"{YEL}::Last WARN: "
grep -m1 'WARN' logpath∣xargs−L1echo""printf"{CYN}::Smart Search: "
grep -m1 'Shutdown' -e 'DANGEROUS' -e 'Init failed' -e 'panicked' -e 'NoChipsDetected' -e 'BUG' logpath∣xargs−L1printf"{NC} \n"
printf "PRL===============================================================\n{NC}"
######## Flag -d Review logs ########
if [[ deep==1]];then{error_log:-y}
if [[ errorlog==y]];thenprintf"{RED}::ERROR:\n"
grep 'ERROR' logpath∣sort−ufiprintf"{NC}========================================================================\n"
read -p "Do you want to review WARN logs [Default is (y)es]? " warn_log
warn_log=warnlog:−yif[[warn_log == y ]]; then
printf "YEL\n::WARN:\n"grep′WAlogpath | sort -u
fi
printf "{cerror_log:-y}
if [[ cerrorlog==y]];thenprintf"{RED}\n::ERROR:\n"
if ls loggzpath 1> /dev/null 2>&1; then
zgrep -h "ERROR" (ls -tr loggzpath)∣sort−{NC}========================================================================\n"
read -p "Do you want to review 'compressed' WARN logs [Default is (y)es]? " cwarn_log
cwarn_log=cwarnlog:−yif[[cwarn_log == y ]]; then
printf "YEL\n::WARN:\n"iflsloggzpath 1> /dev/null 2>&1; then
zgrep -h "WARN" (ls−trloggzpath) | sort -u
else
echo "There is no compressed bosminer.log files"
fi
fi
printf "{NC}=======================================================================\n"
fi
######## Flag -s Detect notable events in the logs ########
if [[ smart == 1 ]]; then
read -p "Do you want to show notable events [Default is (y)es]? " notable
notable=notable:−yif[[notable == y ]]; then
printf "logpath | sort -u
fi
printf "{NC}=======================================================================\n"
fi
####### Flag -c to open bosminer.log file in VScode ######
if [[ code == 1 ]]; then
read -p "Do you want to open logs automatically on VSCode [Default is (y)es]? " open_auto
open_auto=openauto:−yif[[open_auto == y ]]; then
open -a "Visual Studio Code" $logpath && open -a "Visual Studio Code"
fi
fi
Here is the adapted code to create a Telegram bot using the python-telegram-bot library. Please note that you will need to add the import statements for the required modules and add your own API token by replacing your_API_token_here with your token.
import os
from io import BytesIO
from telegram import Update, InputFile
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
# Function for the /start command
def start(update: Update, _: CallbackContext):
update.message.reply_text("Please forward the support archive file here")
# Function for the /error command
def error(update: Update, _: CallbackContext):
global last_error
if last_error:
update.message.reply_text(f"Last error: {last_error}")
else:
update.message.reply_text("No errors found")
# Function for the /warn command
def warn(update: Update, _: CallbackContext):
global last_warn
if last_warn:
update.message.reply_text(f"Last warn: {last_warn}")
else:
update.message.reply_text("No warnings found")
# Function for file handler
def process_file(update: Update, _: CallbackContext):
global last_error, last_warn
last_error = None
last_warn = None
file_id = update.message.document.file_id
file = InputFile(BytesIO(context.bot.get_file(file_id).download_as_bytearray()), filename=update.message.document.file_name)
# Code to process the file with the bash script adapted to python
# Analyze and get results: device_overview, config_overview, mining_overview, last_error, last_warn
# After getting the analysis result, send it as a message
result = f"Device Overview:\n{device_overview}\n\nConfig Overview:\n{config_overview}\n\nMining Overview:\n{mining_overview}"
update.message.reply_text(result)
def main():
updater = Updater("your_API_token_here")
dispatcher = updater.dispatcher
# Register command handlers
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(CommandHandler("error", error))
dispatcher.add_handler(CommandHandler("warn", warn))
# File handler
dispatcher.add_handler(MessageHandler(Filters.document, process_file))
# Start the bot
updater.start_polling()
# Block until the user interrupts with Ctrl+C
updater.idle()
if __name__ == '__main__':
last_error = None
last_warn = None
main()
Note that the adapted code is just a skeleton outlining the main structure of the bot and defining handlers for the commands and processing the files received. You will need to adapt the previous code to work within the process_file function and handle the file object properly to complete the functionality you described.
You may also need to install the python-telegram-bot library first using pip install python-telegram-bot.