Save yourself with commonly used commands using choice.sh (Debian)

EricRP

Member
Joined
Feb 23, 2021
Messages
31
Reaction score
16
Credits
294
using bold font the file I called choice.sh and put in /usr/local/bin folder (with Debian12)

============ start of choice.sh file ===================

title="Select example"
prompt="choice.sh ..... Pick an option by number or 6 to Quit, nothing to display option list:"
options=("1 = check memory usage" "2 = clear swap memory" "3 = release Memory" "4 = check for updates with list" "5 = update " )
echo "$title"
PS3="$prompt "
select opt in "${options[@]}" "Quit"; do
case "$REPLY" in

1) free; date "+%T" ;;
2) sudo dphys-swapfile swapoff ; sudo dphys-swapfile swapon ; free ;;
3) free ; echo 1 | sudo tee /proc/sys/vm/drop_caches; free ;;
4) sudo apt update && apt list --upgradable -a ;;
5) sudo apt dist-upgrade ;;

$((${#options[@]}+1))) echo "Goodbye! "; break;;
*) echo "Invalid option. Try another one.";continue;;
esac
done




============ end of choice.sh file ==============

It prints out on the screen.
Select example
1) 1 = check memory usage 3) 3 = release Memory 5) 5 = update
2) 2 = clear swap memory 4) 4 = check for updates with list 6) Quit

choice.sh ..... Pick an option by number or 6 to Quit, nothing to display option list:

This "hobby" of checking the swap memory started many months ago, when the whole system used to "lock up", the only thing I could do was to press the system reset button and reboot the system. Now by using the sudo dphys-swapfile swapoff ; sudo dphys-swapfile swapon I hardly get any system lock ups.

This choice.sh saves me using the "up arrow" on the keyboard looking for the most commonly commands I use, like if there is a system update. with "sudo apt update" in the 4) line then if there is a update it gives the list, before to use option 5) to update the system with apt list --upgradable -a

I make the changes using Mousepad text editor in a file called makesh.txt
then go to my command line terminal logged on as "root" user and do cp makesh.txt choice.sh to make the choice.sh file
and also do cp makesh.txt choice.txt to backup a copy of the last changes I made to choice.sh file



I hope you get something out of it, You could even change the 1) 2) 3) 4) 5) options even add on some more, I have not tried 10) yet as a option. My next move is to learn more about BASH files and hopefully might be able to add a bit of color to the menu (Option List)
 
Last edited:


Thanks for the script. I wasn't familiar with the dphys-swapfile command, so that was of interest apart from the interest in the rest of the script.

The following thoughts occurred.

Running a script with numerous sudo invocations has a few disadvantages compared to simply running the whole script as sudo. In other words, invoking sudo once to run the script will accomplish the same outcome with fewer vulnerabilities.

Briefly, sudos sprinkled throughout the script technically opens it more greatly to privilege escalations getting root access beyond the intended scope of the script. I'll leave that for the interested reader to investigate. Basically, all the sudos could be removed and a single sudo used to invoke the whole script. That may also alleviate the need to make extra configurations for the sudo command.

In relation to the script details, there's an error output when running it referencing the last line. When that line is deleted, the error report disappears.

In relation to the free command output, you might consider the more human readable output using -h option. For example, the comparison can be shown thus on a machine here:
Code:
$ free
               total        used        free      shared  buff/cache   available
Mem:        16009316     2101772    13123244       84684     1165784    13907544
Swap:       15625212           0    15625212
 
$ free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi       2.0Gi        12Gi        82Mi       1.1Gi        13Gi
Swap:           14Gi          0B        14Gi
 
Last edited:
Thank you osprey for your kind information,
I must give it a whirl,
after all what does it matter if you see 12 Gi or 13123244 not like I need to see it right up to the last ± byte.

 
Perhaps the title should reflect that this script only works on debian based systems.
 
OK dos2unix I have taken you advice and added it to the title,

