r_bash – Telegram
Fixing SQL errors when data includes "|" in the string and when noscript uses "|" as the delimeter

Hi! I am wokring on a bash noscript that extracts data from android device, i have 11 noscripts in total making up one tool. Everything so far works without any issues, except for one noscript, which extracts data from .db files into a readable txt format.

No matter what I do, i cannot get the extraction to work properly when reading data from the chroe browser. It reads the data fine and outputs to a txt file correctly, up to the point where there is a "|" character in the noscript of a page (for example in the gmail page noscript). Also I've tried it with the \\t delimeter but as far as i can remember the issue persists there, it seems like the pipe character is still responible for the issues


I tried enclosing it in double quotes, but it still did not work. here's the snippet of code responsible for that functionality/error.


# Extract browsing history to a text file
sqlite3 "$CHROMEDATAPATH/History" "SELECT noscript, url, lastvisittime FROM urls" \
| while IFS='|' read -r noscript url lastvisittime; do
# Convert unix timestamp to human-readable date
date=$(date -d "@$((lastvisittime/1000000 - 11644473600))" "+%Y-%m-%d %H:%M:%S" 2>/dev/null)
echo "Title: \"$noscript\"" >> "$extr/browsinghistory.txt"
echo "URL: \"$url\"" >> "$extr/browsing
history.txt"
echo "Last Visit Time: $date" >> "$extr/browsinghistory.txt"
echo "" >> "$extr/browsing
history.txt"
done

and here's the error i get in terminal (execution of the extraction stops there, but the noscript continues even tho set -e flag is set). I am pretty sure the issue is with the special characters in the noscript fields. In the database it is a Long varchar.

​

./bash/db_extractor.sh: line 108: http://gmail.com/|13325597979782411: syntax error in expression (error token is "://gmail.com/|13325597979782411")

Does someone have any idea how to handle this? Thank you in advance, have a nice day!

https://redd.it/12y9nvu
@r_bash
Check this link now



I have been researching Linux for DevOps for quite some time and by researching I have stacked piles of sample bash noscripts. So, I want you all to go through my GitHub repo and if you found my repo for the sample noscript good, please Fork it and give my repo some stars. Thanks in advance.

My Github Repo: - https://github.com/yashwant7chaudhari/Sample-Bash-Scripts

https://redd.it/12yd6l0
@r_bash
Langchain AI Bash Tool (Plain English converted to Linux one-liner)

I created an end-to-end llm app with a simple UI for the Langchain Bash tooling. I've been tinkering with an LLM app that generates Bash one-liners using OpenAI's Large Language Model plugged in. The app enabled users to submit plain English requests, receive practical Bash one-liners, and keep a simple command history.

Of course, there's often more than one way to tackle a problem in Bash, and OpenAI's LLM, while powerful, needs help producing focused and logical results. The key to this has been fine-tuning the prompt logic, leading to improved output quality.

I'm eager to know your thoughts and am open to constructive feedback and suggestions.


The World Famous Bash One-liner Tool! (oneliner.tech)

https://redd.it/12yj3n5
@r_bash
Use real time terminal logs in noscript

Hi! I have a game server on pi 4 that is open in a terminal and runs indefinitely in the background thanks to the command screen. It will generate some logs in the terminal and one of them is the info of which player has logged in.

I want to create a noscript that reads this info and sends an email with the name of the player. Is this possible? What would be a sample code for this?

https://redd.it/12ymwud
@r_bash
beepbeep: A nice QOL addition to my workflow

