r_bash – Telegram
Did anyone encounter that problem?

I tried to install ubuntu on my laptop. even though I have 53 Giga free space the installation insisted that I only have 11G and that's not enough

​

https://redd.it/1beoijw
@r_bash
Trouble parsing line when using read command in a noscript.

The trouble I am having is that every second line read of the text file doesn't capture the entire line of text. It is missing the beginning characters of the line. It's not always the same number of characters, either. I have checked the text file and the file names are complete. Any ideas as to what is happening here?

#!/bin/bash -x

ls *.h264 > list.txt

while read line; do
filename=${line:0:15}
ffmpeg -i $line -vf format=gray $filename'-%03d.png'
done < list.txt

&#x200B;

https://redd.it/1bf0g0i
@r_bash
TIL: quickly fetch a file from a squashfs embedded into some iso

This method does not mount anything (no root, no fuse, no udisksctl) and does not extract the whole squash from the iso.

For example, let it be `ubuntu-20.04.6-live-server-amd64.iso`. The squash inside is `/casper/filesystem.squashfs`, and the file in the squash is `/etc/lsb-release`.

First, find out the offset of the squash with `xorriso` (the `Startlba` column):

> xorriso -indev ubuntu-20.04.6-live-server-amd64.iso -find /casper/filesystem.squashfs -exec report_lba 2>/dev/null
Report layout: xt , Startlba , Blocks , Filesize , ISO image path
File data lba: 0 , 128364 , 218124 , 446717952 , '/casper/filesystem.squashfs'

or `isoinfo` (in the square brackets):

> isoinfo -R -l -i ubuntu-20.04.6-live-server-amd64.iso | grep filesystem.squashfs
-r--r--r-- 1 0 0 446717952 Mar 14 2023 [ 128364 00] filesystem.squashfs
-r--r--r-- 1 0 0 833 Mar 14 2023 [ 97913 00] filesystem.squashfs.gpg

In both cases you can see it is `128364` blocks. Block size for iso9660 is 2048 bytes.

Now just use the offset with `unsquashfs`/`sqfscat`:

> sqfscat -o $((128364*2048)) ubuntu-20.04.6-live-server-amd64.iso /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"

https://redd.it/1bf1f35
@r_bash
Ok so... I'm having some problems with finding lines of texts and their numbers

Basically I'm writting a noscript for tmux that allows you to select a command and copy the output to the clipboard.


