r_bash – Telegram
Script to Automatically Start a glassfish domain once it's down?

Steps to reproduce this issue:

1) Glassfish domain called domain1 goes down.

2) Now, start that domain again.

Algorithm like this should exist:

if(domain1 is down)

{
path/to/asadmin start-domain domain1
}

How do I check if domain1 is down or not?
Assume there are multiple domains, around 8 of them And different servers have varying amount of domains.

My pseudocode:

domainarray= get list of all domains in an array

for(i=0;i<domain
array.length;i++)

{
if(path/to/asadmin stop-domain domainarray[i]==0) //assuming exit code 0 returns if the domain is already stopped
{
path/to/asadmin start-domain domain
arrayi;
}
}

Problems with my code:

I might be attempting to stop an unstopped domain which is very bad.

Is there an equivalent of systemctl is-active servicename for glassfish domains?

Sources: https://glassfish.org/docs/5.1.0/administration-guide/domains.html#giurs

https://www.freedesktop.org/software/systemd/man/systemd.service.html

https://redd.it/15jl0cu
@r_bash
Script to send an alert mail once the disk space is above 90% sends disk full even when the disk isn't full, how to resolve this issue?

#!/bin/bash

df -m > myfile
server_ip_address=$(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1)

if awk '$2 > 10000 && $5 > 90' myfile ; then
echo "Disk Full in $server_ip_address"
else
echo "Nothing wrong with the server"
fi


When I execute the noscript, always get disk full as output?
Output of df -m looks like this:

Filesystem 1M-blocks Used Available Use% Mounted on
/dev/mapper/centos-root 949305 512827 436479 55% /
devtmpfs 3811 0 3811 0% /dev
tmpfs 3823 0 3823 0% /dev/abc
tmpfs 3823 18 3806 1% /run
tmpfs 3823 0 3823 0% /sys/fs/cgroup
/dev/sda2 1014 175 840 18% /boot
/dev/sda1 1022 12 1011 2% /boot/efi
tmpfs 765 0 765 0% /run/user/2000



The outut of df -m differs from server to server. I am thus comparing if Size>10GB and Use%>90%. As some disk with size<10GB may not be important to be under 90% disk usage.


**Update 1:**

GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)

OS is centos 7

Problem with the current code:

I need to compare the second row's columns, but my current code is comparing the first rows columns, that's why I suppose it's not working. How to resolve the issue?

https://redd.it/15jkztg
@r_bash
Script to send an alert mail once the disk space is above 90% sends disk full even when the disk isn't full, how to resolve this issue?

#!/bin/bash

df -m > myfile
server_ip_address=$(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1)

if awk '$2 > 10000 && $5 > 90' myfile ; then
echo "Disk Full in $server_ip_address"
else
echo "Nothing wrong with the server"
fi


When I execute the noscript, always get disk full as output?
Output of df -m looks like this:

Filesystem 1M-blocks Used Available Use% Mounted on
/dev/mapper/centos-root 949305 512827 436479 55% /
devtmpfs 3811 0 3811 0% /dev
tmpfs 3823 0 3823 0% /dev/abc
tmpfs 3823 18 3806 1% /run
tmpfs 3823 0 3823 0% /sys/fs/cgroup
/dev/sda2 1014 175 840 18% /boot
/dev/sda1 1022 12 1011 2% /boot/efi
tmpfs 765 0 765 0% /run/user/2000



The outut of df -m differs from server to server. I am thus comparing if Size>10GB and Use%>90%. As some disk with size<10GB may not be important to be under 90% disk usage.


**Update 1:**

GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)

OS is centos 7

Problem with the current code:

I need to compare the second row's columns, but my current code is comparing the first rows columns, that's why I suppose it's not working. How to resolve the issue?

https://redd.it/15jmqf4
@r_bash
Is there any dmenu alternative configured in Lua/YAML/JSON/TOML?

I need a such application launcher which supports such configuration file format there is an already existing LSP and linting for. For instance, I've found projektor launcher, but it seems it's dead, no recent commits exist.

