r_bash – Telegram
Linux Shell question

Hi, I'm currently taking an OS class where we're learning how to work in the Linux shell on a virtual machine and am struggling with finding the log file created by the noscript command. The HW is basically just us creating and removing files for practice, then submitting the log file to prove we did it. I have no issues following the file manipulation instructions... but I can't find the log file. I enter in the noscript command, follow the instructions, type exit and.... I have no idea how to find the log file to turn in? I don't know where it's at on my computer, or if I even am creating files on my computer. When I do the ls -l command, the files I've created all get listed.

​

I'm running the shell on Oracle VM VirtualBox Manager. I downloaded this and the shell from here: http://cs.westminstercollege.edu/\~greg/osc10e/vm/index.html

​

Sorry for asking such a stupid and basic question. I just started this class and am already so lost lol.

https://redd.it/10sxvn5
@r_bash
How do I prevent my noscript from executing sudo?

I've got a noscript that runs noscripts from other files using "sh some-file.txt". I don't want to block my whole noscript if "some-file.txt" contains "sudo" or some input request. How can I prevent that?

I would like "sh some-file.txt" to just fail if sudo is requested. Is it possible? I spent several hours trying to achieve that with no luck :(

https://redd.it/10t1djf
@r_bash
how to get url from text, or why 'grep -o http' doesnt work

i have text

something:
https://url.domain/sub somemoretext

how to get this url using tools like grep/awk etc.?

i tried grep -o http\
but it didnt work, but seemd to be great idea

result must be: `https://url.domain/sub`

​

solve: use quotes... grep -o 'http.* '

https://redd.it/10td8li
@r_bash
Sed can do amazing things!

I've wrote my renders for TlDr-like project (named Command Line Interface Pages or CLIP), but more standardized. They are written in Bash + Sed + Awk. It was more a challenge, but to be honest I use what I've written as I feel it's more convenient than TlDr clients and more flexible. To view sed command examples (from `common/` directory) just write the following command:

clip-view -r tldr-colorful sed

Currently 4 renders available but the 5th and the most complicated will be finished soon. Command output looks like this:

https://preview.redd.it/6sakva70w6ga1.png?width=1920&format=png&auto=webp&v=enabled&s=b26167ee623a0061fa88b152196c5aef7019c70f

Requested pages are automatically cached to speed up example's loading time.


This command will be packaged as .deb package soon. ;) Stay tuned.

https://redd.it/10tiw1t
@r_bash
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