Tmux has a command that allows you to dump all of the text inside a pane (for those who don't use tmux, I have access to the equivalent of a history file with the commands and their outputs, basically everything that the terminal displays). My idea is more or less this.


Get tmux history file -> Prepend a number to every line -> Find the lines that contain $ps1 -> Put them through dmenu -> print whatever is under that line until the next command or the end of the file


(btw, if I'm grepping ❯ instead of $ps1 it's bc I'm using powerlevel10k and... well, it's weird)

I'm struggling with the last part. I'm quite new to bash so... yeah, expect some bs code. This is what I got so far:


#!/bin/bash

# Get the last 10,000 lines from tmux pane
output=$(tmux capture-pane -p -S -10000)

# Extract commands introduced by the user
commands=$(echo "$output" | awk '{print NR, $0}'| grep '❯')

# Present the commands in dmenu
selectedcommand=$(echo "$commands" | dmenu -l 10 -p "Select a command:")
selected
commandnumber=$(echo $selectedcommand | awk '{print $1}')
echo $selectedcommandnumber


# Text stored in a variable
text="$output"

# Search for the line using grep
matchedline=$(grep -E "^$selectedcommandnumber" <<< "$text")
echo $matched
line

if ! -z "$matched_line" ; then
# Get the line number of the matched line
linenumber=$(grep -n -E "$regexpattern" <<< "$text" | head -n 1 | cut -d: -f1)

# Output the next line using sed
nextlinenumber=$((linenumber + 1))
next
line=$(sed "${nextlinenumber}q;d" <<< "$text")
echo "nextline $nextline"
else
echo "nextline $nextline"
fi

&#x200B;

https://redd.it/1bf0ob4
@r_bash
Loop until success

I have curl command I want to run in a loop every 10 seconds that keeps running until it is successful (exits with status 0) and echos the output to the screen. If it has non 0 code it keeps going. Something like

while true; do curl $arg; sleep 10; done

How can I check the output code and end the loop when is successful?

https://redd.it/1bf5kt1
@r_bash
Trouble sending a large list of files into a text file.

I have a directory of approx. 90,000 files. I am using find . -maxdepth 1 -name "*.png" > $frames_list to generate a text file of filenames that I can process later. Using this command, I only manage to generate approx. 80,000 filenames in the text file. What is going wrong here?

https://redd.it/1bflsx7
@r_bash
Overwritten bashprofile?

I think I accidentally overwrote my bash
profile when I tried to add a path for something. I wrote something like export PATH=something and then I saved it. Now none of my commands work in my bash (emulator, for windows) terminal. I'm not sure what to do? Please make answers beginner friendly.

https://redd.it/1bfqf9q
@r_bash
SNMPGET, multiple OIDs, single line output with delimeter?

Hi, I am trying to pull together a noscript which will allow me to use snmpget to get multiple OID values and output to a CSV file with something like a comma as a delimeter. At the moment I have the following but this outputs to multiple lines:

#!/bin/bash

&#x200B;

### Synology Veriables

SynologyOID_Name='.1.3.6.1.2.1.1.5.0'

SynologyOID_Model='.1.3.6.1.4.1.6574.1.5.1.0'

SynologyOID_Serial='.1.3.6.1.4.1.6574.1.5.2.0'

SynologyOID_Firmware='.1.3.6.1.4.1.6574.1.5.3.0'

&#x200B;

### Synology SNMPGET

snmpget -Oqv -v 2c -c 'public' `192.168.50.10` $SynologyOID_Name $SynologyOID_Model $SynologyOID_Serial $SynologyOID_Firmware | tr -d '"'

This outputs as the following:

DS415Plus

DS415+

1512MIN750113

DSM 7.1-42962

Any thoughts?

Thanks.

https://redd.it/1bg4rix
@r_bash
Share & Improve: A Bash Script for Streamlining Math Calculations

Hey everyone,

I've put together a bash noscript aimed at simplifying a wide array of math calculations. From quick percentage figures to solving algebraic equations, this tool is designed to help those who prefer working within the terminal or need a quick, noscriptable solution to common math problems. It's a project born out of a desire to assist and provide value to our community.

# Script Highlights:

Broad Coverage: Includes calculations for percentages, geometry, algebra, and more.

User-Friendly: Offers a straightforward selection menu for different formulas, designed with ease of use in mind.

# I Need Your Insight:

This noscript isn't just for me; it's for all of us. I'm reaching out to you for two main reasons:

Efficiency and Optimization: If you have suggestions on how to make the noscript run smoother or cleaner, I'm all ears.

Expanding the Toolkit: I want this to be as useful as possible. If there's a calculation you find yourself needing that's not included, let me know. Let's build something great together.

# Why This Matters:

I believe in the power of sharing knowledge and tools. This noscript is a small contribution to that ethos. It's about more than just solving equations; it's about empowering each other with the resources to tackle our challenges more efficiently. I believe there are people, especially students, who could benefit from a noscript like this.

# Contribute:

Whether it's suggesting new features, optimizing current ones, or just sharing your thoughts on the approach, your input is invaluable. This noscript is open for improvement, and with your help, we can make it an even more useful resource for everyone.

I look forward to seeing your feedback.

GitHub Script

https://redd.it/1bgjjx5
@r_bash
completely new to bash, what is this thing? what is it telling me?
https://redd.it/1bgy38y
@r_bash
Writing some bash noscripts to check and restart Emby server on Devuan 5 as soon as it closes...

Hello to everyone.

I'm trying to keep up one Emby server on my ARM Chromebook arm 32 bit aka SNOW. The real problem is that it is able to be up only for some time and then closes. To fix this problem,I've created a couple of bash noscripts that act as a sentinel. As soon as it goes down,they detect it and they try to restart the process. I created 3 bash noscripts that should do the trick :

check-emby :

while :
do
 if pgrep Emby > /dev/null
 then
     echo "Emby Server is running..."
     sleep 10s
 else
     echo "Emby Server is not running...but now it will run again"
     /opt/emby-server/bin/./emby-server &
 fi
done


check-check-emby :


while :
do
 if pgrep Emby > /dev/null
 then
     echo "Emby Server is running..."
     sleep 10s
 else
     echo "Emby Server is not running...but now it will run again"
     /opt/emby-server/bin/./check-emby &
 fi
done

This is what happens when "emby-server &" is invoked :

# ps ax | grep emby

9202 pts/1    Sl+    1:06 /opt/emby-server/system/EmbyServer
-programdata /var/lib/emby -ffdetect /opt/emby-server/bin/ffdetect
-ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe
-restartexitcode 3 -updatepackage emby-server-deb{version}armhf.deb

I had to create two bash noscripts because when EmbyServer stops working,even check-emby closes. I don't understand why. Inside my sick mind the check-check-emby noscript should restart both. I don't know if it will work. For the moment it is still up and running.

Well. I have a couple of questions to ask you :

1. Can you imagine a better method than mine to achieve the same goal ?
2. Do you think that it will work ? I ask this because Emby is not yet closed by itself. It did the first time and it didn't work (but at that time I hadn't created the check-check-emby noscript). I have already checked what happens if I close it by myself. It works. But I want to see what happens if it naturally closes.
3. When Emby closes I would like to hear a beep coming from the Chromebook and I would like that it is produced by the bash noscript. 