It would be nice to have config in Lua format as I plan to use Awesome window manager which uses Lua for setup. But at the same time I love YAML for it's simplicity because not always I need rich customization capabilities.

https://redd.it/15jx9yn
@r_bash
I created a noscript to start or stop an Aria2 downloader daemon.

For those of you who aren't familiar, aria2 has over 30,000 stars on GitHub because of its usefulness to people who are looking for one of the best command line download softwares on the internet.

I have included info and instructions at the top of the noscript for the user to read.

I hope someone finds this useful!

Cheers!

Aria2 Repo

GitHub Script

https://redd.it/15k2q0q
@r_bash
awk Match everything between two patterns, but ignore the first occurrence of the end pattern

# Overview

I'm hacking old Chromeboxes to be digital signage for the school district I'm working at over the summer. The functional needs are working, but I discovered that the Chromeboxes can't drive 4K displays without a significant performance hit.

I'm modifying the runtime noscript to check for available resolutions below 4K (or QHD if the Chromebox is using two monitors, just to be safe), and pick the highest supported resolution that preserves the aspect ratio of the current resolution if possible. Yeah, it's a bit overengineered, but I'm not going to be there if something goes wrong, so I want to make this as functional as possible.

# Problem

To get available resolutions for each monitor (iterated in a for loop), I'm parsing xrandr -q, which outputs the list of available resolutions in a nice, indented list like this:

Screen 0: minimum 320 x 200, current 3280 x 1080, maximum 16384 x 16384
HDMI-1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 527mm x 296mm
1920x1080 60.00+ 50.00 59.94
1680x1050 59.88
1600x900 60.00
1280x1024 60.02
1440x900 59.90
1280x800 59.91
1280x720 60.00 50.00 59.94
1024x768 60.00
800x600 60.32
720x576 50.00
720x480 60.00 59.94
640x480 60.00 59.94
720x400 70.08
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-2 connected 1360x768+1920+0 (normal left inverted right x axis y axis) 410mm x 230mm
1360x768 60.02
+
1920x1080i 60.00 59.94
1280x720 60.00 59.94
1024x768 75.03 70.07 60.00
1440x480i 59.94
800x600 75.00 60.32
720x480 60.00 59.94
720x480i 60.00 59.94
640x480 75.00 60.00 59.94
720x400 70.08

The command I have written to parse this information is

DISPLAY=:0 xrandr | awk -v mon="$MONITOR" '$0 ~ mon, $0 !~ /^ /{print $1}'

I want awk to print everything between line with the monitor's name (eg, HDMI-1) and the end of the indentation block, excluding the headings themselves (some help on that would be cool as well). With MONITOR = "HDMI-1"

1920x1080
1680x1050
1600x900
1280x1024
1440x900
1280x800
1280x720
1024x768
800x600
720x576
720x480
640x480
720x400

However, this only returns

HDMI-1

I think I understand the issue. The line that matches the start pattern also matches the end pattern, so awk only prints that line and calls it a job well done. How do I tell awk to ignore the line with the start pattern and stop at the next line that matches the end pattern?

https://redd.it/15k3fjk
@r_bash
Should I learn python, ruby or perl for shell noscripting in Linux?


I just heard bash noscripting is inefficient thing to learn for shell noscripting in Linux in 2023. While being a stubborn fellow, I'd still learn bash. Which of python, perl or ruby should I learn for shell noscripting?
I'd go with anything that has tons of resources available specific to shell noscripting. I know a little bit of python already.

https://redd.it/15kat8x
@r_bash
if you had to recommend only 1 bash book which one would you recommend (except tldp)

My requirements:

I don't read books line by line. I learn by solvng exercises given in the book. The exercises given in the book should have a kind of hint in the earlier chapter about it. i.e in theory.


That's all my requirement. Please recommend me a book.

I want to learn bash shell noscripting as I decided that it's not optional to learn bash as a sysadmin.

