Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 358211bcff | |||
| a2f95b2ecb |
@@ -7,6 +7,11 @@
|
|||||||
# Author: Kovács Zoltán <kovacs.zoltan@smartfront.hu>
|
# Author: Kovács Zoltán <kovacs.zoltan@smartfront.hu>
|
||||||
# Kovács Zoltán <kovacsz@marcusconsulting.hu>
|
# Kovács Zoltán <kovacsz@marcusconsulting.hu>
|
||||||
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
|
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||||
|
# 2026-05-01 v1.1
|
||||||
|
# new: dnf support has been added for Oracle/RHEL compatibility.
|
||||||
|
# mod: the egrep calls have been replaced by grep -E command
|
||||||
|
# for better POSIX compatibility.
|
||||||
|
# fix: 'which zpool 2>/dev/null' to omit unnecessary warnings.
|
||||||
# 2023-06-18 v1.0
|
# 2023-06-18 v1.0
|
||||||
# new: forked from the "SMARTERP_skeleton" repository.
|
# new: forked from the "SMARTERP_skeleton" repository.
|
||||||
# mod: "instance" => "service"
|
# mod: "instance" => "service"
|
||||||
@@ -55,7 +60,7 @@ if [ -n "$CRON" ]; then
|
|||||||
# Ubuntu gets the initial environment from a separate file.
|
# Ubuntu gets the initial environment from a separate file.
|
||||||
if [ -r "/etc/environment" ]; then
|
if [ -r "/etc/environment" ]; then
|
||||||
# Extracts from this file, strips the right part w/o quotes.
|
# Extracts from this file, strips the right part w/o quotes.
|
||||||
includepath=$(cat "/etc/environment" | $(which egrep) '^PATH=')
|
includepath=$(cat "/etc/environment" | $(which grep) -E '^PATH=')
|
||||||
includepath=${includepath:5}
|
includepath=${includepath:5}
|
||||||
includepath="${includepath%\"}"; includepath="${includepath#\"}"
|
includepath="${includepath%\"}"; includepath="${includepath#\"}"
|
||||||
[[ -n "$includepath" ]] && PATH="$PATH:$includepath"
|
[[ -n "$includepath" ]] && PATH="$PATH:$includepath"
|
||||||
@@ -71,7 +76,7 @@ if ! [[ "$PATH" =~ '/sbin:' ]]; then PATH="$PATH:/usr/local/sbin:/usr/sbin:/sbin
|
|||||||
#
|
#
|
||||||
TR=$(which tr 2>/dev/null)
|
TR=$(which tr 2>/dev/null)
|
||||||
if [ -z "$TR" ]; then echo "$MSG_MISSINGDEP tr."; exit 1 ; fi
|
if [ -z "$TR" ]; then echo "$MSG_MISSINGDEP tr."; exit 1 ; fi
|
||||||
for item in basename cut df egrep head mail printf sleep
|
for item in basename cut df grep head mail printf sleep
|
||||||
do
|
do
|
||||||
if [ -n "$(which $item)" ]
|
if [ -n "$(which $item)" ]
|
||||||
then export $(echo $item | "$TR" '[:lower:]' '[:upper:]')=$(which $item)
|
then export $(echo $item | "$TR" '[:lower:]' '[:upper:]')=$(which $item)
|
||||||
@@ -92,12 +97,14 @@ if [ -x "$MAIL" ]; then
|
|||||||
[[ -x "/etc/update-motd.d/00-header" ]] \
|
[[ -x "/etc/update-motd.d/00-header" ]] \
|
||||||
&& message+="$("/etc/update-motd.d/00-header")\n\n"
|
&& message+="$("/etc/update-motd.d/00-header")\n\n"
|
||||||
message+="$("$DF" -h | "$HEAD" -n1)\n"
|
message+="$("$DF" -h | "$HEAD" -n1)\n"
|
||||||
message+="$("$DF" -h | "$EGREP" '^/dev/' | "$EGREP" -v 'loop')\n"
|
message+="$("$DF" -h | "$GREP" -E '^/dev/' | "$GREP" -E -v 'loop')\n"
|
||||||
if [ -n "$(which zpool)" -a -x "$(which zpool)" ]; then
|
if [ -n "$(which zpool 2>/dev/null)" -a -x "$(which zpool 2>/dev/null)" ]; then
|
||||||
# Includes ZFS partitions (if any).
|
# Includes ZFS partitions (if any).
|
||||||
for pool in $("$(which zpool)" list -H | "$CUT" -f1) "" #"
|
for pool in $("$(which zpool)" list -H | "$CUT" -f1) "" #"
|
||||||
do [[ -n "$pool" ]] && message+="$("$DF" -h | "$EGREP" "^$pool/")\n"; done
|
do [[ -n "$pool" ]] && message+="$("$DF" -h | "$GREP" -E "^$pool/")\n"; done
|
||||||
fi
|
fi
|
||||||
|
[[ -x "/bin/dnf" ]] \
|
||||||
|
&& message+="\n$("/bin/dnf" updateinfo summary)\n"
|
||||||
[[ -x "/etc/update-motd.d/90-updates-available" ]] \
|
[[ -x "/etc/update-motd.d/90-updates-available" ]] \
|
||||||
&& message+="$("/etc/update-motd.d/90-updates-available")\n"
|
&& message+="$("/etc/update-motd.d/90-updates-available")\n"
|
||||||
[[ -x "/etc/update-motd.d/98-fsck-at-reboot" ]] \
|
[[ -x "/etc/update-motd.d/98-fsck-at-reboot" ]] \
|
||||||
@@ -105,7 +112,7 @@ if [ -x "$MAIL" ]; then
|
|||||||
[[ -x "/etc/update-motd.d/99-reboot-required" ]] \
|
[[ -x "/etc/update-motd.d/99-reboot-required" ]] \
|
||||||
&& message+="$("/etc/update-motd.d/99-reboot-required")\n"
|
&& message+="$("/etc/update-motd.d/99-reboot-required")\n"
|
||||||
message+="\nBest regards: the Maintenance Bot"
|
message+="\nBest regards: the Maintenance Bot"
|
||||||
echo -e "$message" | "$MAIL" -s "$subject" "$USER"
|
echo -e "$message" | "$MAIL" -s "$subject" "$USER"
|
||||||
fi
|
fi
|
||||||
# Done with mail.
|
# Done with mail.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# 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.
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Dummy file to met the dependencies. Does nothing.
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# A simple wrapper script to s-nail. Needs a suitable smarthost.
|
||||||
|
# A copy of sent mail is saved in the /var/mail/$USER mbox file.
|
||||||
|
# It is recommended to rotate these files e.g via /etc/logrotate.d.
|
||||||
|
# See also https://manpages.ubuntu.com/manpages/focal/man1/s-nail.1.html
|
||||||
|
|
||||||
|
# SMTP settings - feel free to adjust.
|
||||||
|
#
|
||||||
|
# Sender's address is fixed - pay attention to the SPF DNS record!
|
||||||
|
FROM="no-reply@example.com"
|
||||||
|
# Default recipient(s), delimited by space.
|
||||||
|
TO="sysadmin@example.com webadmin@example.com"
|
||||||
|
SMTP_SERVER="mail.example.com"
|
||||||
|
# smtp (for tcp/25), smtps (for tcp/465), submission (for tcp/587).
|
||||||
|
SMTP_PROTO="submission"
|
||||||
|
# URL escaping required for special characters below.
|
||||||
|
SMTP_USER="no-reply%40example.com"
|
||||||
|
SMTP_PASS="topsecret"
|
||||||
|
|
||||||
|
# s-nail call.
|
||||||
|
#
|
||||||
|
if [ -x "$(which s-nail 2>/dev/null)" ]; then
|
||||||
|
# The recipient's address is the last argument.
|
||||||
|
recipient="${@: -1}"
|
||||||
|
set -- "${@: 1: $#-1}"
|
||||||
|
# Our scripts may send mails to the local user.
|
||||||
|
# In this case, we need replace the recipient address.
|
||||||
|
[[ "$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 \
|
||||||
|
-S mta="$SMTP_PROTO://$SMTP_USER:$SMTP_PASS@$SMTP_SERVER" \
|
||||||
|
-S record="/var/mail/$USER" \
|
||||||
|
"${@}" $recipient
|
||||||
|
fi
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user