r_bash – Telegram
AWK noscript to generate Entity Relationship diagrams

Hello, everyone!

I wrote a small AWK noscript that generates ER diagrams for the SAP CAP model: https://github.com/rabestro/sap-cds-erd-mermaid/

Although this is a tiny and simple noscript, it managed to generate mermaid diagrams for the entities of our project. It does not support all the features in the CDS format. In any case, this noscript can be improved, and it may be helpful to someone.

https://redd.it/10tln0k
@r_bash
noscripts for sys admins!

Made quite a few noscripts for server management. These are all in production use for my TrueNas home lab. Thought id create a repo and share. There's also a noscript for updating a Minecraft server and starting it up again but I have yet to add it. For all the home labbers of the bash community https://github.com/Agb43/server-admin-noscripts.git

https://redd.it/10tqd5i
@r_bash
I get errors in if statement "[: : integer expression expected"

I'm trying to write simple code that notifies me when battery is low. Here's my code

#!/bin/bash

# maximal energy in battery
enf0=$(cat /sys/class/power_supply/BAT0/energy_full)

# notify at these levels
btlow=30
bthigh=90

# check every n seconds
time=30

while [ 1 ]
do

# current energy, charging/discharging, energy level in %
enc=$(cat /sys/class/power_supply/BAT0/energy_now) ;
state=$(cat /sys/class/power_supply/BAT0/status) ;
lvl=$(echo "scale=2; $enc * 100 / $enf" | bc) ;

if [ $lvl -lt $btlow ] && [ "$state" == 'Discharging' ]
then
notify-send "Low battery" "Battery level: $lvl%"
fi

sleep $time

done