bash noscripting is mostly about sed, awk commands mastery so recommend 1 book for them as well and word processing and regular expressions in general.

https://redd.it/15kia65
@r_bash
Is there any way to change the pipe buffer size of a single specific pipe using shell tools?

I have a bash function that more-or-less does the following:

#!/bin/bash

# setup anonymopus pipe and tmpdir
exec {fd_nOrder}<><(:)
baseDir=$(mktemp -d)

# fork a coproc to print output file names to anonymous pipe (same names that `split -d` uses)
# this basically does: printf '%s\n' {00..89} {9000..9899} {990000..998999} {99900000..99989999} ...
coproc pOrder (

local v0 v9

v9=''
v0=''

printf '%s\n' {00..09} {10..89} >&${fd_nOrder}

while true; do
v9="${v9}9"
v0="${v0}0"

source <(printf '%s\n' 'printf '"'"'%s\n'"'"' {'"${v9}"'00'"${v0}"'..'"${v9}"'89'"${v9}"'} >&'"${fd_nOrder}")
done
)

# set exit trap to cleanup
trap 'kill '"${pOrder_PID}"'; exec {fd_nOrder}>&-; rm -rf "${baseDir:?}"' EXIT

# run each element of array x through someFunction in a forked process
# save output to tmpfile whose base name it read from pipe {fd_nOrder}
for kk in ${!x[@]}; do
read -r -u ${fd_nOrder}
{
someFunction "${x[$kk]}" >"${baseDir}/x${REPLY}"
} &
done

# cat all the outputs saved to ${baseDir}
# outputs will be in the same order as inputs are in array x
cat ${baseDir}/x*

# WARNING: FORKING LOOP ITERATIONS IN THE WAY SHOWN ABOVE IS DANGEROUS!!!
# Depending on how many elements are in x and how complex someFunction is
# this could easily crash your system. My "real" code does not do this.


The idea behind the above code is that the file names that I will be using to safe each forked process's output will nicely sort in order, so that I can just `cat` them and they will be ordered the same way as the inputs (in array `x`) are ordered. These are the same filenames as `split` uses when using numeric suffixes (`split -d`). They start at 00 and go up to 89, then when you hit 90 you add `00` to the end (giving 9000), then go from 9000 - 9899, when you hit 9900 add `00` to the end again (giving 900000), and keep on repeating indefinitely.

The coproc `pOrder` generates these filenames using bash's builtin shell expansion of `{#...#}` and writes them to an anonymous pipe, which is read by the main process just before it forks that iteration's `someFunction` call. It will keep generating filenames until it fills up the `{fd_nOrder}` pipe's buffer (64 kb --> ~10000 filenames initially, less as the file names keep getting longer). This has the benefit of the filenames being buffered in the pipe (so there is no wait to read them) and of not adding any additional complexity/IPC to the code (to tell pOrder when it needs to generate more filenames), but 10000 filenames is *way* more than really need to be buffered, and wastes memory and cpu time on generating filenames that will never be used.

**Is there some way (using the tools available to a shell...i.e., not with C/C++) to modify the buffer size of just the `{fd_nOrder}` pipe down to, say, 1 kb (or even less)?**

I dont want to globally change the pipe buffer size, just the buffer size for that specific pipe. Using procfs and/or sysfs is fine, though Id prefer a way that doesnt require root privileges. Using tools that are "standard" is preferable too...id rather not add any additional unusual dependencies to the code.

Thanks in advance!

***

**ADDITIONAL NOTES**

Ill again note that I dont (and you shouldnt) fork things like shown above. But, what is above makes for a simple easy-to-understand example, whereas the "actual" way I do this is more efficient and is safer and is *considerably* more complicated, so...

