r_bash | Unsorted

Telegram-канал r_bash - r_bash

46

Credits: @r_channels & @reddit2telegram

Subscribe to a channel

r_bash

DirDiff: does anyone know to set depht to compare?

Hi, I'd like to use dirdiff with a degree of depht for compare 2 dirs. why? I have some heavy sub-dirs (with lots of pics, vids) and spend lot of time seeing into them! If I can set depht: bingo!

Thank you and regards!

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

Читать полностью…

r_bash

Config skill issue

How to remove line number in bat command

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

Читать полностью…

r_bash

GitHub - helpermethod/up: Climbing the directory tree at the speed of thought.
https://github.com/helpermethod/up

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

Читать полностью…

r_bash

Article about Bash Strict Mode

I write an article about Bash Strict Mode.

I would love to hear your feedback:

https://github.com/guettli/bash-strict-mode

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

Читать полностью…

r_bash

Looking for some guidance on how to tackle this problem with bash. Had a few ideas that I think can work but would like more experienced opinions.

Hello! For context to the title, I'm trying to make a bash script(s) that use the ncat util from nmap to capture data being streamed by a phone server, that part I've been able to accomplish no problem. I'm running into an issue when trying to take that data capture and output it to unique daily files, and having those files have only the output for that specific day.

The issues i've ran into are:

* if I move the file where ncat is being redirected to, it keeps appending to that same file even after renaming
* if I try to have the script running ncat change the file name to make new output file every day, no dice.
* using a cron job worked to an extent, in that scenario the ncat command was still putting everything in 1 big file and that was what was copied daily.

How would you approach something like this??

I've changed my scripts around a lot and the concepts are pretty simple so I haven't pasted my code here in the post, but if you'd like to see some of it by all means just ask :)


One thought I had was to make the script running ncat in a way where it can be called by a cron job, the only issue I can see there is making sure the ncat process stops after the day's over.

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

Читать полностью…

r_bash

ImageMagick6: ¿how change save 75 compr.(default) to 95 compr.?

Hi, this ask is about ImageMagic 6: Do you know how I change the compression for save by default is 75 and I'd like to set compression 95 (so change 75 for 95 by default).

Thank you and Regards!

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

Читать полностью…

r_bash

Simple bash script help

Looking to create a very simple script to start a few services at once just for ease. My issue is it only wants to run one or the other. I'm assuming because they're both trying to run in the same shell? Right now I just have

cd ~/path/to/file &
./run.sh &
sudo npm run dev

As it sits, it just starts up the npm server. If I delete that line, it runs the initial bash script fine. How do I make it run the first script, then open a new shell and start the npm server?

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

Читать полностью…

r_bash

Temporarily change terminal 16 color palette in a script?

What's the specific term to call/describe the 16 colors that's always being used by the terminal? (neofetch colored squares, etc.)

And is there a way to dynamically change them through a script?

Searching for solutions, not sure if the command I need is tput or dircolors or something else.

Why do I want to do this? One utility I'm using will only use the set of 16 colors used by the terminal. I'm looking for a workaround so that I can force it to use colors I specify (from the 256 color set) without changing the defaults of my terminal.

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

Читать полностью…

r_bash

Bash grep

I've tried numerous rules, but I can't seem to figure out the correct pattern.

I have numerous words in a file

abcd:1234:ef35
f24a:5fa3
ab12:34fa:cd42


I'm trying to write a grep that if a word contains more than 1 colon, the entire word is returned.

The issue is that the strings may be in a list, or they may be side-by-side, only separated by a space

abcd:1234:ef35 f24a:5fa3 ab12:34fa:cd42

I can't seem to pull the whole word, it always returns a single character.

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

Читать полностью…

r_bash

Help (Newbie)

if i gonna learning bash scripting, where to start and how?. i know understand bash scripting, but can'not make it myself

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

Читать полностью…

r_bash

M3U file list

I know I can create a file list with ls -1 > filename.txt, but I don't know how to prepend the directory path. I'm trying to create an m3u file list I can transfer to Musicolet on my phone. Can someone point me in the right direction?

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

Читать полностью…

r_bash

Confirming speed / bash practices

