Jump to content

how to modify MOTD


Go to solution Solved by g00d,

Recommended Posts

Posted

Hello community,

 

when I SSH into my ODROID-HC2 I get the nice coloured MOTD which I really like.

Zitat

 


  ___      _           _     _  __  ___   _ _  _   
 / _ \  __| |_ __ ___ (_) __| | \ \/ / | | | || |  
| | | |/ _` | '__/ _ \| |/ _` |  \  /| | | | || |_
| |_| | (_| | | | (_) | | (_| |  /  \| |_| |__   _|
 \___/ \__,_|_|  \___/|_|\__,_| /_/\_\\___/   |_|  
                                                   
Welcome to Armbian 21.08.3 Bullseye with Linux 5.4.151-odroidxu4

System load:   1%               Up time:       13:38    
Memory usage:  6% of 1.94G      IP:           192.168.0.181
CPU temp:      46°C               Usage of /:    5% of 32G        

Last login: Sun Oct 31 09:18:55 2021 from 192.168.0.58
 

 

 

Question 1)

I found the configuration file /etc/default/armbian-motd and the directory /etc/update-motd.d and after reading the bash code I lack in understanding why some information lines are suppressed in the MOTD banner when the scripts get executed. For example: I would expect to see some net traffic stats because /etc/default/armbian-motd uses the default setting PRIMARY_DIRECTION="rx" and the package "vnstat" is installed and "vnstat -i eth0" return correct output. I also tried changing PRIMARY_DIRECTION line to ="both" but I don't get any net status displayed in that MOTD banner. Why?

 

EDIT: I found the culprit which lies in /etc/update-motd.d/30-armbian-sysinfo script. My PRIMARY_INTERFACE is eth0 and as such also defined in /etc/default/armbian-motd. But that line here:

# Check whether PRIMARY_INTERFACE exist in /var/lib/vnstat/
PRIMARY_INTERFACE=$(comm -12 <(ls -1 /var/lib/vnstat/ 2> /dev/null) <(echo "$PRIMARY_INTERFACE" | sed 's/+/\n/g') | sed -n -e 'H;${x;s/\n/+/g;s/^+//;p;}')

sets that variable to "blank" because the command shown above will fail. The content of /var/lib/vnstat in my case is only one single file called "vnstat.db". When I comment out that line, I get the expected output of RX and TX when running the 30-armbian-sysinfo script. Is anything known about this and can provide more information?

 

Question 2) I don't get various stuff displayed, for example the disk temperature. It's not displayed when running the 30-armbian-sysinfo script although the command provided in the script for the variable "storage_temp" inside the function storage_info() works fine when executed at the bash prompt. Why does the command

display "storage temp" "$storage_temp" $HDD_TEMP_LIMIT "0" "°C" "" ; a=$((a+$?))

 

not output the storage temperature ?

 

Question 3)

I also wanna display the last and current value of smartmontool for my SATA disk for ID#192 which corresponds to "Power-Off_Retract_Count". The  command therefore is smartctl -a /dev/sda | grep Power-Off_Retract | awk '{ print $10 }' but where do I add this? I think it's not advised to modify /etc/update-motd.d/30-armbian-sysinfo file because on the next upgrade it will get overwritten, is it?

 

My idea was modifying that file /etc/update-motd.d/30-armbian-sysinfo by adding a new line after line:162 in the function storage_info which stores the current desired value into the variable name storage_poff_retract :

function storage_info() {
        # storage info
        RootInfo=$(df -h /)
        root_usage=$(awk '/\// {print $(NF-1)}' <<<${RootInfo} | sed 's/%//g')
        root_total=$(awk '/\// {print $(NF-4)}' <<<${RootInfo})
        StorageInfo=$(df -h $STORAGE 2>/dev/null | grep $STORAGE)
        if [[ -n "${StorageInfo}" && ${RootInfo} != *$STORAGE* ]]; then
                storage_usage=$(awk '/\// {print $(NF-1)}' <<<${StorageInfo} | sed 's/%//g')
                storage_total=$(awk '/\// {print $(NF-4)}' <<<${StorageInfo})
                if [[ -n "$(command -v smartctl)" ]]; then
                        DISK="${STORAGE::-1}"
                        storage_temp+=$(smartctl -l scttempsts $DISK 2> /dev/null | grep -i 'Current Temperature:' | awk '{print $(NF-1)}')
                        storage_poff_retract=$(smartctl -a $STORAGE | grep Power-Off_Retract | awk '{print $10}')
                fi
        fi
} # storage_info

 

