Compare commits

...

2 Commits

Author SHA1 Message Date
Kovács Zoltán 14d499350e Improvements (cronmail) and fixes in mail utilities. 2026-05-02 23:46:29 +02:00
Kovács Zoltán 5b0b5ae2d3 configs_backup.sh now saves all root files (not only the docker-compose.yml). 2026-05-02 23:12:36 +02:00
6 changed files with 70 additions and 15 deletions
BIN
View File
Binary file not shown.
+7 -3
View File
@@ -1,3 +1,7 @@
# Wrapper scripts to various mail transfer agents.
Only needed if your system does not provide the POSIX mailx compatible mail command. If sending email is prohibited from your environment use *mail.dummy* to avoid warnings from cron, etc.
To activate, choose a suitable one then place it somewhere in the path (~/bin or /usr/local/bin are recommended), name it mail and give it execute permission.
# Wrapper scripts to various mail agents
Only needed if your system does not provide a local MTA (e.g *sendmail*) and/or a POSIX *mailx* compatible mail command.
To activate, choose a suitable one then place it somewhere in the path (*/usr/local/bin* is recommended), name or symlink it to *mail* and give it execute permission to anyone.
To use them with *crond*, you may need the *cronmail* converter script, which can accept sendmail-formatted mail and convert it into a suitable *mailx* call. You can usually set this script as a mail sender for *crond* using the *CRONDARGS* environment variable.
+52
View File
@@ -0,0 +1,52 @@
#!/bin/bash
#
# This is a sendmail to mailx format converter script.
# It receives a well-formed email text from standard input, parses it,
# and invokes a POSIX mailx compliant mail user agent with the result.
#
# It is primarily designed to use with crond. To activate
# use CRONDARGS="-m pathname_to_cronmail" in/etc/default/cron or
# /etc/sysconfig/crond configuration.
#
# Author: Kovács Zoltán <kovacsz@marcusconsulting.hu>
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
# 2026-05-02 v0.1 Initila release.
# Initialisations.
#
SUBJECT=""
RECIPIENT="$USER" # Default recipient.
MESSAGE=""
MUA="/usr/local/bin/mail" # Custom mail user agent script.
# Parsing the stdin line by line.
#
while IFS= read -r line
do
# Parses the recipient.
if [[ "$line" =~ ^(T|t)o:\ .*$ ]]; then
RECIPIENT="${line#*: }"
# Parses the subject line.
elif [[ "$line" =~ ^(S|s)ubject:\ .*$ ]]; then
SUBJECT="${line#*: }"
# Message body starts with an empty line.
elif [[ "$line" =~ ^$ ]]; then
MESSAGE+="\n"
# Collects the message body lines.
# The first empty line will be stripped.
elif [ -n "$MESSAGE" ]; then
[[ "$MESSAGE" = "\n" ]] \
&& MESSAGE="$line\n" \
|| MESSAGE+="$line\n"
fi
done
# Calls the mail user agent.
#
if [ -x "$MUA" ]; then
if [ -n "$SUBJECT" -o -n "$MESSAGE" ]; then
echo -e "$MESSAGE" | "$MUA" -s "$SUBJECT" "$RECIPIENT"
fi
fi
# That's all, Folks! :)
-3
View File
@@ -1,3 +0,0 @@
#!/bin/bash
#
# Dummy file to met the dependencies. Does nothing.
+3 -3
View File
@@ -20,7 +20,7 @@ SMTP_PASS="topsecret"
# s-nail call.
#
if [ -x "$(which s-nail 2>/dev/null)" ]; then
if [ -x "/bin/s-nail" ]; then
# The recipient's address is the last argument.
recipient="${@: -1}"
set -- "${@: 1: $#-1}"
@@ -29,8 +29,8 @@ if [ -x "$(which s-nail 2>/dev/null)" ]; then
[[ "$recipient" = "$USER" ]] && recipient="$TO"
[[ "$recipient" = "$USER@$HOSTNAME" ]] && recipient="$TO"
if [ -n "$recipient" ]; then
"$(which s-nail)" -S from="$FROM" -S v15-compat \
-S smtp-auth="login" -S smtp-use-starttls \
"/bin/s-nail" -S from="$FROM" -S v15-compat \
-S smtp-auth="login" $([[ "$SMTP_PROTO" = "submission" ]] && echo "-S smtp-use-starttls") \
-S mta="$SMTP_PROTO://$SMTP_USER:$SMTP_PASS@$SMTP_SERVER" \
-S record="/var/mail/$USER" \
"${@}" $recipient
+4 -2
View File
@@ -5,6 +5,8 @@
#
# Author: Kovács Zoltán <kovacsz@marcusconsulting.hu>
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
# 2026-04-28 v0.3
# mod: now includes all files (not only YMLFILE) in the base folder.
# 2024-03-07 v0.2
# fix: tar now dereferences the symlinks (if any).
# 2021-09-03 v0.1 Initial release
@@ -26,7 +28,7 @@ MSG_NONWRITE="The target directory isn't writable"
# Checks the dependencies.
TR=$(which tr 2>/dev/null)
if [ -z "$TR" ]; then echo "$MSG_MISSINGDEP tr."; exit 1 ; fi
for item in date dirname hostname readlink tar
for item in date dirname find hostname readlink tar
do
if [ -n "$(which $item)" ]
then export $(echo $item | "$TR" '[:lower:]' '[:upper:]' | "$TR" '-' '_')=$(which $item)
@@ -72,7 +74,7 @@ if [ -w "$BACKUPDIR" ]; then
BACKUP_NAME="configs.$("$DATE" '+%Y%m%d_%H%M%S').$("$HOSTNAME")"
( cd "$BASE_DIR"
"$TAR" czhf "$BACKUPDIR/$BACKUP_NAME.tgz" \
"$YMLFILE" configs docker \
$("$FIND" -maxdepth 1 -type f) configs docker \
2>>"$BACKUPDIR/$BACKUP_NAME.log"
)
fi