Long story short, I have a CSV file, 5 fields.

I read it into bash, and used IFS / while loop to read through the delimiters.

I'd say the CSV file in total is roughly 40MB. Pretty large for a CSV.

I went back and just decided to add a condition to check if the folder existed, because each row can be placed in different folders depending on the category.

When I added that check along with mkdir, I noticed that the speed dramatically went to hell. Without mkdir, the file completed in about 2 minutes. When I add mkdir -p, the speed to run the file went above 30 minutes, and then I just killed the script because it wasn't worth waiting anymore.

Is mkdir that heavy in a while loop? Or is their a better way to do this to ensure the sub-folders are created. Obviously I can't do what I was doing, because that just tanked the speed.

Just to give an idea, all I did was:

if test ! -d ${CAT}; then
mkdir -p ${CAT}
fi


Which I guess I could just do mkdir -p and the check doesn't really matter. But I was just wondering what aspect is what caused the slow-down, using test or mkdir, and if there's a much faster set of commands when working inside a loop, or should I try to do as much as possible outside the loop and do the bare minimum inside.

I could see it adding a few minutes on, but I wasn't expecting such a dramatic change.

I'm sitting here running tests, and it appears if I do anything at all command based, it kills the speed. I tried tr just to manipulate a string, and that also did it.

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

Читать полностью…

r_bash

Two values separated by control character

I have a file from a program which I need to parse. The contents is simple, but the control character in the middle is really throwing me off

01 Brad
05 Dan
12 Tim


This is in a file, so my original thought was to just look each line of the file

for line in $(cat list.txt); do

done


But what I'm trying to do is for each loop, I get access to both the number on the left, and the name, because a folder is going to be created based on the left number, and then the filename will be the value on the right.

In a perfect world, I could just call each where I need it

for line in $(cat list.txt); do
mkdir -p ${leftValue}
touch ${rightValue}
done


This is just an example, but the objective is to have control of calling each side when I need.

I've tried sed filtering \009, \u0009, etc. Even trying [:alnum:] just to do something simple like replace the control character with a | pipe. Just to get some type of result.

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

Читать полностью…

r_bash

sensors_t: a simple bash function for monitoring the temperature of various system components with sensors

