Addition of Markdown File: - Introduce a Markdown file 'handout.md' to store information in a structured format. - Markdown file is created with headers, columns, and content for German and Spanish text. Refactoring and Cleanup: - Declare 'markdown_file' variable to store the path of the Markdown file. - Introduce 'all' array to store components like 'date' and 'time'. - Clear files in 'text_dir' at the beginning to ensure a clean start. File Transfer and Notification: - Use 'scp' to transfer files to A72, maintaining the directory structure. - Enhance the curl command to include the Markdown file as an attachment. - Set the 'Filename' header for better identification on the server. - Display the constructed curl command for visibility. - Execute the curl command to send a high-priority notification with the Markdown file. Logging and Output: - Display the content of the generated Markdown file. - Initiate 'generate_mp3.sh' on A72 in the background. Note: Adjusted the output formatting for better readability in the commit message.
106 lines
3.0 KiB
Bash
Executable File
106 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#######################################
|
|
# generate_text.sh - Create text files (German and Spanish)
|
|
#
|
|
# Author: Michael Haider
|
|
# Created on: 26.01.2024
|
|
# Description: This script generates various text files with information such as date, time, news, and weather in German and Spanish.
|
|
#######################################
|
|
|
|
text_dir="/root/iobroker_scripts/general/.text"
|
|
markdown_file="$text_dir/handout.md"
|
|
|
|
all=("date" "time") # Add more elements as needed
|
|
|
|
# remove files in text_dir
|
|
rm -f $text_dir/*
|
|
|
|
# Function to get the IP address of Lisa's iPhone
|
|
check_ip() {
|
|
mac_address="e4:cd:d1" # Replace this with the MAC address
|
|
attempts=10
|
|
interval=5
|
|
|
|
for ((i = 1; i <= $attempts; i++)); do
|
|
A72_ip=$(arp-scan -r 3 -v --localnet | grep "$mac_address" | awk '{print $1}')
|
|
|
|
if [ -n "$A72_ip" ]; then
|
|
echo "Found IP: $A72_ip"
|
|
return 0 # Success: IP address found
|
|
fi
|
|
|
|
if [ $i -lt $attempts ]; then
|
|
echo "Wait $interval seconds before the next attempt."
|
|
sleep $interval
|
|
fi
|
|
done
|
|
|
|
# All attempts unsuccessful
|
|
echo "The target could not be reached after $attempts attempts."
|
|
return 1 # Error: IP address not found
|
|
}
|
|
|
|
# Execute the check_ip function.
|
|
check_ip
|
|
|
|
# Function to generate the text files
|
|
generate_text() {
|
|
# German
|
|
date_de=$(date '+Heute ist %A, der %d. %B %Y.')
|
|
echo "$date_de" > "$text_dir/date_de.txt"
|
|
time_de=$(date '+Es ist %H:%M Uhr.')
|
|
echo "$time_de" > "$text_dir/time_de.txt"
|
|
|
|
# Spanish
|
|
date_es=$(trans -b :de :es "$date_de")
|
|
echo "$date_es" > "$text_dir/date_es.txt"
|
|
time_es=$(trans -b :de :es "$time_de")
|
|
echo "$time_es" > "$text_dir/time_es.txt"
|
|
}
|
|
|
|
# Call the generate_text function
|
|
generate_text
|
|
|
|
# Create Markdown file
|
|
echo "## Handout:" > $markdown_file
|
|
echo "| Deutsch | Español |" >> $markdown_file
|
|
echo "| ------- | ------- |" >> $markdown_file
|
|
|
|
for component in "${all[@]}"; do
|
|
german_output=$(cat $text_dir/${component}_de.txt)
|
|
spanish_output=$(cat $text_dir/${component}_es.txt)
|
|
echo "| $german_output | $spanish_output |" >> $markdown_file
|
|
done
|
|
|
|
# Transfer files to A72
|
|
scp -r -i /root/.ssh/A72 "$text_dir" root@$A72_ip:/data/scripts/
|
|
|
|
# Send Notification to A72 with handout.md file
|
|
curl_command="curl -u 'Michaelis:u5ptufUFuDL6q4yEcSN3iqas5gtXNkN77Lx3cy3oX8UoSgFWdifYy9FVopv2Zwtu' \
|
|
-H 'Priority:High' \
|
|
-T $markdown_file \
|
|
-H 'Filename: handout.md' \
|
|
-d $'notification_date: Heute ist Dienstag, der 30. Januar 2024.\n"
|
|
|
|
for component in "${all[@]}"; do
|
|
curl_command+="${component}:\n"
|
|
curl_command+="$(cat $text_dir/${component}_de.txt)\n"
|
|
curl_command+="$(cat $text_dir/${component}_es.txt)\n"
|
|
done
|
|
|
|
curl_command="${curl_command%\\n}" # Remove the trailing newline
|
|
curl_command+="\n'"
|
|
|
|
curl_command+=" https://ntfy.michaelis.digital/ioBroker"
|
|
|
|
echo "curl_command: $curl_command"
|
|
eval "$curl_command" # Execute the constructed curl command
|
|
|
|
# Display Markdown file content
|
|
cat $markdown_file
|
|
|
|
# Start generate_mp3.sh on A72
|
|
nohup ssh -i /root/.ssh/A72 -f root@$A72_ip '/data/scripts/generate_mp3.sh' > /root/generate_mp3.log &
|
|
|