fix: add few functions

- create send_notification function
- auto scripts/*.sh scripts searcher
This commit is contained in:
2025-06-18 23:18:52 +02:00
parent 98aa864306
commit 4856b90ee1
5 changed files with 28 additions and 26 deletions

View File

@@ -56,10 +56,7 @@ install_file() {
} }
echo echo
datetime_print "------------- install files -------------" datetime_print "------------- install files -------------"
install_file "aws-backup.sh" "$SCRIPT_FILE" -Dm755 for element in scripts/*.sh; do install_file "$(basename $element)" "$SCRIPT_FILE" -Dm755; done
install_file "disk-monitor.sh" "$SCRIPT_FILE" -Dm755
install_file "sshd-login.sh" "$SCRIPT_FILE" -Dm755
install_file "telegram.sh" "$SCRIPT_FILE" -Dm755
install_file "docker-compose.yml" "$ETC_DIR" -Dm644 install_file "docker-compose.yml" "$ETC_DIR" -Dm644
create_env_variable() { create_env_variable() {

View File

@@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
source /etc/serverconfig/.env source /usr/local/bin/notifications.sh
disk_usage() { disk_usage() {
df -h / | grep / | awk -v max="$1" '{ df -h / | grep / | awk -v max="$1" '{
usage = $5; usage = $5;
gsub("%", "", usage); gsub("%", "", usage);
@@ -11,9 +11,6 @@
} }
printf "<b>💾 Disk Usage Information:</b>\nTotal Size: %s, Used: %s, Available: %s\n\n", $2, $3, $4; printf "<b>💾 Disk Usage Information:</b>\nTotal Size: %s, Used: %s, Available: %s\n\n", $2, $3, $4;
}' }'
} }
curl -X POST "https://api.telegram.org/bot$TOKEN/sendMessage" \ send_notification "$(disk_usage 80)"
-d "chat_id=$CHAT_ID" \
-d "text=$(disk_usage 80)" \
-d "parse_mode=HTML"

11
scripts/notifications.sh Normal file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
source /etc/serverconfig/.env
send_notification() {
local message="$1"
curl -X POST "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage" \
-d "chat_id=$TELEGRAM_CHAT_ID" \
-d "text=$message" \
-d "parse_mode=HTML"
}

View File

@@ -1,6 +1,6 @@
#!bin/bash #!bin/bash
source /etc/serverconfig/.env source /usr/local/bin/notifications.sh
case "$PAM_TYPE" in case "$PAM_TYPE" in
open_session) open_session)
@@ -12,8 +12,5 @@ case "$PAM_TYPE" in
esac esac
if [ -n "$PAYLOAD" ] ; then if [ -n "$PAYLOAD" ] ; then
curl -X POST "https://api.telegram.org/bot$TOKEN/sendMessage" \ send_notification "$PAYLOAD"
-d "chat_id=$CHAT_ID" \
-d "text=$PLAYLOAD" \
-d "parse_mode=HTML"
fi fi

View File