LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   HowTo open a terminal for output in Debian11 Gnome? (https://www.linuxquestions.org/questions/linux-newbie-8/howto-open-a-terminal-for-output-in-debian11-gnome-4175736482/)

floppy_stuttgart 04-27-2024 12:34 PM

HowTo open a terminal for output in Debian11 Gnome?
 
1 Attachment(s)
Hello,

I created an icon on my gnome desktop which start the script below: showing the RAM usage.
So far after clicking the icon, a window open but there is a message coming up: I have to click 3x time on "restart" = "Erneut starten" before I could see the message "RAM usage..". (see attachment) because it is probably hidden behind the message "Der Kindprozess..".

Any proposal HowTo delete this message "Der Kindprozess.." is welcome.

Code:

#! /bin/bash
THRESHOLD=5  # Set your desired threshold percentage
# https://www.inmotionhosting.com/support/server/linux/check-memory-usage/
RAM=$(free | awk '/Speicher/{printf("%.2f"), $3/$2*100}')
if [ $(echo "$RAM > $THRESHOLD" | bc) -eq 1 ]; then
    gnome-terminal --window-with-profile=RAM --command "echo 'RAM usage is above $THRESHOLD% - Current usage: $RAM%'" --geometry=50x10
fi


michaelk 04-27-2024 02:29 PM

I would just use Terminal=True in my desktop shortcut and then instead starting another terminal I would use:
Quote:

echo "RAM usage is above $THRESHOLD% - Current usage: $RAM%"
read -p "Press enter to exit ..."
Granted you get the default window size.

However, to fix your problem:
Code:

gnome-terminal --geometry=50x10  -- bash -c "echo 'RAM usage is above $THRESHOLD% - Current usage: $RAM%'; exec bash"

floppy_stuttgart 04-28-2024 05:20 AM

Outstanding proposal.
My last improved version is below:
- click on an icon on the gnome desktop (which execute this script; .desktop file in the bottom of the message),
- a window pop up,
- it stay open for 30s,
- then it goes alone away (no need to close or further act).

executable script check_ram.sh
Quote:

#! /bin/bash
THRESHOLD=5 # Set your desired threshold percentage
# https://www.inmotionhosting.com/supp...-memory-usage/
RAM=$(free | awk '/Speicher/{printf("%.2f"), $3/$2*100}')
if [ $(echo "$RAM > $THRESHOLD" | bc) -eq 1 ]; then
gnome-terminal --geometry=50x10 -- bash -c "echo 'RAM usage is above $THRESHOLD% - Current usage: $RAM%'; sleep 30; exit; exec bash"
fi
file RAM.desktop in /home/userX/Schreibtisch
Quote:

[Desktop Entry]
Name=RAM check
Comment=this is an icon for checking the RAM use
Exec=bash /home/userX/pc_issues/RAM/check_ram.sh
Type=Application
Terminal=false
Icon=/home/userX/pc_issues/RAM/ram.jpeg

UPDATE (added: indication of the used swap in a new line)

Quote:

#! /bin/bash
THRESHOLD=5 # Set your desired threshold percentage
RAM=$(free | awk '/Speicher/{printf("%.1f"), $3/$2*100}')
SWAP=$(free | awk '/Speicher/{printf("%.0f"), $8}')
if [ $(echo "$RAM > $THRESHOLD" | bc) -eq 1 ]; then
gnome-terminal --geometry=63x5 -- bash -c "echo 'RAM usage is above $THRESHOLD% - Current usage: $RAM%' ; printf %b '\n' ; echo 'SWAP used: $SWAP'; sleep 15; exit; exec bash"
fi


All times are GMT -5. The time now is 06:52 PM.