[LINK TO THE CODE ON GITHUB](https://github.com/jkool702/misc-public-scripts/blob/main/sensors_t.bash)

`sensors_t` is a fairly short and simple bash function that makes it easy to monitor temperatures for your CPU and other various system components using `sensors` (from the `lm_sensors` package).

***

###FEATURES

`sensors_t` is not *drastically* different than a simple infinite loop that repeatedly calls `sensors; sleep 1`, but `sensors_t` does a few extra things:

1. `sensors_t` "cleans up" the output from `sensors` a bit, distilling it down to the sensor group name and the actual sensor outputs that report a temperature or a fan/pump RPM speed.
2. for each temperature reported, `sensors_t` keeps track of the maximum temperature seen since it started running, and adds this info to the end of the line in the displayed `sensors` output.
3. `sensors_t` attempts to identify which temperatures are from the CPU (package or individual coreS), and adds a line showing the single hottest temperature from the CPU.^(1)
4. if you have a nvidia GPU and have `nvidia-smi` available, `sensors_t` will ue it to get the GPU temp and adds a line displaying it.^(2)

NOTE: the only systems I have available to test `sensors_t` use older (pre-p/e-core) intel CPU's and nvidia GPU's.

^(1)This (identifying which sensors are from the CPU) assumes that [only] these lines all begin with either "Core" or "Package". This assumption may not be true for all CPU's, meaning the "hottest core temp" line may not work on some CPU's. If it doesnt work and you leave your CPU name and the output from calling `sensors` I'll try to add in support for that CPU.

^(2)If someone with an AMD or intel GPU can provide a 1-liner to get the GPU temp, i'll try to incorporate it and add in support for non-nvidia GPU's too.

***

###USAGE

Usage is very simple: source the `sensors_t.bash` script, then run

sensors_t [N] [CHIP(S)]

`N` is an optional input to change the waiting period between updates (default is 1 second). If provided it must be the 1st argument.

`CHIP(S)` are optional inputs to limit which sensor chips have their data displayed (default is to omit this and display all sensors temp data). To see possible values for `CHIP(S)`, first run `sensors_t` without this parameter.

# example invocations
sensors_t # 1 second updates, all sensors
sensors_t 5 # 5 second updates, all sensors
sensors_t coretemp-isa-0000 # 1 second updates, only CPU temp sensors

***

###EXAMPLE OUTPUT PAGE

___________________________________________
___________________________________________

Monitor has been running for: 173 seconds
-------------------------------------------

----------------
coretemp-isa-0000
----------------
Package id 0: +46.0°C ( MAX = +98.0°C )
Core 0: +46.0°C ( MAX = +81.0°C )
Core 1: +46.0°C ( MAX = +88.0°C )
Core 2: +48.0°C ( MAX = +87.0°C )
Core 3: +45.0°C ( MAX = +98.0°C )
Core 4: +43.0°C ( MAX = +91.0°C )
Core 5: +45.0°C ( MAX = +99.0°C )
Core 6: +45.0°C ( MAX = +82.0°C )
Core 8: +44.0°C ( MAX = +84.0°C )
Core 9: +43.0°C ( MAX = +90.0°C )
Core 10: +43.0°C ( MAX = +93.0°C )
Core 11: +44.0°C ( MAX = +80.0°C )
Core 12: +43.0°C ( MAX = +93.0°C )
Core 13: +46.0°C ( MAX = +79.0°C )
Core 14: +44.0°C ( MAX = +81.0°C )

----------------
kraken2-hid-3-1
----------------
Fan: 0 RPM
Pump: 2826 RPM
Coolant: +45.1°C ( MAX = +45.4°C )

----------------
nvme-pci-0c00
----------------
Composite: +42.9°C ( MAX = +46.9°C )

----------------
enp10s0-pci-0a00
----------------
MAC Temperature: +53.9°C ( MAX = +59.3°C )

----------------
nvme-pci-b300
----------------

Читать полностью…

r_bash

Would you consider these silly aliases?

alias vi="test -f ./.vim/viminfo.vim && VIMINFO=./.vim/viminfo.vim || VIMINFO=~/.viminfo; vim -i \$VIMINFO"

alias make='vim Makefile && make'

The first one is so that I don't have my registers for prose-writing available whenever I'm doing Python stuff, and vice versa.

The second one is basically akin to git commit.

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

Читать полностью…

r_bash

I have written a utility to transcribe user-specified media files to subtitles using Bash
https://gitlab.com/brlin/media-to-whisper.cpp-subtitles

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

Читать полностью…

r_bash

Bash script to simplify finding Flatpaks via the command line
https://github.com/TDGalea/flatpak-finder

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

Читать полностью…

r_bash

Filter video files by codec?

How to list and sort/move video files by codec?

Ideally just move all have/x265 files into a subfolder kinda thing.

I've just grabbed mediainfo and am prodding at but don't really know what I'm doing....I suspect with a little bash and some knowledge it should make this simple.

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

Читать полностью…

r_bash

What terminal app do you use on your Linux distro

Hello everyone,

I am a Mac user, and there is a long time I don't use a Linux distribution. My terminal app is iTerm2. What is the best replacement for iTerm on Linux distro, such as, Ubuntu/Fedora/Alpine ?

My requirements are 256xterm colors and font change ability.
Thanks.

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

Читать полностью…

r_bash

When a process is killed because it exhausted free memory, I'd prefer bash says "Killed: out of memory" instead of just "Killed"

I see in siglist.c the internationalized string:

sys_siglist[SIGKILL] = _("Killed");

But I'm wondering if we can use anything that the kernel does around https://github.com/torvalds/linux/blob/master/mm/oom_kill.c#L947 to tell the user that the reason was low memory?

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

Читать полностью…

r_bash

Learning more practical automation

Can anyone point me to where I can learn more real world scripting. More so applying updates to things or monitoring system health, so far all of the “courses” don’t really help more than understanding simple concepts.

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

Читать полностью…

r_bash

Trying to understand why my search returns no results

Hi all,

Let me preface this by saying this is day one of my scripting journey. I'll also add that I am using ChatGPT to try to cheat the hell out of it!

With that said, here is my problem. I am going step by step through the process of converting a PDF to text, parsing the text for info and then saving that info into a csv file.

I am on OSX so I started by using Shortcuts to "Get text from PDF" which i initially outputted to a text file; it worked fine. I then added a script (generated by ChatGPT) to search the clipboard (I changed the Shortcuts output to the clipboard) for the line "Grand Total" and output the line below (which had the amount) to a csv file. However the script can't find the line "Grand Total". Ive tried this initially with Applescript and now with a shell script, neither work.

Here is the code I'm using:

#!/bin/bash

echo "pbpaste version: $(pbpaste)"

# Get the clipboard contents
input_text=$(pbpaste)

# Convert the clipboard text into an array of lines
mapfile -t lines <<< "$input_text"

# Initialize variables
grand_total_found=false
grand_total_value=""

# Loop through each line
for ((i = 0; i < ${#lines[@]}; i++)); do
# Normalize the line by trimming spaces and converting to lowercase
current_line=$(echo "${lines[i]}" | sed 's/^[ \t]*//;s/[ \t]*$//' | tr '[:upper:]' '[:lower:]')

# Check if line contains "grand total" (case-insensitive)
if [[ "$current_line" == *"grand total"* ]]; then
# Get the next line for the total amount and trim whitespace
grand_total_value=$(echo "${lines[i+1]}" | sed 's/^[ \t]*//;s/[ \t]*$//')
grand_total_found=true
break
fi
done

# Check if "Grand Total" was found
if [ "$grand_total_found" = true ]; then
# Prompt for output file location
echo "Enter the path to save the CSV file (e.g., /path/to/output.csv):"
read -r output_file

# Write "Grand Total" and value to the CSV file
echo "Grand Total,$grand_total_value" > "$output_file"
echo "Grand Total saved to CSV successfully at $output_file"
else
echo "No 'Grand Total' found in the clipboard text."
fi


And here is the output from that currrently:

> pbpaste version: Remittance Statement
>
> 1.00
>
> To:
>
> REDACTED
>
> Date: 31/10/2024
>
> Ref: TR16246
>
> (Property) REDACTED
>
> Date Main Tenant Description VAT
>
> Charge
>
> (inc VAT)
>
> Payment
>
> (inc VAT)
>
> 29/11/2022 Not Applicable 392208 7,850.29
>
> 0.00
>
> 7,850.29
>
> 0.00
>
> Grand Total
>
> 7,850.29
>
> REDACTED
>
> E-mail: REDACTED
>
> VAT No: REDACTED
>
> Page 1 of 2
>
> Income and Expenditure
>
> Type VAT
>
> Charges
>
> (inc VAT)
>
> c000- Contractor Charge 7,850.29
>
> Payments
>
> (inc VAT)
>
> Totals
>
> 7,850.29
>
> Total Remitted 7,850.29
>
> REDACTED
>
> Page 2 of 2
>
> No 'Grand Total' found in the clipboard text.


I added the echo just to review the text it was taking from the clipboard was correct.

Any help at this basic stage much appreciated as this is going to get more complicated (I'll eventually need to output multiple lines). Also, what are the best places to look for documentation onn this sort of stuff?

Thanks all.

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

Читать полностью…

r_bash

Who else has something like this in their .rc?

straight to prod \(\/s\)

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

Читать полностью…

r_bash

Idea's needed

I was mildly annoyed at the one line update script for ubuntu. So I created a wonderfully bloated monstrosity of a bash script to accomplish the updates and some other stuff. I wish to bloat this thing further with more functionality. Any ideas would be appreciated.

https://github.com/ageorge224/Update-Script

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

Читать полностью…

r_bash

File names with spaces as arguments

I want to merge a bunch of PDF s. The file names have spaces : a 1.pdf, b 2.pdf, a 3.pdf. And they're a lot of them.

I tried this script:

merge $@

And called it with merge.sh *.pdf

The script got each separated character as an argument : a 1.pdf b 2.pdf a 3.pdf.

I there a way to feed these file names without having to enclose each in quotes?


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

Читать полностью…

r_bash

cat match string / move to end of file

i've been over a few different websites reading up on this, but I feel like I'm missing something stupid.

I have a file, which contains a mix of ipv4 and ipv6 addresses. I'd like to use sed to match all ipv6 addresses in the file, cut them from their current position, and move them to the end of the file.

I've tried a few ways to do this, including using cat to read in the file, then using sed to do the action. It seems to be finding the right lines, but I read online that /d should be delete, and I'm trying to just get that to work before I even try to append to the end of the file.

cat iplist.txt | sed -n "/::/d"


I haven't even figured out the part of appending to the end of the file yet, I just wanted to get it to delete the right lines, and then add it back

cat iplist.txt | sed -n "/::/d" >> iplist.txt


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

Читать полностью…

r_bash

shellm: A one-file Ollama CLI client written in bash
https://github.com/Biont/shellm

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

Читать полностью…

r_bash

Composite: +40.9°C ( MAX = +42.9°C )
Sensor 1: +40.9°C ( MAX = +42.9°C )
Sensor 2: +42.9°C ( MAX = +48.9°C )

----------------
nvme-pci-0200
----------------
Composite: +37.9°C ( MAX = +39.9°C )

----------------
Additional Temps
----------------
CPU HOT TEMP: +48.0°C ( CPU HOT MAX = +99.0°C )
GPU TEMP: +36.0°C ( GPU MAX = 39.0°C )

----------------
----------------

***

I hope some of you find this useful. Feel free to leave comments / questions / suggestions / bug reports.

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

Читать полностью…

r_bash

What is it called when you ad an interface tu your terminal?

I apologize if this isn't the right sub but I do plan on using bash to do this. So I can use it across platforms. I'm trying to figure out what it's called, as I don't think shell is the proper term. And visor seems unrelated, Basically something with buttons for functions that sticks around at the top of terminals active area, active just meaning the space you can change the color of and nowhere outside it.
?

Thing is I don't want any input or output going underneath the buttons, which I want to use ANSI for. To me I would just called it an interface but that's way too vague, and it would be way too little to call a shell.

Like it would look similar to a HUD placed on you terminal, with active areas you could click with HID, any idea what this is called?

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

Читать полностью…

r_bash

bash: java: command not found

My Linux distro is Debian 12.7.0, 64bit, English.

I modified the guide titled [How to install Java JDK 21 or OpenJDK 21 on Debian 12](https://green.cloud/docs/how-to-install-java-jdk-21-or-openjdk-21-on-debian-12/) so that I could "install"/use the latest production-ready release of OpenJDK 23.0.1 (FYI Debian's official repos contain OpenJDK 17 which is outdated for my use.)

I clicked the link [https://download.java.net/java/GA/jdk23.0.1/c28985cbf10d4e648e4004050f8781aa/11/GPL/openjdk-23.0.1\_linux-x64\_bin.tar.gz](https://download.java.net/java/GA/jdk23.0.1/c28985cbf10d4e648e4004050f8781aa/11/GPL/openjdk-23.0.1_linux-x64_bin.tar.gz) to download the software to my computer.

Next I extracted the zipped file using the below command:

`tar xvf openjdk-23.0.1_linux-x64_bin.tar.gz`

A new directory was created on my device. It is called *jdk-23.0.1*

I copied said directory to `/usr/local`

`sudo cp -r jdk-23.0.1 /usr/local`

I created a new source script to set the Java environment by issuing the following command:

su -i
tee -a /etc/profile.d/jdk23.0.1.sh<<EOF
> export JAVA_HOME=/usr/local/jdk-23.0.1
> export PATH=$PATH:$JAVA_HOME/bin
> EOF

After having done the above, I opened [*jdk23.0.1.sh*](http://jdk23.0.1.sh) using FeatherPad and the contents showed the following:

export JAVA_HOME=/usr/local/jdk-23.0.1
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/bin

Based on the guide, I typed the following command:

`source /etc/profile.d/jdk23.0.1.sh`

To check the OpenJDK version on my computer, I typed:

`java --version`

An error message appeared:

`bash: java: command not found`

Could someone show me what I did wrong please? Thanks.

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

Читать полностью…
Subscribe to a channel