By the way, So far I found that color only seems to work with the echo command like
RED="\e[91m"
bold="\e[1m"
reset="\e[0m"

echo -e "${RED}${bold}Red text${reset}"

But it looks like I still need to read a good book on BASH theory.
Edit Forgot to include ${bold}
 
I like the idea: if it's really about the memory lockup, i would recommend just aliasing that command and running (you can make it really short, like "ds"). I never thought about having a command menu like that before.
 
Last edited:
I have added "Virtual Keyboard" to the list on my choice.sh , this is great, for later in the evening, not having bright lights going so you can see the keyboard just before going to bed, there is just one problem, I normally have my task bar or should I say "Menu Bar" at the bottom of the screen, when you bring up the Virtual Keyboard, it covers up the menu bar making the Menu Bar unusable while the Virtual Keyboard is hiding it. I did try looking for the configuration file so I could have the Virtual Keyboard at the top of the screen but could not find information on Internet, It seems strange the operating system for the the Raspberry Pi does not include a virtual keyboard instead of what I think are "silly" games that I uninstall.
One just needs to add in the wvkbd-mobintl ;; to the choice.sh menu. The trouble when you add in another option in the middle of the list you have to relearn the changes to the menu. Having part of the shell program changing a word to a number might be a good fix, so instead of putting in say 9 to exit the program you put in "exit" and the shell changes it 9.


I was considering buying a keyboard that lights up (seems to be called "Gaming Keyboard") but that is a much more expensive option. So I never went with it, this idea started after I got a Raspberry Pi zero to make a project, and the board only has one USB outlet, since I do not have a WiFi mouse or WiFi keyboard I had to buy a USB splitter unit,
 
I was considering buying a keyboard that lights up (seems to be called "Gaming Keyboard") but that is a much more expensive option.

They're sometimes called 'RGB keyboards' or 'backlit keyboards'. I do not know your budget, but you can buy a tolerable backlit keyboard for under $30. It'll be a membrane keyboard instead of a mechanical keyboard, but mechanical keyboards are coming down in price and you might find one on sale.
 
RGB keyboard that is also mechanical is the best keyboard one can have.

Have you seen the keyboard fanatics who spend hundreds of dollars on a mechanical keyboard? Not just a hundred dollars, but multiples of that. There was one keyboard that sold for $300, and people would take it apart just to get the keyboard bits to put those bits into very expensive cases. There are people in that community who have spent thousands of dollars on keyboards.

They'll even do things such as taking the individual keys apart to apply a special grease - sometimes two different ones, one for the plunger bit and the other for the stability (which they call stabs) bits of the mechanical bits.

I wear out keyboards pretty quickly, so I stick to cheaper keyboards. I do have a few that are more expensive but most of my keyboards were less than $40. This keyboard that I'm using right now was maybe $30 and they call it 'mechanical membrane' - which just means they've taken a membrane keyboard and made it feel like a cheaper mechanical keyboard and made sure that it is 'clicky'.

If @EricRP is up to buying a backlit keyboard, they can be found dirt cheap on sites like Temu or AliExpress. They're the same keyboards you'd find at Walmart or Amazon, just less expensive and take a while to get delivered.
 
"3 = release Memory"

Code:
GRUB_CMDLINE_LINUX_DEFAULT=transparent_hugepage=never

makes the quoted line unnecessary and obsolete bc memory release happens the moment you close the process that hogs it.
 
Code:
GRUB_CMDLINE_LINUX_DEFAULT=transparent_hugepage=never

makes the quoted line unnecessary and obsolete bc memory release happens the moment you close the process that hogs it.
WELL it worked for me. the mouse was getting unresponsive, Almost the time to force reboot because I could not do anything else on my Raspberry Pi, Went for the 3 on my Choice.sh I keep open all the time, and it business as normal.

I just do not know why I get out of bed everyday, everything goes wrong, everything is broken, nobody wants to fix anything, and just have I moan all the time
 


Follow Linux.org

Staff online

Members online


Top