[https://github.com/SpicyLemon/SpicyLemon/blob/master/bash\_fun/generic/beepbeep.sh](https://github.com/SpicyLemon/SpicyLemon/blob/master/bash_fun/generic/beepbeep.sh)

This started out a simple a command that preserved the last exit code and beeped twice. Since then, I made a few enhancements to it.

Features:

* Exits with the same exit code as the previous command.
* Number of beeps can be provided as an argument.
* If no arguments are provided, it will beep twice if the previous exit code was \`0\`, or, three times if it was not \`0\`.
* If a non-numeric argument is provided and the \`say\` command is available, it will execute \`say\` with the text provided as args.

I like to use it at the end of commands that I expect to take longer than a few seconds so that I can shift my attention somewhere else, but still know when the command finishes.

For example:

$ make test; beepbeep

I actually have it aliased to \`alert\`: \`$ alias alert='beepbeep'\`, which is what I think of it as (and is easier to type). I didn't want the function named \`alert\` though due to high probability of conflicting with other commands.

You can download that file (at the top) and source it to add the \`beepbeep\` function to your environment. The file can also be directly executed if you prefer not to add it as a function to your environment.

Here's just the function definition from that file:

beepbeep () {
# Presever last exit code
local ec=$?
local count
if [[ "$#" -gt 1 || "$1" =~ [^[:digit:]] ]]; then
if command -v say > /dev/null 2>&1; then
say "$@"
return $ec
fi
printf 'beepbeep: Unknown argument(s): %s\n' "$*" >&2
else
count="$1"
fi

if [[ -z "$count" ]]; then
if [[ "$ec" -eq '0' ]]; then
count=2
else
count=3
fi
fi

printf '\a'
count=$(( count - 1 ))
while [[ "$count" -gt '0' ]]; do
sleep .3
printf '\a'
count="$(( count - 1 ))"
done
return $ec
}

It's just been so useful for me that I thought I'd share.

https://redd.it/12yurcx
@r_bash
Help

I need help writing a bash noscript to delete every folder that is older than 6 months, and delete 3 folder a week and save 2 for month 4 to month 6. The folders have the following naming convention; “files20230425”, “files20230424” z

https://redd.it/12yw7yo
@r_bash
filenames from a find / read loop being corrupted?

I have never seen this behavior before. This seems to be caused by running the python command line noscript "demucs". This utility from facebook will split individual instrument tracks from a song. When I saw how well it worked, of course I have to split my whole music library. In the course of doing so I found that when feeding it song file names from a `find` command, it would remove either 0, 1 or 2 characters from the front of the filename.

$ find . -type f -name '*.flac' | while read -r i; do \
echo "$i"
demucs -n htdemucs_ft -o ~/split --filename '{track} {stem}.{ext}' -j2 -d cpu --clip-mode rescale -- "$i"
done


Hiding the output from demucs, the result from the `echo "$i"` line is:

./02 California.flac
/08 Easily.flac
./01 Laughing And Not Being Normal.flac
/14 Butterfly.flac
./07 Artangels.flac
03 Scream (Ft. Aristophanes).flac
/06 Kill V. Maim.flac
./11 World Princess Ii.flac
05 Belly Of The Beat.flac
15 Realiti (Demo).flac
13 Life In The Vivid Dream.flac
/09 Pin.flac
./10 Realiti.flac
12 Venus Fly (Ft. Janelle Monae).flac
/04 Flesh Without Blood.flac


If the demucs command is removed, here is the output, which is what I expect:

./02 California.flac
./08 Easily.flac
./01 Laughing And Not Being Normal.flac
./14 Butterfly.flac
./07 Artangels.flac
./03 Scream (Ft. Aristophanes).flac
./06 Kill V. Maim.flac
./11 World Princess Ii.flac
./05 Belly Of The Beat.flac
./15 Realiti (Demo).flac
./13 Life In The Vivid Dream.flac
./09 Pin.flac
./10 Realiti.flac
./12 Venus Fly (Ft. Janelle Monae).flac
./04 Flesh Without Blood.flac


Any ideas how this can happen? I think that demucs is doing something weird, but it would think it shouldn't be able to modify this memory.

For completeness, I get the same behavior with this form:

while read -r file; do
demucs --etc
done < <(find blah)

https://redd.it/12zfuwq
@r_bash
Multiple case words

You can use

case $WORD in
pattern1)
function
1
;;
pattern2|pattern3)
function2
;;
esac

to execute functions depending on the value of WORD. `pattern
2|pattern3)` will execute if either `pattern2 or pattern3` match `$WORD`.

Is there a way to have multiple WORDS, like

case $WORD
1|$WORD2 in
pattern
1)
true
;;
esac

, where the commands inside pattern_1) is executed if pattern_1 match either $WORD_1 or $WORD_2?

https://redd.it/12zpjdw
@r_bash
Linux/bash noscripting projects for resume

I have recently been learning linux and bash noscripting and i want to know what is the best way to apply this to hands on projects.

What are some projects i can work on to add to my resume? for beginners-intermediate

https://redd.it/12zzwv7
@r_bash
echo -e doesn't work

I wrote a bash noscript with an ANSI Escape Sequence,

#!/bin/bash
echo -e "\33[2J"

and it doesn't work, and I have no Idea why.

https://redd.it/130l286
@r_bash
save root user's crontab as owned by normal user

hi. tried this in sudo crontab -e:

@weekly crontab -l -u root | sudo tee /configs/crontab-root-$(date +"%F").bak

also this

@weekly sh -c "crontab -l -u root > /configs/crontab-root-$(date +"%F").bak"

but get this on ls -l

-rw------- 1 root root 1.5K Apr 27 20:20 crontab-root-2023-04-27.bak
-rw-r--r-- 1 ram ram 525 Apr 26 15:18 gunicorn-2023-04-26.service.bak

while I need to save crontab-root file as 775 or 750 (or what's best approach)

https://redd.it/130q9a9
@r_bash
RPM upgrade - Redhat package manager

RPM - Redhat package manager question. Need help on upgrading from RPM 4 to 5. I tried this command: /usr/lib/rpm/bin/dbupgrade.sh but it says there's no such file or directory. Any option to do a sudo install or other suggestions would be appreciated.

https://redd.it/131dxzq
@r_bash
Help create a noscript to open a folder from terminal in Mac

I want to open this folder from terminal by running a sh noscript.

open '/Users/xxx/Library/Group Containers/xxx.ru.keepcoder.Telegram/appstore/account-xxx/postbox/media'

So I created an .sh file, put the above line in it and try to run it, but it shows 'command not found'. What did I do wrong ?

https://redd.it/131l9i7
@r_bash
What does the ampersand mean in command > /dev/null 2>&1?

command > /dev/null 2>&1


Like, I understand what it does, it's basically read and translated as "redirect the standard error to standard output, and redirect the standard output of command to /dev/null, so that both stderr and stdout get discarded".


Okay, cool, I understand what /dev/null is, what 2 and 1 represent, and what output redirection operators > do. But what does the & ampersand before 1 mean?


I could write this command line as


command > /dev/null 2>1


And it would still do what it's expected to do, so what's the point or meaning of the ampersand?


I understand that trailing ampersand at the very end of a command line makes a long-running command return immediately to the current shell while it runs the command in a background subshell, but this isn't a trailing ampersand as it's actually used before &1, or at least I think so.

https://redd.it/1328lk9
@r_bash
How does cat cat << EOF exactly work?

Can someone dissect in great details what's exactly going on when you run that cat command with cat << EOF?


cat << EOF > file.txt


Or when you write a noscript and then output text via writing:


cat << EOF
------
Some text to display when this noscript is run
------
EOF


I have a vague idea of what's going on but I'd rather a shell guru explains it correctly, just so I don't assume things.


I know that EOF stands for End of File and that it's just a convention, I could use abc instead and it'd still work.


What happens here is that cat << EOF lets you redirect inputs to cat until you type EOF to quit. cat will then output to the display what you just typed.


So cat << EOF > file.txt redirects everything you type to cat until the keyword you provided (EOF in our case) was entered, and when that happens, cat's output is redirected to be written to file.txt.

When EOF is entered, the shell? (or cat?) somehow knows the end of file is reached, and doesn't continue writing input to cat, how does that "magically" work? Is EOF detected by the shell interpreter or the cat command?



I get the general idea that cat << EOF tells the shell to give cat every line that follows, until the EOF is encountered again, I know what the lines do, I just don't understand the logic behind it. Does the redirection syntax signal to the shell that we only want cat to display whatever values of text that are only between the first EOF and the last EOF?

https://redd.it/132dgu9
@r_bash
How can I configure my bashrc so that the man command always check the number of columns available before re-rendering the text after I maximized the terminal window?

I have the following annoying pattern. I have the terminal emulator set to open at a certain geometry. When I open a man page, it's hard to read this way, so I maximize the window. The problem is the window background is max, but the text is still rendered as if it is limited to half the screen. Instead of using 211 cols, it still uses 86.

https://imgur.com/kMGIUSB

I tried some ChatGPT, but I failed. I guess I don't know how to ask. It told me to export MANPAGER='less -r' and source it. That didn't work. I asked a bit more and told me to try trap 'COLUMNS=$(tput cols)' SIGWINCH Still does not work for me.

So as of now I do it manually (q to exit less, arrow key up and voilà the text is rendered out with 211 columns). I tried to change the man pager to most. Same story. I tried different terminal. The same. I see nvim or nano don't have this problem. The column size gets recalculated when the window is maximized, neither less by itself. For example, less /var/log/syslog the text gets rendered taking into account the column size when I toggle between maximized and unmaximized.

Also, worth saying with man the problem doesn't happen if the terminal is maximized when initially opening the page, I can toggle the terminal window size and the text gets re-rendered just fine. It only has an issue when I try to increase the size of the window and for whatever reason the variable that holds the size of the available columns doesn't get pass.

Any help?

https://redd.it/132nrry
@r_bash
Mainline Nginx for Amazon Linux 2023

I am unable to install nginx from nginx repo instead it is installing nginx from amazonlinux repo again and again after following this [instructions\](http://nginx.org/en/linux\_packages.html#Amazon-Linux:\~:text=To%20set%20up%20the%20yum%20repository%20for%20Amazon%20Linux%202023%2C%20create%20the%20file%20named%20/etc/yum.repos.d/nginx.repo%20with) :

So, after failing i did

`dnf config-manager --add-repo http://nginx.org/packages/mainline/amzn/2023/`

'yum install nginx -y`

and came up with this error

```

nginx mainline repo 21 kB/s | 8.1 kB 00:00

created by dnf config-manager from http://nginx.org/packages/mainline/amzn/2023/7.1 kB/s | 3.3 kB 00:00

Errors during downloading metadata for repository 'nginx.org_packages_mainline_amzn_2023_':

\- Status code: 404 for http://nginx.org/packages/mainline/amzn/2023/repodata/repomd.xml (IP: 3.125.197.172)

Error: Failed to download metadata for repo 'nginx.org_packages_mainline_amzn_2023_': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

Ignoring repositories: nginx.org_packages_mainline_amzn_2023_

Dependencies resolved.

```

&#x200B;

https://preview.redd.it/7luxns5uatwa1.png?width=1899&format=png&auto=webp&v=enabled&s=ae9968d26e7691602c24fa3e482a4aa6ad9b175c

there should be nginx-mainline in the first row of repository.

How do i resolve this i can't understand .

https://redd.it/132qu2r
@r_bash
Best courses to learn bash noscripting

I want to learn bash noscripting. I know there are lot of resources out there but i want a course or site where they give small tasks or assignments along with the video.
I want to learn end to end. Like using awk,sed etc

https://redd.it/132sd5a
@r_bash