-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from AaveChan/aavechan/fix
fix & Automation of script
- Loading branch information
Showing
7 changed files
with
308 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/bin/bash | ||
|
||
# Get the directory where the script is located | ||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
|
||
# Log file | ||
LOG_FILE="${SCRIPT_DIR}/logs/dolce_vita_collector_log.txt" | ||
|
||
# Ensure the logs directory exists | ||
mkdir -p "${SCRIPT_DIR}/logs" | ||
|
||
# Function to log messages | ||
log_message() { | ||
echo "$(date +"%Y-%m-%d %H:%M:%S"): $1" | tee -a "$LOG_FILE" | ||
} | ||
|
||
# Function to execute and log a command with timeout | ||
execute_command_with_timeout() { | ||
local COMMAND="$1" | ||
local TIMEOUT=180 # 180 seconds = 3 minutes | ||
|
||
log_message "Executing with ${TIMEOUT}s timeout: $COMMAND" | ||
|
||
timeout $TIMEOUT $COMMAND | ||
local EXIT_CODE=$? | ||
|
||
if [ $EXIT_CODE -eq 0 ]; then | ||
log_message "$COMMAND successful" | ||
return 0 | ||
elif [ $EXIT_CODE -eq 124 ]; then | ||
log_message "$COMMAND timed out after ${TIMEOUT} seconds" | ||
return 1 | ||
else | ||
log_message "$COMMAND failed with exit code $EXIT_CODE" | ||
return 1 | ||
fi | ||
} | ||
|
||
# Check if MAINNET should be included | ||
INCLUDE_MAINNET=0 | ||
if [ "$1" == "--include-mainnet" ]; then | ||
INCLUDE_MAINNET=1 | ||
fi | ||
|
||
# Array of networks | ||
NETWORKS=( | ||
"AVALANCHE" | ||
"OPTIMISM" | ||
"POLYGON" | ||
"ARBITRUM" | ||
"METIS" | ||
"BASE" | ||
"GNOSIS" | ||
"BNB" | ||
"SCROLL" | ||
) | ||
|
||
# Add MAINNET if flag is set | ||
if [ $INCLUDE_MAINNET -eq 1 ]; then | ||
NETWORKS+=("MAINNET") | ||
fi | ||
|
||
# Main execution | ||
log_message "Script execution started" | ||
|
||
# Execute make clean | ||
execute_command_with_timeout "make clean" | ||
|
||
# Execute make fetch-reserves and wait for it to complete | ||
if execute_command_with_timeout "make fetch-reserves"; then | ||
log_message "make fetch-reserves completed successfully. Proceeding with minting." | ||
|
||
log_message "Starting minting process for all networks" | ||
|
||
for NETWORK in "${NETWORKS[@]}"; do | ||
log_message "Processing $NETWORK" | ||
|
||
COMMAND="make mint NETWORK=$NETWORK" | ||
if execute_command_with_timeout "$COMMAND"; then | ||
log_message "Minting successful for $NETWORK" | ||
else | ||
log_message "Minting failed or timed out for $NETWORK. Moving to next network." | ||
fi | ||
|
||
echo "----------------------------------------" | ||
done | ||
|
||
log_message "Minting process completed for all networks" | ||
else | ||
log_message "make fetch-reserves failed or timed out. Aborting minting process." | ||
fi | ||
|
||
log_message "Script execution completed" | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/bash | ||
|
||
LOG_DIR="/var/log/dolce_vita_collector" | ||
COUNTER_FILE="${LOG_DIR}/counter.log" | ||
MAX_LINES=2000 | ||
|
||
# Function to send Telegram messages | ||
send_telegram_message() { | ||
local message=$1 | ||
local bot_token="7292479786:AAGb1isSfJpjRpIsgGzwYy6GalIIc6-jNqI" | ||
local chat_id="253560971" | ||
curl -s -X POST "https://api.telegram.org/bot$bot_token/sendMessage" -d chat_id="$chat_id" -d text="$message" | ||
} | ||
|
||
# Initialize the counter and date if they don't exist | ||
if [ ! -f $COUNTER_FILE ]; then | ||
echo "Loop Counter: 0" > $COUNTER_FILE | ||
echo "Last Run: Never" >> $COUNTER_FILE | ||
fi | ||
|
||
# Read the current counter value and date of last run | ||
counter=$(grep -o '[0-9]\+' $COUNTER_FILE | head -n 1) | ||
last_run=$(grep 'Last Run:' $COUNTER_FILE) | ||
|
||
# Increment the counter | ||
counter=$((counter + 1)) | ||
current_date=$(date '+%Y-%m-%d %H:%M:%S') | ||
|
||
# Update the counter file with the new counter and date | ||
echo "Loop Counter: $counter" > $COUNTER_FILE | ||
echo "Last Run: $current_date" >> $COUNTER_FILE | ||
|
||
# Determine if this is a weekly run (with MAINNET) | ||
if [[ "$1" == "--include-mainnet" ]]; then | ||
run_type="Weekly (including MAINNET)" | ||
log_file="${LOG_DIR}/weekly.log" | ||
else | ||
run_type="Daily" | ||
log_file="${LOG_DIR}/daily.log" | ||
fi | ||
|
||
# Log the start of the process | ||
{ | ||
echo "🚀 Starting Dolce Vita Collector $run_type script..." | ||
echo "Loop Counter: $counter" | ||
echo "Last Run: $current_date" | ||
|
||
send_telegram_message "🚀 Starting Dolce Vita Collector $run_type script. Loop Counter: $counter. Last Run: $current_date" | ||
|
||
# Run the original script | ||
if /home/mzeller/dolce_vita_collector/dolce_vita_collector.sh "$@"; then | ||
echo "🎉 Dolce Vita Collector $run_type script completed successfully." | ||
send_telegram_message "🎉 Dolce Vita Collector $run_type script completed successfully. Loop Counter: $counter." | ||
else | ||
echo "⚠️ Dolce Vita Collector $run_type script encountered errors." | ||
send_telegram_message "⚠️ Dolce Vita Collector $run_type script encountered errors. Loop Counter: $counter." | ||
fi | ||
|
||
# Truncate the log file to keep only the last $MAX_LINES lines | ||
tail -n $MAX_LINES $log_file > $log_file.tmp && mv $log_file.tmp $log_file | ||
|
||
# Concatenate the counter file and the log file | ||
cat $COUNTER_FILE $log_file > $log_file.tmp && mv $log_file.tmp $log_file | ||
} | ts '[%Y-%m-%d %H:%M:%S]' >> $log_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.