and the also after line 234 adding a new line to display this value:

display "storage temp" "$storage_temp" $HDD_TEMP_LIMIT "0" "°C" "" ; a=$((a+$?))
display "storage Power-Off Retract Count" "$storage_poff_retract" "" ; a=$((a+$?))

 

though I am not sure if that would be correct because it doesn't work as expected and not displayed, same issue as in question 2. What do you think?

Please point me to the right direction. Thanks!

  • Solution
Posted

Well, I made some progression and want to share it with the community:

 

Related to question 1)

still unresolved because I don't know if I am missing something or this could possibly be a bug?

 

Related to question 2)

the culprit lies inside the function storage_info() because I am not using simply /dev/sda1 but an encrypted drive. My disk *is* /dev/sda1 but it's LUKS encrypted and so my device for the system is /dev/mapper/rootfs or even more /dev/mapper/volumeGroup1-rootfs because I am also using LVM. The storage_info() function does not take this into account. I had to modify the function to this here:

function storage_info() {
        # storage info
        RootInfo=$(df -h /)
        root_usage=$(awk '/\// {print $(NF-1)}' <<<${RootInfo} | sed 's/%//g')
        root_total=$(awk '/\// {print $(NF-4)}' <<<${RootInfo})
        StorageInfo=$(df -h $STORAGE 2>/dev/null | grep $STORAGE)
        #if [[ -n "${StorageInfo}" && ${RootInfo} != *$STORAGE* ]]; then
        if [[ -n "${StorageInfo}" ]]; then
                storage_usage=$(awk '/\// {print $(NF-1)}' <<<${StorageInfo} | sed 's/%//g')
                storage_total=$(awk '/\// {print $(NF-4)}' <<<${StorageInfo})
                if [[ -n "$(command -v smartctl)" ]]; then
                        #DISK="${STORAGE::-1}"
                        storage_temp+=$(smartctl -l scttempsts $DISK 2> /dev/null | grep -i 'Current Temperature:' | awk '{print $(NF-1)}')
                        storage_pwroff_retract_count=$(smartctl -a $DISK | grep Power-Off_Retract | awk '{print $10}')
                fi
        fi
} # storage_info

 

in detail:

 

it needs to comment out the originally line

#if [[ -n "${StorageInfo}" && ${RootInfo} != *$STORAGE* ]]; then

 

and change it to:

if [[ -n "${StorageInfo}" ]]; then

 

it needs to comment the following line here inside the if clause:

#DISK="${STORAGE::-1}"

 

and it needs a definition in the top of the script where we need to add a DISK variable. Simply said, we need to separate DISK and STORAGE in case of encrypted systems and/or LVM used. The top of the script 30-armbian-sysinfo looks like that in my case:

DISK=/dev/sda1
STORAGE=/dev/mapper/volumeGroup1-rootfs

 

that way the script works fine and outputs the correct values.

 

Related to question 3)

solved also according to question 2. I added the threshold 50 for the power-off retract count in the beginning for the script:

[...]

CPU_TEMP_OFFSET=0
HDD_TEMP_LIMIT=60
PWROFF_WARN=25

[...]

 

The variable and display command should look like that:

disk_pwroff_retract_count=$(smartctl -a $DISK | grep Power-Off_Retract | awk '{print $10}')

[...]

# display info

display "HDD PWRoff Retract Count" "$disk_pwroff_retract_count" $PWROFF_WARN "0" "times" "" ; a=$((a+$?))

[...]

 

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines