r_bash – Telegram
Help needed with noscript

Hello is have noscript, it works when I run it manually. Problem is when I want to run it with cron, backup is not created. From log seems noscript stuck on password. Any help appreciated

#!/usr/bin/expect -f

log_file /tmp/debug.log

spawn echo "cron started"

spawn rm /home/admin/backup-restore/mls_backup/mls-backup.tar.gz

set password {password}

spawn /usr/sbin/exec /home/admin/backup-restore/backup-restore --target /home/admin/backup-restore/mls_backup/mls-backup.tar.gz --no-encryption

expect "admin password:"

send "$password\r"

interact

https://redd.it/1grwnht
@r_bash
Is there a tool for compare 2 dirs side by side?

Hi, I am using dirdiff, grsync but dirdiff show the same files like differents when they are the same. grsync will copy over the same file in destiny.

I will do the backup manually so,

I need a tool for compare 2 dirs side by side...

I have pending to see yours complete replies to my last post here.

Thank you and Regards!

https://redd.it/1grxc96
@r_bash
Codai: AI code assistant in Terminal with understanding the full project context

Codai is an AI code assistant designed to help developers efficiently manage their daily tasks through a session-based CLI, such as adding new features, refactoring, and performing detailed code reviews. What makes codai stand out is its deep understanding of the entire context of your project, enabling it to analyze your code base and suggest improvements or new code based on your context. This AI-powered tool supports multiple LLM models, including GPT-4o, GPT-4, Ollama, and more.

https://github.com/meysamhadeli/codai

https://redd.it/1grw5zx
@r_bash
Testers wanted: I made a noscript to automatically add and remove swap without rebooting.