If you are curious, the "real" code im using this for is [here](https://github.com/jkool702/forkrun/blob/main/mySplit_nLinesAuto_test.bash), which is a prototype for a new IPC method for my [forkrun
project](https://github.com/jkool702/forkrun/blob/main/forkrun.bash), which is (IMO) basically a better/faster version of `xargs` that parallelizes loops using (almost) pure bash.

Its also worth noting that I previously implemented this using a function that more or less did

getNextFileName() {

for nn in "${@}"; do
# OMITTED - SOMETHING TO DEAL WITH BASH TREATING 00-09 AS OCTALS
((nn++))
[[ ${nn} =~ ^9+0+$ ]] && nn="${nn}00"
echo ${nn}
done

}

fName='00'
for kk in ${!x[@]}; do
{
someFunction "${x[$kk]}" >"${baseDir}/x${fName}"
} &
fName="$(getNextFileName ${fName})"
done

This worked, but generating them in batches using bash's built-in expansion via `printf '%s\n' {#..#}` is *considerably* faster and more efficient.

https://redd.it/15kn6o7
@r_bash
What is the difference between :class: and [:class:]?

I can't find anything on the net or manual.

https://redd.it/15kupef
@r_bash
Small notification panel helper

After seeing another notification helper post in this sub, I felt the need to try creating one for myself. Here is the result, it uses terminal sequences to shorten the scroll area and reserve a couple of lines at the top for notification lines.

This has to be run using source. If anyone has a better idea on how to do it without source-ing, please do let me know.

I tried avoiding file-IO which is why we source and export instead. Also I am not a fan of tput, since its syntax is more foreign to me compared to regular VT-sequences.

The notification log is done in one printf line to hopefully atomically write it's output.

https://redd.it/15kx82h
@r_bash
WSL PATH Variable Appending Duplicates After Custom Command Execution

### FALSE ALARM ###

The issue is actually because some of my own code was appending to the PATH variable essentially the same way as:

export PATH="$PATH:$PATH:/the/path/i/want"

I only found this out because I saw the post "set -x is your friend" and used it.

Sorry for wasting your guys' time with this. I'll leave the post up in case anyone wants to read it (for some reason).

(Also, I keep pressing CTRL + S when trying to save this post. I'm not sure if I'm the only one doing that or not...)

### FALSE ALARM ###

I'm having an issue with my PATH variable in WSL.

I will mention right now, I make a ton of custom functions to help me get around the WSL environment. One is called "ref" which "refreshes" my environment. This function is running exec $SHELL, that way I can source any noscripts needed without closing WSL and opening it again. It might not be secure, but It's what I use.

I'm noticing that every time I use this, paths are being appended to my PATH variable that were already there before the refresh. Because of this, bash takes forever to autocomplete a command since it has to parse 50+ paths every time.

I've already looked inside the global file in /etc/bash.bashrc, but it doesn't even reference my PATH variable, and neither does \~/.bashrc. Because I couldn't find where something could be added, I added an echo at the beginning of my \~/.bashrc file and opened a new WSL session. This is what I got as the output:

/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/mnt/c/Program Files/Common Files/Oracle/Java/javapath
/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath
/mnt/c/Program Files/Microsoft/jdk-11.0.16.101-hotspot/bin
/mnt/c/Program Files (x86)/Common Files/Intel/Shared Libraries/redist/intel64/compiler
/mnt/c/Windows/system32
/mnt/c/Windows
/mnt/c/Windows/System32/Wbem
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/
/mnt/c/Windows/System32/OpenSSH/
/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common
/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR
/mnt/c/Program Files/dotnet/
/mnt/c/Program Files (x86)/Lua/5.1
/mnt/c/Program Files (x86)/Lua/5.1/clibs
/mnt/c/Program Files/PuTTY/
/mnt/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn/
/mnt/c/Program Files/Microsoft SQL Server/150/Tools/Binn/
/mnt/c/Users/%USER%/AppData/Local/Microsoft/WindowsApps
/mnt/c/Users/%USER%/AppData/Local/Programs/Microsoft VS Code/bin
/mnt/c/Users/%USER%/.dotnet/tools
/mnt/c/Users/%USER%/AppData/Local/GitHubDesktop/bin
/snap/bin
/home/%USER%/.dotnet/tools
/home/%USER%/bin
/usr/java/jdk-13.0.2/bin

This leads me to assume that bash is fetching the PATH variable from Windows and appending it to its PATH.

Does anyone know why bash is doing this and how I can fix it?

&#x200B;

&#x200B;

This is what my PATH looks like as of writing this:

/home/%USER%/.local/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/mnt/c/Program Files/Common Files/Oracle/Java/javapath
/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath
/mnt/c/Program Files/Microsoft/jdk-11.0.16.101-hotspot/bin
/mnt/c/Program Files (x86)/Common Files/Intel/Shared Libraries/redist/intel64/compiler
/mnt/c/Windows/system32
/mnt/c/Windows
/mnt/c/Windows/System32/Wbem
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/
/mnt/c/Windows/System32/OpenSSH/
/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common
/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR
/mnt/c/Program Files/dotnet/
/mnt/c/Program Files (x86)/Lua/5.1
/mnt/c/Program Files (x86)/Lua/5.1/clibs
/mnt/c/Program Files/PuTTY/
/mnt/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn/
/mnt/c/Program Files/Microsoft SQL
Server/150/Tools/Binn/
/mnt/c/Users/%USER%/AppData/Local/Microsoft/WindowsApps
/mnt/c/Users/%USER%/AppData/Local/Programs/Microsoft VS Code/bin
/mnt/c/Users/%USER%/.dotnet/tools
/mnt/c/Users/%USER%/AppData/Local/GitHubDesktop/bin
/snap/bin
/home/%USER%/.dotnet/tools
/home/%USER%/bin
/usr/java/jdk-13.0.2/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/mnt/c/Program Files/Common Files/Oracle/Java/javapath
/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath
/mnt/c/Program Files/Microsoft/jdk-11.0.16.101-hotspot/bin
/mnt/c/Program Files (x86)/Common Files/Intel/Shared Libraries/redist/intel64/compiler
/mnt/c/Windows/system32
/mnt/c/Windows
/mnt/c/Windows/System32/Wbem
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/
/mnt/c/Windows/System32/OpenSSH/
/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common
/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR
/mnt/c/Program Files/dotnet/
/mnt/c/Program Files (x86)/Lua/5.1
/mnt/c/Program Files (x86)/Lua/5.1/clibs
/mnt/c/Program Files/PuTTY/
/mnt/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn/
/mnt/c/Program Files/Microsoft SQL Server/150/Tools/Binn/
/mnt/c/Users/%USER%/AppData/Local/Microsoft/WindowsApps
/mnt/c/Users/%USER%/AppData/Local/Programs/Microsoft VS Code/bin
/mnt/c/Users/%USER%/.dotnet/tools
/mnt/c/Users/%USER%/AppData/Local/GitHubDesktop/bin
/snap/bin
/home/%USER%/.dotnet/tools
/home/%USER%/bin
/usr/java/jdk-13.0.2/bin
/mnt/f/.BACKUPS/.LOADER/bin
/home/%USER%/.local/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/mnt/c/Program Files/Common Files/Oracle/Java/javapath
/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath
/mnt/c/Program Files/Microsoft/jdk-11.0.16.101-hotspot/bin
/mnt/c/Program Files (x86)/Common Files/Intel/Shared Libraries/redist/intel64/compiler
/mnt/c/Windows/system32
/mnt/c/Windows
/mnt/c/Windows/System32/Wbem
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/
/mnt/c/Windows/System32/OpenSSH/
/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common
/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR
/mnt/c/Program Files/dotnet/
/mnt/c/Program Files (x86)/Lua/5.1
/mnt/c/Program Files (x86)/Lua/5.1/clibs
/mnt/c/Program Files/PuTTY/
/mnt/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn/
/mnt/c/Program Files/Microsoft SQL Server/150/Tools/Binn/
/mnt/c/Users/%USER%/AppData/Local/Microsoft/WindowsApps
/mnt/c/Users/%USER%/AppData/Local/Programs/Microsoft VS Code/bin
/mnt/c/Users/%USER%/.dotnet/tools
/mnt/c/Users/%USER%/AppData/Local/GitHubDesktop/bin
/snap/bin
/home/%USER%/.dotnet/tools
/home/%USER%/bin
/usr/java/jdk-13.0.2/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/mnt/c/Program Files/Common Files/Oracle/Java/javapath
/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath
/mnt/c/Program Files/Microsoft/jdk-11.0.16.101-hotspot/bin
/mnt/c/Program Files (x86)/Common Files/Intel/Shared Libraries/redist/intel64/compiler
/mnt/c/Windows/system32
/mnt/c/Windows
/mnt/c/Windows/System32/Wbem
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/
/mnt/c/Windows/System32/OpenSSH/
/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common
/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR
/mnt/c/Program Files/dotnet/
/mnt/c/Program Files (x86)/Lua/5.1
/mnt/c/Program Files (x86)/Lua/5.1/clibs
/mnt/c/Program Files/PuTTY/
/mnt/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn/
/mnt/c/Program Files/Microsoft SQL Server/150/Tools/Binn/
/mnt/c/Users/%USER%/AppData/Local/Microsoft/WindowsApps
/mnt/c/Users/%USER%/AppData/Local/Programs/Microsoft VS
Code/bin
/mnt/c/Users/%USER%/.dotnet/tools
/mnt/c/Users/%USER%/AppData/Local/GitHubDesktop/bin
/snap/bin
/home/%USER%/.dotnet/tools
/home/%USER%/bin
/usr/java/jdk-13.0.2/bin
/mnt/f/.BACKUPS/.LOADER/bin
/mnt/f/.BACKUPS/.LOADER/bin

&#x200B;

https://redd.it/15kux9r
@r_bash
How do I select my entire command line using the keyboard? In Windows it is ctrl + A

I'm trying to highlight my command line prompt

$ cat "Random command"

In Windows, I could press ctrl + A and that would select my cat "Random command" but in Bash ctrl + A, just moves my cursor to the front of the line.

I tried shift + Home but it just scrolls the terminal history to the top of the page.

https://redd.it/15l23h5
@r_bash
What happens if you just type expand with no file input?

Sorry for the basic question but it was on https://linuxjourney.com/lesson/expand-unexpand-command.

I couldn't figure out the purpose of not having a file input. It repeats what I'm entering but even if the command was converting TABs to spaces, I wasn't sure what the point would be and I'm sure there is a use case.

It doesn't even expand my variables, $city="Phoenix" doesn't do anything but repeat the input.

https://redd.it/15l8c7f
@r_bash
How do I write a bash noscript to escape html inside a json string?

- I am trying to upload templates to Amazon SES to send html emails
- As per their documentation here they want you to upload a json file that contains html text inside a string

I wrote a cli command like this

aws ses create-template --cli-input-json file://./wiki/email-templates/ses/confirm-email.json


My main problem is with the json file itself
Given an input html file and a text file, I want to generate that json on the fly and send it aws cli
{
"Template": {
"TemplateName": "MyTemplate",
"SubjectPart": "Greetings, {{name}}!",
"HtmlPart": "WHAT TO WRITE IN BASH HERE??? to take HTML file and generate a string out of it that is valid as per JSON rules",
"TextPart": "text file to string HERE...."
}
}

Super appreciate if someone can give me directions on this. I don't even know if my approach is correct

https://redd.it/15lcr07
@r_bash
How to move #n from the end of files name to the beginning?

I used linux before, so I know that this could be done with bash command probably.
I have a folder on my phone that has a 40 mp4 files with different names but each on of them ends with #n (#1,#2...etc)
I want to put this #n at the beginning of each file name so I can add them to a playlist on vlc as vlc doesn't support sorting by date
I will do this using termux.
And thanks in advance.

https://redd.it/15lgr8f
@r_bash
Why $(( 015 )) calculate as octal?

echo $(( 015 )) yeilds 13. Why and how to change this behavior?

https://redd.it/15lm0ev
@r_bash