but when I run it I get error `line 25: [: -lt: unary operator expected`, I read [this](https://stackoverflow.com/questions/50349389/shell-noscript-lt-unary-operator-expected) but when I change this line to `if [ "$lvl" -lt "$btlow" ] && [ "$state" == 'Discharging' ]` then I get different error `line 25: [: : integer expression expected`

https://redd.it/10trm1l
@r_bash
cp: no such file or directory

Hi all,

I'm using FreeBSD and trying to migrate my jails from iocage to bastille. Really not familiar with bash so figured I would try and noscript it rather than do it manually as a learning exercise.

On the cp command below I get the error:

cp: /tank/iocage/images/db_2023-02-05.*: No such file or directory

Here is the full noscript. I would appreciate any help.

​

#!/usr/bin/bash

jails=$(/usr/local/bin/iocage list -qh | awk '{print $1}')
today=`date "+%Y-%m-%d"`

for jail in ${jails[@]}; do
filename=$jail
filename+="_"
filename+="$today"

iocage stop $jail
iocage export $jail
iocage set boot=0 $jail
cp "/tank/iocage/images/$filename.*" /usr/local/bastille/backups/
bastille import "$filename.zip"
done

https://redd.it/10u8qgq
@r_bash
I keep getting this error bash: venv/bin/activate: No such file or directory

Following this here on my Git Bash:

https://github.com/openai/openai-quickstart-python

I am at Step 4 where I input:

$ python -m venv venv

Nothing happens. When I type this, the error message in the noscript:

$ . venv/bin/activate

I tried following this guidance, but still no luck.

https://github.com/addok/addok/issues/553

What am I doing wrong here?

https://redd.it/10uh74p
@r_bash
A bash noscript that takes all the files inside a folder recursively and then create a csv with the filenames and two columns called typenoscript and javanoscript and checkmark them depending on their extension js or tsx?

A bash noscript that takes all the files inside a folder recursively and then create a csv with the filenames and two columns called typenoscript and javanoscript and checkmark them depending on their extension js or tsx?

https://redd.it/10uwro2
@r_bash
Should Ulfnic stop using UpperCamel?

Asking for opinions if I should drop UpperCamel for snake_case.

If writing BASH was just about serving myself or following the herd i'd have my answer but here we are... feeling lucky I have people I can ask.

Harsh criticism greatly appreciated.

### Context

I want to start contributing my projects to the BASH ecosystem.

- I'd like my noscripts to useful for learning.
- I'd like people to be able to take pieces of my noscripts for their own projects or use them as a whole.
- Some are source-able meaning some syntax will mix into other people's noscripts (function calls/variable assignment).
- It'll be part of my resume so it'll affect my hire-ability. To what degree i'm not sure as BASH tends be treated as a supplementary language and i'm pretty flexible.

### UpperCamel vs snake_case

Why I think UpperCamel is better:

- It doesn't tread on filename or ENVIRONMENT namespace for both single and multi-word names (with very rare exceptions).
- It doesn't tread on "normal" BASH syntax like snake_case if sourced by someone else reducing likelihood of error and annoyance.
- It makes variables and functions stand out as they don't look like executables.
- Denoscriptive names are shorter because they don't need readability separators.
- Generally easier on people newer to BASH because of the above (imho, mileage may vary).

Why I think snake_case is better:

- It's used by the vast majority of BASH devs so syntax doesn't need to be re-written if code's being merged with other projects reducing likelihood of error and annoyance.
- It doesn't tread on ENVIRONMENT namespace.
- It mostly doesn't tread on multi-word filename namespace

Not sure:

- UpperCamel is easier? harder? for people to read who've only been exposed to snake_case/UPPERCASE BASH.

Thank you for your feedback,

https://redd.it/10v3ol4
@r_bash
Why the second loop is not getting executed in the shell?

n=1

while (( $n <= 10 ))
do
echo "$n"
((n++))
sleep 0.5
done

echo

while (( $n <= 10 ))
do
echo "$n"
((++n))
sleep 0.5
done

#

https://redd.it/10v3ndv
@r_bash
Solution to log bash history

Hello,

I'm currently in need of session logs with timestamp and additional metadata from a bash session Input and Output of commands run in bash terminal but currently i found that "tmux logging" logs only a screen of the pane and can't be manipulated very efficiently, i also tried implementing "tlog" but apparently it only works on centOS

Any idea on how to implement such a solution?
in the end i need to have a json file with the input, output, path, user and some other data
thank you !

https://redd.it/10v6hv3
@r_bash
How to run a background noscript when a user logs in?

I have a bash noscript I need to run in the background on macOS. I want it to launch automatically when a user logs in. I tried all approaches that I could find and nothing worked as expected.

The closest solution was a LaunchDaemon. However, I need my noscript to be located and to have access to "\~/Downloads" and LaunchDaemon is unable to do that :(. If you try to run a noscript from "\~/Downloads" it will fail with 126 or 129 error (I don't remember). If you put it somewhere else and try to access "\~/Downloads" it will fail.

I also tried to create an Automator app and add it to "Login Items", but it looks like it starts my noscript and kills it immediately, I don't see it running in the background. My noscript is launching `fswatch` and observes a file all the time.

I even tried adding my noscript using `crontab -e` with "@reboot /my\_noscript", but it doesn't work either. It looks like it doesn't launch at all.

Any ideas? My main requirements are:

* operating system: macOS Ventura or lower
* the noscript will be running in the background after each login
* the noscript is located in "\~/Downloads"
* the noscript has access to "\~/Downloads"
* the noscript has access to packages installed via Homebrew for the current user

https://redd.it/10vc5gw
@r_bash
How do I synchronize threads?

These ideas didn't work

#!/bin/bash

stop=0
# (for ((i=0 ; i<10 ; i++)) ; do echo $i"/10" ; sleep $i ; done ; stop=1 ; echo stop="$stop" ) & # Doesn't work
# for ((i=0 ; i<10 ; i++)) ; do echo $i"/10" ; sleep $i ; done ; (( stop++ )) ; echo stop="$stop" & # Doesn't work
for ((i=0 ; i<10 ; i++)) ; do echo $i"/10" ; sleep $i ; done && stop=1 && echo stop="$stop" & # Doesn't work

echo waiting
while (( stop==0 )) ; do echo "Waits stop=$stop" ; sleep 5 ; done
echo Done :\)

https://redd.it/10vjmla
@r_bash
Is there a repository with snippets to manipulate csv data and create them from the data inside the file system (folders and folder content and file extensions)?

Just trying to write some useful noscript for internal tracking for myself to get better at bash, because the Udemy tutorials I watch goes from one ear and goes out to the other.

https://redd.it/10vl9z9
@r_bash
Minimal setup for shellcheck as a compiler in Vim for linting bash noscripts.

Hello.

This is the most minimal setup I wanted, because I don't have time to fiddle with this, and I have a setup for quickfix lists, with keyboard shortcuts I remember.

I run 9.0, but there is only 8.x code in the files.

So, I have an sh.vim that I have dropped in `~/.vim/ftplugin` it`s below:

" Vim-licence (c) 2023 McUsr
" Miniscule shellcheck setup
" you :copen the quick fix list however you open the quickfix list!
compiler shellcheck

nnoremap <buffer> <F9> :silent exe "make %:p" <bar> redraw!<CR>


And then there is the sh.vim file in the `~/.vim/compiler` folder file below:

" Vim-licence (c) 2023 McUsr
" Miniscule shellcheck setup
" you :copen the quick fix list however you open the quickfix list!
"
if exists("current_compiler")
finish
endif
let current_compiler = "shellcheck"

CompilerSet makeprg=shellcheck\ -f\ gcc\ \"%:p\"
CompilerSet errorformat=
\ '%f:%l:%c: %trror: %m,' .
\ '%f:%l:%c: %tarning: %m,' .
\ '%I%f:%l:%c: note: %m'


And that is pretty much all there is to it, after I dropped the files in their respective folders I now hit F9 to lint a shellnoscript in the active window.
I hit `\co` to open the `quick fix list`, and then I can jump to the error messages.
FYI. I nicked the format string and the reload-guard from [here](https://github.com/itspriddle/vim-shellcheck).

Enjoy, if you aren't set up already.

https://redd.it/10vmjcp
@r_bash
why from a function in .zshrc i can't process files in another folder ?

I have a noscript that use [Swaks](https://www.jetmore.org/john/code/swaks/) i try to be able to run it from a simple command in my terminal without having to go to the right folder and from their open terminal and run the noscript.

cd .noscript
cd swaks
sh email.sh

I made this function in my .ZSHRC

&#x200B;

function email {
zsh $HOME/.noscripts/SWAKS/email.sh
}

Program run, but the program doesn't process the file **mod.html**

&#x200B;

&#x200B;

#!/bin/bash
# encoding: UTF-8

while true; do
echo "give email adress"
read -r email
echo "PRICE:"
read -r prix


email_regex="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"


if [[ $email =~ $email_regex ]]; then
cp template.html mod.html
echo "Adresse email valid."

if [ -z "$prix" ]; then
sd ppprice " " mod.html
else
declare -i prix
if [[ "$prix" -gt 350 && "$prix" -lt 1500 ]]; then
sd ppprice "the price of this is $prix&euro;" mod.html
else
clear
echo "PRIX INCORECT POUR UNE VENTE";
rm mod.html;
exit 1
fi
fi
else
clear
echo "bad email";
exit 1
fi

swaks --body @mod.html -t "$email" --add-header "MIME:Version 1.0" --add-header "Content-Type: text/html" --h-Subject "buy my product" --h-From: '" my name" <xxxxx@gmail.com>' -s smtp.gmail.com:587 -tls -au xxxxxx@gmail.com -ap ejixxxxxxxlelinp -f xxxxxxx@gmail.com --tls-protocol tlsv1_3
clear
rm mod.html;
done

&#x200B;

https://preview.redd.it/8zjt7qg6tnga1.png?width=315&format=png&auto=webp&v=enabled&s=dcfda9f7d80e13e2068e1fa6dbe69007bce7980c

https://redd.it/10vmzpj
@r_bash
oh ..what a so many variety of 'output' bash noscript have to have?

i know there's visible output in the terminal and there some others are hidden while doing it's process.

my goal 'straight question' is : i need to export whatever is the bash noscript is writing to a text file , what ever kind of out put is happening 'or not' i want it to be exported to a text file, then after use same noscript again it creates A NEW text file to save those logs OR in same old text file but without wiping the old logs , well ..should i study those standard outputs or someone just tell me how things going ?

what sort of syntax should i add to the noscript to save whatever output happened and write it to specific text file into specific directory ? if someone have time explain to me please . that was my real question for real people .

,if my question doesn't seems cool to you, hold on please don't rush to be a reason for infection of the downvote button syndrome here the question you will like bro. what types of bash outputs and how to manage which is to write and be visible and which to hide if needed 'in case those outputs not needed' thanks in advance .

https://redd.it/10vr5gk
@r_bash