I use Debian as my daily driver (I've been using Linux in some for or the other as my daily driver since 2006). I also us Debian for all my servers. I also running a webhosting business and in my 20+ years in the game, I have learned that...

1. VPS's do not come with SWAP, but sometimes you need a bit of SWAP to handle heavy load.
2. SWAP files can be added and removed on the fly (no reboot required), however a SWAP partition, not so simple.

On my daily driver machine, I also create a lot of digital artwork. I recently found myself rendering a finished artfile that was 9.5GB (24000px by 13700px) in Gimp, and half way through I started running out of RAM and SWAP. So I quickly created the needed SWAP file, and Gimp was able to finish the render without crashing.

So I created a noscript to automate the process, along with two supporting noscript.

I am wanting some guys to test it out, maybe in a VM if you don't want to risk a production or daily driver machine.

I am running it currently on my laptop. It has 12GB RAM and 4GB SWAP. I opened several of my art pieces 12000px wide to 24000px wide, several times into various programs. I watched my desktop widget show the RAM getting used up, and then the SWAP, then suddenly, more SWAP. When I closed all the images from all the programs, I watched all the extra SWAP space disappear?

Looking for constructive criticism and feedback. The Git Repo is https://git.zaks.web.za/thisiszeev/linux-server-tools and it's all in the folder swap-management.

Thanks in advanced, as I am wanting to rework it in to a solution that can be installed via a package manager, to simplify life for others...

https://redd.it/1gst49e
@r_bash
Resources for learning Bash basics

I was recently tasked with creating some resources for students new to computational research, and part of that included some material on writing bash noscripts to automate various parts of their computational workflow. On the one hand: this is a little bit of re-inventing the wheel, as there are many excellent resources already out there. At the same time, it's sometimes helpful to have guides that are somewhat limited in scope and focus on the most common patterns that you'll encounter in a particular domain.

With that in mind, I tried to write some tutorial material targeted at people who, in the context of their research, are just realizing they want to do something better than babysit their computer as they re-run the same code over and over with different command line options. Most of the Bash-related information is on this "From the command line to simple bash noscripts" page, and I also discuss a few noscripting strategies (running jobs in parallel, etc) on this page on workload and workflow management.

I thought I would post this here in case folks outside of my research program find it helpful. I also know that I am far from the most knowledgeable person to do this, and I'd be more than happy to get feedback (on the way the tutorial is written, or on better/more robust ways to do noscript things up) from the experts here!

https://redd.it/1gthizk
@r_bash
commitzen init generates incorrect output when run from a bash noscript

### Denoscription

- cz init does not work properly when run programmatically inside the python:3.10.11 docker container
- I am trying to run cz init from a bash noscript without manual intervention and I tried various formats with no luck so far

### Steps to reproduce

1. Install docker
1. docker pull python:3.10.11
1. Install poetry inside docker
curl -sSL https://install.python-poetry.org | python3 - --version 1.6.0

1. Install commitizen docker
1. Try running cz init programmatically inside docker as shown below

### Current behavior

## Method 1
printf "\npyproject.toml\ncz_conventional_commits\npoetry: Get and set version from pyproject.toml:tool.poetry.version field\nsemver\nv$major.$minor.$patch$prerelease\nY\nY\ncommit-msg" | /root/.local/bin/poetry run cz init

## Output 1
Welcome to commitizen!

Answer the questions to configure your project.
For further configuration visit:

https://commitizen-tools.github.io/commitizen/config/

Warning: Input is not a terminal (fd=0).
? Please choose a supported config file: pyproject.toml
? Please choose a cz (commit rule): (default: cz_conventional_commits) cz_customize
? Choose the source of the version: poetry: Get and set version from pyproject.toml:tool.poetry.version field
No Existing Tag. Set tag to v0.0.1
? Choose version scheme: semver
? Please enter the correct version format: (default: "$version") semver
? Create changelog automatically on bump Yes
? Keep major version zero (0.x) during breaking changes Yes
? What types of pre-commit hook you want to install? (Leave blank if you don't want to install) done

You can bump the version running:

cz bump

Configuration complete 🚀


## Method 2
poetry run cz init <<EOF
pyproject.toml
cz_conventional_commits
poetry: Get and set version from pyproject.toml:tool.poetry.version field
semver
v\$major.\$minor.\$patch\$prerelease
Y
Y
commmit-msg
EOF


## Output 2
Welcome to commitizen!

Answer the questions to configure your project.
For further configuration visit:

https://commitizen-tools.github.io/commitizen/config/

Warning: Input is not a terminal (fd=0).
? Please choose a supported config file: .cz.toml
? Please choose a cz (commit rule): (default: cz_conventional_commits) cz_conventional_commits
? Choose the source of the version: scm: Fetch the version from git and does not need to set it back
No Existing Tag. Set tag to v0.0.1
? Choose version scheme: pep440
? Please enter the correct version format: (default: "$version") v$major.$minor.$patch$prerelease
? Create changelog automatically on bump Yes
? Keep major version zero (0.x) during breaking changes Yes
? What types of pre-commit hook you want to install? (Leave blank if you don't want to install) done

You can bump the version running:

cz bump

Configuration complete 🚀


### Desired behavior

## Both outputs should be as follows

Welcome to commitizen!

Answer the questions to configure your project.
For further configuration visit:

https://commitizen-tools.github.io/commitizen/config/

? Please choose a supported config file: pyproject.toml
? Please choose a cz (commit rule): (default: cz_conventional_commits) cz_conventional_commits
? Choose the source of the version: poetry: Get and set version from pyproject.toml:tool.poetry.version field
No Existing Tag. Set tag to v0.0.1
? Choose version scheme: semver
? Please enter the correct version format: (default: "$version") v$major.$minor.$patch$prerelease
? Create changelog automatically on bump Yes
? Keep major version zero (0.x) during breaking changes Yes
? What types of pre-commit hook you want to install? (Leave blank if you don't want to install) [commit-msg]
commitizen pre-commit hook is now installed in your '.git'


You can bump the version running:

cz bump

Configuration complete 🚀


### Environment

commitizen version: 3.30.0
python version: 3.10.11
docker version: Docker version 27.2.0, build 3ab4256
cz init is running inside a docker container very specifically the python 3.10.11
Course to improve

I already understand how mostly everything works in bash, however, I am looking for a course to learn how to more effectively format noscripts. My noscripts are so messy and hard to read. Any ideas?

https://redd.it/1gudh85
@r_bash
Reading array not working

I'm running my noscripts on ubuntu.

I've tried to read an array using read command and it's as follows:

read -a arr

which is working when I execute it as a standalone command and not working when I'm trying it use it in a shell noscript file.

https://preview.redd.it/hjo58avuxz1e1.png?width=582&format=png&auto=webp&s=faea749ec637d31dff18fc0f027ab901f7d83df0



https://redd.it/1gviv1m
@r_bash
Running a Binary From Another Disk – macOS

Hello,


I faced a real-life challenge by trying to run a Unix binary installed on another partition of my SSD. Trying to execute it showed the "Segmentation error" message which usually points to an incompatibility. Switching to the partition with a newer macOS that hosts the binary allows me to run it as intended.

I suspect it's because of the paths to dependencies hardcoded in the binary. My question is, is it possible to make it use these paths even if I'm currently working from the other partition?

https://redd.it/1gvk0he
@r_bash
Is there ever a good reason to use exit 1 in a noscript?

Is there ever a good reason to use `exit 1` in a **function** (noscript is wrong)? You should *always* use `return 1` and let the caller handle what to do after? The latter is more transparent, e.g. you can't assume `exit 1` from a function always exits the noscript if the function is run inside a subshell like command substitution? Or is `exit 1` in a function still fine and the maintainer of the noscript should be mindful of this, e.g. depending on whether it's run in a subshell in which case it won't exit the noscript?

I have an `abort` function:

abort() {
printf "%b\n" "${R}Abort:${E} $*" >&2
exit 1
}

which I intended to use to print message and exit the noscript when it's called.

But I have a function running in a command substition that uses this `abort` function so I can't rely on it to exit the noscript.

Instead, change `exit 1` to `return 1` and `var=$(func) || exit $?`? Or can anyone recommend better practices? It would be neater if the abort function can handle killing the noscript (with signals?) instead of handling at every time `abort` gets called but not sure if this introduces more caveats or is more prone to error.

I guess I shouldn't take "exit" to typically mean exit the noscript? I believe I also see typical `abort`/`die` with `exit 1` instead of `return 1`, so I suppose the maintainer of the noscript should simply be conscious of calling it in a subshell and handling that specific case.

https://redd.it/1gvwzxa
@r_bash
I don't know how to use 'less' and 'read in a while loop together, and I'm sick of coming up with hacky workarounds.

This is a problem I run into frequently, but I'll describe the current application.

So, I have a list of subnoscript files for all the episodes of a program called "Forged in Fire". I'm trying to review each file that contains something about "meeting parameters" to compile a list of the episodes where there has been a "parameter failure". I thought it would be as simple as...

egrep -o "./Forged.in.Fire.S.E.extractedsub" ./matching_episodes | uniq | sort | while read file ; do less -FX "$file" ; reset ; read -p "Did that episode have a parameter failure?: yes_no" ; if [ "$yes_no" = "yes" ] ; then echo "$file" >> ./episodes_with_parameter_failures ; fi ; done

However it turns out that between piping information into "while", the way "less" blocks and how "read" blocks for input, this isn't working. All that happens is 'less' runs, and when I exit, the next instance of 'less' runs immediately instead of my prompt. I've tried a whole host of things like trying to run 'clear', or 'reset', or other more direct tty options to no avail.

I'm not really sure how to change my approach to this because it seems like it's just simply not feasible due to the way 'while' is creating a subshell thanks to the standard-input redirection, and then with 'less' and 'read' both blocking for input. But I'm not sure what other tools in bash I might be able to use.

I need to be able to

Read a dynamically-created list of files
For each file, use some kind of pager like 'less' or 'more (no, it doesn't work with 'more' either) to able to page up and down, and seek within the file contents
Upon exit from the pager, prompt the user for input
Run conditional tests on the input

I'm wondering if I could somehow used 'xargs' to avoid piped input, but I still think there's an underlying issue of competing blocking going on between "less" and "read" that won't resolve? Perhaps not, because as a workaround I did this...

echo '#!/bin/bash' > ./
noscript.sh ; egrep -o "./Forged.in.Fire.S.E._extracted_sub" ./matchingepisodes | uniq | sort | while read file ; do echo -ne "less "$file"\n./review.sh "$file"\n"; done >> ./noscript.sh

That allows me to run '
noscript.sh' afterwards, and works as I want, but I would really like to understand this to not have to rely on such a hacky workaround for next time I encounter something like this, because there are many occasions where I would like to run a loop that presents me the contents of something in a pager program, and then be prompted about what to do about it. But the current ways I know how to skin this cat really suck.

So long story short, I really want to be able to do something like this...

*produce list of files* | while read file ; do less "$file" ; read -p "Question about file" user
input ; if expression evaluating $user_input ; then run some code ; fi ; done

As a quick one-liner and have it actually work.

https://redd.it/1gwsdkq
@r_bash
Repository updater

Need a repo updater and need to implement in your custom bash noscripts to make your noscript up-to-date and monitor for the updates??, here it is called repo-updater

Needs a code update for better use

It was originally created for Android Sysinfo noscript to check updates here


https://redd.it/1gy2ybp
@r_bash
Ble-sh Performance Tune Help

Hello everyone,

I am a newbie Ble-sh user. I installed it using all default configurations. I think it's a bit slow, and that latency bothers me a lot. I would like to know some good tips to tune the performance. Do you mind sharing them with me?
I appreciate any help you can provide.

PS: I also use Atuin integrated with it. I would greatly appreciate any performance tunes upon it as well.

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