Can you help me ? thanks.

https://redd.it/1bh0gzd
@r_bash
Radion, an internet radio CLI client, written in Bash.
https://redd.it/1bh3x8y
@r_bash
How to fix unbound variables?

I've been using the following noscript for several years without issues.

https://github.com/Cody-Learner/aurch/blob/main/aurch

When I try to implement set -euo pipefail in the noscript, specifically the set -u exits with line 23: 2: unbound variable.

Trying to see how many unbound variables there are, I comment out line 23, and it fails on line 45 now. Comment out line 45 and 46, it still exits with line 45: package: unbound variable

1) I don't understand why set -u won't ignore line 45/46 being commented out.
2) I have no idea how to fix these unbound variables, because they work, without them the noscript would be broken, and they're obviously being set or the noscript would fail to work properly.

What am I not getting with "unbound variables" and possibly provide an alternate method to noscript a problematic lines for an example?

https://redd.it/1bh6fwj
@r_bash
How to play a beep when the emby server process die using a bash noscript.

Hello to everyone.

I'm trying to keep up one Emby server on my ARM Chromebook arm 32 bit aka SNOW where I have installed Devuan 5.

The real problem is that it is up only for some time and then it closes.

To fix this problem,I've added this line :

&#x200B;

7:2345:respawn:/opt/emby-server/bin/emby-server

to /etc/inittab.

Furthermore,for the sake of my curiosity I would like to hear a beep when the emby server process dies. I tried some noscripts written in bash found on Internet,but none of them worked.

&#x200B;

&#x200B;

https://redd.it/1bheafr
@r_bash
Pass arguments to other noscript

In bash noscript ./noscript there is such line

su - usr -c "VAR1=text VAR2=text command --options"

I want if I call like ./noscript --outside-option outside-value then inside noscript will be called like

su - usr -c "VAR1=text VAR2=text command --options --outside-option outside-value"

So in noscript I changed line to

su - usr -c "VAR1=text VAR2=text command --options $@"

But that isn't working. command shows error like it is detecting --outside-option without outside-value.

It is recommended to always surround $@ with quotes like "$@". Is that the cause for error? I can't see how to escape it properly inside quotes in the noscript.

https://redd.it/1bhdx6b
@r_bash
Command not Found in Script Only

Hi,

I recently starting learning bash. I thought to create a bash noscript to automate installing and configuring ollama.

#!/usr/bin/bash
curl -fsSL https://ollama.com/install.sh | sh // This is for installing ollama
ollama run llama2
touch Modelfile
// rest of file


Once it reach line 3, it says command not found: ollama and the noscript fails from that point. What could be the problem?

https://redd.it/1bhr4yi
@r_bash
Securely Store API Key & Use Crontab

Hi, I have a bash noscript which requires an API key for SendGrid to send an email. I am planning on calling this noscript every 6hrs so adding to crontab.

What are the best practices for storing the API key? Obviously not in the noscript itself but I have read that environment variables is also not great and the fact that I want to call via crontab.

Thoughts? Thanks.

https://redd.it/1bhs5zh
@r_bash
i am running rsync in a while loop and it isn't releasing when finished.

Everything runs as it should, but at the end of the program rsync isn't signalling that it is finished and the "Working" stays in an infinite loop until I shut it down. What am I missing? I should be simple enough, print out the stuff while the program runs, when finished, stop.

&#x200B;

RUN_RSYNC() {
tput sc ; tput civis ; tput ed ; size=5 ;
host=$1 ; dest=$2 ;
declare exitcode ;
printf '\t%s\r\t' "One moment. Checking destination drive..." ;
while [[ $( rsync "${RSYNC_FLAGS[*]}" -- "${host}/" "${dest}" | sed "s/^/$(date +%m-%d-%Y_%H%M)\t>>\t" |& tee -a "${RSYNC_LOG}" ) != 0 ]] ; do
unset i ;
tput el ;
printf '\r\tWorking' ;
for (( i=1 ; i<="${size}" ; i++ )) ; do
printf '%s' "." ;
sleep 0.5 ; done ;
printf '\r\tWorking' ;
for (( i=1 ; i<="${size}" ; i++ )) ; do
printf '%s' " " ;
sleep 0.5 ; done ;
printf '\r' ;
done ;
exitcode=$? ;
return "${exitcode}" ;
tput cnorm ; tput rc ;
} ;

Edit: I have tried not using != 0, and using just the process itself, and there is the same issue

https://redd.it/1bhuqn4
@r_bash
what are favorite commands in bash?

so i searched "what are favorite commands in bash?" in reddit and i was surprised to find that this question doesn't seem to have ever been asked in r/bash

so i wanted to take this opportunity, what are your favorite commands in the bash shell and why?

doesn't matter why you like them, or what their purpose is, just what are your flat out favorite commands and why?

thank you

https://redd.it/1biemu1
@r_bash