Aggregate multiple lines
I have a file that looks like this -
a 6509568
a 8011776
a 8011776
a 8011776
a 8011776
b 1112800
b 1369600
b 1369600
How do I make it look like -
a 38556672
b 3852000
https://redd.it/12t9df7
@r_bash
I have a file that looks like this -
a 6509568
a 8011776
a 8011776
a 8011776
a 8011776
b 1112800
b 1369600
b 1369600
How do I make it look like -
a 38556672
b 3852000
https://redd.it/12t9df7
@r_bash
Reddit
r/bash on Reddit: Aggregate multiple lines
Posted by u/daredevildas - No votes and 1 comment
kube-dialog update
Hi, I've just updated kube-dialog with a filter command, you can filter namespaces and objects(pods,jobs...) with ease now, enjoy)
https://preview.redd.it/d8zv5c0jp3va1.png?width=742&format=png&auto=webp&v=enabled&s=7da1fc340ca5be8cfd2bf0ac3a709b435c3b0bc9
https://redd.it/12teich
@r_bash
Hi, I've just updated kube-dialog with a filter command, you can filter namespaces and objects(pods,jobs...) with ease now, enjoy)
https://preview.redd.it/d8zv5c0jp3va1.png?width=742&format=png&auto=webp&v=enabled&s=7da1fc340ca5be8cfd2bf0ac3a709b435c3b0bc9
https://redd.it/12teich
@r_bash
GitHub
GitHub - vaniacer/kube-dialog: Dialog wrapper for kubectl on bash.
Dialog wrapper for kubectl on bash. Contribute to vaniacer/kube-dialog development by creating an account on GitHub.
Pure bash password generator
I wrote something like this but *waay* too complicated a few months ago. I fully realize it's not up to CISA standards, but I needed a way to auto generate dev Mysql passwords inside containers on startup.
genpw(){
declare -i limit="$1"
declare pw=''
_instr(){
declare -r str="$1"
declare -i sl=${#str}
declare -r chr="${2:0:1}"
declare -i ndx=$((RANDOM % ${sl}))
echo "${str:0:ndx}${chr}${str:$((ndx+1)):$((sl-ndx))}"
}
while [[ ${#pw} -le $limit ]]
do
if [[ $((RANDOM % 2)) -eq 0 ]]; then
# lc ascii
pw="$pw"$(printf "\x$(printf %x $((97+(RANDOM % 26))))")
elif [[ $((RANDOM % 2)) -eq 0 ]]; then
# uc ascii
pw="$pw"$(printf "\x$(printf %x $((65+(RANDOM % 26))))")
elif [[ $((RANDOM % 2)) -eq 0 ]]; then
# digits
pw="$pw"$((RANDOM % 10))
fi
done
declare c
# often mandatory non alpha characters
for c in '#' '@' '%'
do
pw="$(_instr ${pw:0:$limit} $c)"
done
echo "$pw"
unset -f _instr
} # genpw()
ahare@box:~/wk$ genpw 30
lQki068h@kUqa#8ewbtqw%t8eZkGcN
ahare@box:~/wk$ genpw 40
zwxNg7xl5Fz%EJBzajXdAn2dPTh#kdcJp@gk3fgM
https://redd.it/12trtg2
@r_bash
I wrote something like this but *waay* too complicated a few months ago. I fully realize it's not up to CISA standards, but I needed a way to auto generate dev Mysql passwords inside containers on startup.
genpw(){
declare -i limit="$1"
declare pw=''
_instr(){
declare -r str="$1"
declare -i sl=${#str}
declare -r chr="${2:0:1}"
declare -i ndx=$((RANDOM % ${sl}))
echo "${str:0:ndx}${chr}${str:$((ndx+1)):$((sl-ndx))}"
}
while [[ ${#pw} -le $limit ]]
do
if [[ $((RANDOM % 2)) -eq 0 ]]; then
# lc ascii
pw="$pw"$(printf "\x$(printf %x $((97+(RANDOM % 26))))")
elif [[ $((RANDOM % 2)) -eq 0 ]]; then
# uc ascii
pw="$pw"$(printf "\x$(printf %x $((65+(RANDOM % 26))))")
elif [[ $((RANDOM % 2)) -eq 0 ]]; then
# digits
pw="$pw"$((RANDOM % 10))
fi
done
declare c
# often mandatory non alpha characters
for c in '#' '@' '%'
do
pw="$(_instr ${pw:0:$limit} $c)"
done
echo "$pw"
unset -f _instr
} # genpw()
ahare@box:~/wk$ genpw 30
lQki068h@kUqa#8ewbtqw%t8eZkGcN
ahare@box:~/wk$ genpw 40
zwxNg7xl5Fz%EJBzajXdAn2dPTh#kdcJp@gk3fgM
https://redd.it/12trtg2
@r_bash
Reddit
r/bash on Reddit: Pure bash password generator
Posted by u/accuratehare5860 - No votes and no comments
Can anyone PLEASE help with this noscript!
When run it says : versions found then SELECT not found and Syntax error: "do" unexpected.
Can you help solve this (probable really simple error)?
​
\#!/bin/bash
\# Get the name of the song from the user
read -p "Enter the name of the song: " song_name
\# Use find to search for all versions of the song in the Music folder
song_paths=$(find /home/Music -name "$song_name*")
​
\# Print out a numbered list of the song versions and ask the user which one they want to play
echo "Versions of '$song_name' found:"
select song_path in $song_paths;
do
if [ ! -n "$song_path" \]; then
break
fi
done
\# Play the selected song using the default music player on the system
xdg-open "$song_path"
exit
https://redd.it/12txs4b
@r_bash
When run it says : versions found then SELECT not found and Syntax error: "do" unexpected.
Can you help solve this (probable really simple error)?
​
\#!/bin/bash
\# Get the name of the song from the user
read -p "Enter the name of the song: " song_name
\# Use find to search for all versions of the song in the Music folder
song_paths=$(find /home/Music -name "$song_name*")
​
\# Print out a numbered list of the song versions and ask the user which one they want to play
echo "Versions of '$song_name' found:"
select song_path in $song_paths;
do
if [ ! -n "$song_path" \]; then
break
fi
done
\# Play the selected song using the default music player on the system
xdg-open "$song_path"
exit
https://redd.it/12txs4b
@r_bash
Reddit
r/bash on Reddit: Can anyone PLEASE help with this noscript!
Posted by u/france20-21 - No votes and 1 comment
Help/Direction creating a commandline AI?
I understand that their is a tool out there currently by the name of CLAI, however I'm wondering if it would be possible (as an independent project) to build/design a better command line artifical intelligence similar to the CLAI bot that is currently available. If so what reading materials should I start with? Is it possible to leverage "zsh"/"bash" and other cli tools with python AI systems.
https://redd.it/12uhaak
@r_bash
I understand that their is a tool out there currently by the name of CLAI, however I'm wondering if it would be possible (as an independent project) to build/design a better command line artifical intelligence similar to the CLAI bot that is currently available. If so what reading materials should I start with? Is it possible to leverage "zsh"/"bash" and other cli tools with python AI systems.
https://redd.it/12uhaak
@r_bash
Reddit
r/bash on Reddit: Help/Direction creating a commandline AI?
Posted by u/Successful-Two6838 - No votes and no comments
getting used and free disk space before and after rsync/trash noscript
Hi. Iconsider the following noscript:
if mountpoint -q /media/external; then
printf "Disk space before:\n"
# <usedGB>/<totalGB> Free: <freeGB>
rsync -avzP --ignore-existing --update --delete --modify-window=2 --stats --human-readable --delete --exclude={'*.db','*.tmp','recycle/'} /sambashare/ /media/external
find /sambashare/recycle -mtime +$30 -delete +
printf "Disk space after:\n"
# <usedGB>/<totalGB> Free: <freeGB>
else
exit 1
fi
the challenging part is, getting the disk space right (for me). tried.
df -ht ext4
but it outputs something like this
ilesystem Size Used Avail Use% Mounted on
/dev/nvmexxxx 21G 6.8G 13G 35% /
/dev/nvmexxxx 8.4G 2.3G 5.7G 28% /home
Can you point me to the right path ?
also, can it be done more efficiently what I am trying to achieve ? Thanks
https://redd.it/12upmle
@r_bash
Hi. Iconsider the following noscript:
if mountpoint -q /media/external; then
printf "Disk space before:\n"
# <usedGB>/<totalGB> Free: <freeGB>
rsync -avzP --ignore-existing --update --delete --modify-window=2 --stats --human-readable --delete --exclude={'*.db','*.tmp','recycle/'} /sambashare/ /media/external
find /sambashare/recycle -mtime +$30 -delete +
printf "Disk space after:\n"
# <usedGB>/<totalGB> Free: <freeGB>
else
exit 1
fi
the challenging part is, getting the disk space right (for me). tried.
df -ht ext4
but it outputs something like this
ilesystem Size Used Avail Use% Mounted on
/dev/nvmexxxx 21G 6.8G 13G 35% /
/dev/nvmexxxx 8.4G 2.3G 5.7G 28% /home
Can you point me to the right path ?
also, can it be done more efficiently what I am trying to achieve ? Thanks
https://redd.it/12upmle
@r_bash
Reddit
r/bash on Reddit: getting used and free disk space before and after rsync/trash noscript
Posted by u/format_c_enter - No votes and no comments
Parse XML from a larger non-XML string in BASH
Hello people, I'm using a Calibre utility to fetch e-book metadata (via a BASH noscript):
$ fetch-ebook-metadata --isbn="9780791085455" --opf
The utility works by trying several resources, it returns errors as well as the metadata in XML format,
see output:
Failed to get cached URL from google for URL: https://www.amazon.com/Peyote-Mescaline-Drugs-Straight-Facts/dp/0791085457 with error: HTTP Error 429: Too Many Requests
Failed to get cached URL from google for URL: https://www.amazon.com/Nanny-Lana-Ferguson-ebook/dp/B0B6B41KFP with error: HTTP Error 429: Too Many Requests
Failed to get cached URL from google for URL: https://www.amazon.com/Basic-Geriatric-Nursing-Patricia-Williams/dp/0323554555 with error: HTTP Error 429: Too Many Requests
Response from wayback machine: {'archivedsnapshots': {},
'url': 'https://www.amazon.com/Basic-Geriatric-Nursing-Patricia-Williams/dp/0323554555'}
Failed to get cached URL from google for URL: https://www.amazon.com/-/es/M-Foster-Olive/dp/0791085457 with error: HTTP Error 429: Too Many Requests
Response from wayback machine: {'archivedsnapshots': {},
'url': 'https://www.amazon.com/-/es/M-Foster-Olive/dp/0791085457'}
Failed to get cached URL from google for URL: https://www.amazon.com/Responding-Emergency-American-Red-Cross/dp/1584805544 with error: HTTP Error 429: Too Many Requests
<?xml version='1.0' encoding='utf-8'?>
<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="uuidid" version="2.0">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
<dc:language>eng</dc:language>
<dc:subject>Juvenile Nonfiction</dc:subject>
<dc:subject>Health & Daily Living</dc:subject>
<dc:subject>Substance Abuse</dc:subject>
</metadata>
<guide/>
</package>
I only need this part (obviously):
<?xml version='1.0' encoding='utf-8'?>
<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="uuidid" version="2.0">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
<dc:language>eng</dc:language>
<dc:subject>Juvenile Nonfiction</dc:subject>
<dc:subject>Health & Daily Living</dc:subject>
<dc:subject>Substance Abuse</dc:subject>
</metadata>
<guide/>
</package>
Running the BASH noscript via Cygwin, but I can move to a Linux box.
I Googled it, but the Stack Overflow threads I got don't mention this scenario, at least not that I saw. My Shell capabilities aren't that strong.
https://redd.it/12v1lo6
@r_bash
Hello people, I'm using a Calibre utility to fetch e-book metadata (via a BASH noscript):
$ fetch-ebook-metadata --isbn="9780791085455" --opf
The utility works by trying several resources, it returns errors as well as the metadata in XML format,
see output:
Failed to get cached URL from google for URL: https://www.amazon.com/Peyote-Mescaline-Drugs-Straight-Facts/dp/0791085457 with error: HTTP Error 429: Too Many Requests
Failed to get cached URL from google for URL: https://www.amazon.com/Nanny-Lana-Ferguson-ebook/dp/B0B6B41KFP with error: HTTP Error 429: Too Many Requests
Failed to get cached URL from google for URL: https://www.amazon.com/Basic-Geriatric-Nursing-Patricia-Williams/dp/0323554555 with error: HTTP Error 429: Too Many Requests
Response from wayback machine: {'archivedsnapshots': {},
'url': 'https://www.amazon.com/Basic-Geriatric-Nursing-Patricia-Williams/dp/0323554555'}
Failed to get cached URL from google for URL: https://www.amazon.com/-/es/M-Foster-Olive/dp/0791085457 with error: HTTP Error 429: Too Many Requests
Response from wayback machine: {'archivedsnapshots': {},
'url': 'https://www.amazon.com/-/es/M-Foster-Olive/dp/0791085457'}
Failed to get cached URL from google for URL: https://www.amazon.com/Responding-Emergency-American-Red-Cross/dp/1584805544 with error: HTTP Error 429: Too Many Requests
<?xml version='1.0' encoding='utf-8'?>
<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="uuidid" version="2.0">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
<dc:language>eng</dc:language>
<dc:subject>Juvenile Nonfiction</dc:subject>
<dc:subject>Health & Daily Living</dc:subject>
<dc:subject>Substance Abuse</dc:subject>
</metadata>
<guide/>
</package>
I only need this part (obviously):
<?xml version='1.0' encoding='utf-8'?>
<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="uuidid" version="2.0">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
<dc:language>eng</dc:language>
<dc:subject>Juvenile Nonfiction</dc:subject>
<dc:subject>Health & Daily Living</dc:subject>
<dc:subject>Substance Abuse</dc:subject>
</metadata>
<guide/>
</package>
Running the BASH noscript via Cygwin, but I can move to a Linux box.
I Googled it, but the Stack Overflow threads I got don't mention this scenario, at least not that I saw. My Shell capabilities aren't that strong.
https://redd.it/12v1lo6
@r_bash
sleep in while clause
Hello,
i found a noscript where there is sleep () inside done clause, i am not sure... but from my point of view its pure mess?
​
while [[ something \]\]; do
.....
sleep X;
done << (sleep Y);
​
does it make any sense to use 2 times sleep and especially inside done clause...
​
​
thanks!
https://redd.it/12v4cu7
@r_bash
Hello,
i found a noscript where there is sleep () inside done clause, i am not sure... but from my point of view its pure mess?
​
while [[ something \]\]; do
.....
sleep X;
done << (sleep Y);
​
does it make any sense to use 2 times sleep and especially inside done clause...
​
​
thanks!
https://redd.it/12v4cu7
@r_bash
Reddit
r/bash on Reddit: sleep in while clause
Posted by u/phearr - No votes and 2 comments
Cool bash CLI for optimizing your development productivity on Git and other things
This a bash CLI I have been developing in my spare time. It provides developers with the ability for optimising the execution of commonly performed tasks, commands, directory navigations, and environment setups/noscript executions.
https://github.com/hwixley/WIX-CLI
Please check it out, and leave a star if you found it useful! (it helps me out alot) :)
https://redd.it/12vascj
@r_bash
This a bash CLI I have been developing in my spare time. It provides developers with the ability for optimising the execution of commonly performed tasks, commands, directory navigations, and environment setups/noscript executions.
https://github.com/hwixley/WIX-CLI
Please check it out, and leave a star if you found it useful! (it helps me out alot) :)
https://redd.it/12vascj
@r_bash
GitHub
GitHub - hwixley/WIX-CLI: Customisable bash CLI for optimising your development workflow and productivity
Customisable bash CLI for optimising your development workflow and productivity - GitHub - hwixley/WIX-CLI: Customisable bash CLI for optimising your development workflow and productivity
Why does this work??
I am not a programmer - I like to tinker.
I needed to batch process all file name in a folder all files having the naming convention as follows
3. 3. 2023-03-14 p.1 teaching.mp3
3. 3. 2023-03-14 p.2 discussion.mp3
etc
I needed to remove all characters upto the 2023 and keep the remaining string from 2023 to the end.
​
Here's the noscript(which I run in the folder it needs to operate):
1 For file in * ; do
2 if [[ -f “$file” ]]; then
3 upto=“2023”
4 result=$(echo “$file” | sed “s/^.*$upto/$upto/“) // this works
5 result=$(echo “$file” | sed “s/^.*$upto//“) // this does not work
6 echo $result
7 fi
8 Done
When I use the noscript with line 5 it does not work
But it works with line 4
Any idea why??
https://redd.it/12vigo6
@r_bash
I am not a programmer - I like to tinker.
I needed to batch process all file name in a folder all files having the naming convention as follows
3. 3. 2023-03-14 p.1 teaching.mp3
3. 3. 2023-03-14 p.2 discussion.mp3
etc
I needed to remove all characters upto the 2023 and keep the remaining string from 2023 to the end.
​
Here's the noscript(which I run in the folder it needs to operate):
1 For file in * ; do
2 if [[ -f “$file” ]]; then
3 upto=“2023”
4 result=$(echo “$file” | sed “s/^.*$upto/$upto/“) // this works
5 result=$(echo “$file” | sed “s/^.*$upto//“) // this does not work
6 echo $result
7 fi
8 Done
When I use the noscript with line 5 it does not work
But it works with line 4
Any idea why??
https://redd.it/12vigo6
@r_bash
Reddit
r/bash on Reddit: Why does this work??
Posted by u/redwisdomlight - No votes and 1 comment
I wrote a small utility to merge my dashcam recordings automatically using Bash, RFC!
https://github.com/brlin-tw/dashcam-recording-automerge
https://redd.it/12w2n1y
@r_bash
https://github.com/brlin-tw/dashcam-recording-automerge
https://redd.it/12w2n1y
@r_bash
GitHub
GitHub - brlin-tw/dashcam-recording-automerge: Automatic merging dashcam recordings that are named in a specific fashion
Automatic merging dashcam recordings that are named in a specific fashion - GitHub - brlin-tw/dashcam-recording-automerge: Automatic merging dashcam recordings that are named in a specific fashion
How to interact with the history of the shell that the noscript is being executed?
I've found several ways but none seem to work, the closest I got is one where I got output from the commands run by the own noscript but not from the shell. I've also tried #!/bin/bash -i, set -o, looking into \~/.bash_history... that last one seemed to work, but it didn't. I want to have the same output that I'd have when I type "history" on the terminal.
https://redd.it/12wq567
@r_bash
I've found several ways but none seem to work, the closest I got is one where I got output from the commands run by the own noscript but not from the shell. I've also tried #!/bin/bash -i, set -o, looking into \~/.bash_history... that last one seemed to work, but it didn't. I want to have the same output that I'd have when I type "history" on the terminal.
https://redd.it/12wq567
@r_bash
Reddit
r/bash on Reddit: How to interact with the history of the shell that the noscript is being executed?
Posted by u/Velascu - No votes and no comments
E: Could not lock file (13: Permission denied)
I'm trying to install Node JS on linux and I keep getting errors saying what I've described in the noscript, I've treied to fix it but I can't change the permission.
I'm on Pop_OS, if that is related to the very problem I'm getting.
Cheers.
https://redd.it/12xuekv
@r_bash
I'm trying to install Node JS on linux and I keep getting errors saying what I've described in the noscript, I've treied to fix it but I can't change the permission.
I'm on Pop_OS, if that is related to the very problem I'm getting.
Cheers.
https://redd.it/12xuekv
@r_bash
Reddit
r/bash on Reddit: E: Could not lock file (13: Permission denied)
Posted by u/AyoWasuup - No votes and no comments
How to one-line with & ?
Normally in a .sh file, I will write:
But when I do it in bash -c
It gives me an error:
How do I write it properly with bash -c?
https://redd.it/12xuacc
@r_bash
Normally in a .sh file, I will write:
sleep 1000 &
echo 'Say this now'
But when I do it in bash -c
bash -c "sleep 1000 & ; echo 'say this now'"
It gives me an error:
error near unexpected token `;'
How do I write it properly with bash -c?
https://redd.it/12xuacc
@r_bash
Reddit
r/bash on Reddit: How to one-line with & ?
Posted by u/freedomisfreed - No votes and 4 comments
Garbage characters appearing in terminal output when using 'watch'
So, when I run the following bash command, my terminal output file gets filled with a lot of random garbage between the data I am looking for.
watch -t -n 1 'sensors k10temp-pci-00c3 -j | jq '..Tccd1.temp3input'' >> output.txt
> \[?1049h \[22;0;0t \[1;51r (B \[m \[4l \[?7h \[H \[2J46 \[51;193H \[H44 \[51;
What's causing this? Are console control characters being injected into my output file? How can I stop this?
It only happens when I run the command with watch. Running just:
sensors k10temp-pci-00c3 -j | jq '.[].Tccd1.temp3input'' >> output.txt
yields me
>45.25
>
>47.75
>
>44.75
>
>44.5
>
>48.75
as expected.
https://redd.it/12xyje3
@r_bash
So, when I run the following bash command, my terminal output file gets filled with a lot of random garbage between the data I am looking for.
watch -t -n 1 'sensors k10temp-pci-00c3 -j | jq '..Tccd1.temp3input'' >> output.txt
> \[?1049h \[22;0;0t \[1;51r (B \[m \[4l \[?7h \[H \[2J46 \[51;193H \[H44 \[51;
What's causing this? Are console control characters being injected into my output file? How can I stop this?
It only happens when I run the command with watch. Running just:
sensors k10temp-pci-00c3 -j | jq '.[].Tccd1.temp3input'' >> output.txt
yields me
>45.25
>
>47.75
>
>44.75
>
>44.5
>
>48.75
as expected.
https://redd.it/12xyje3
@r_bash
Reddit
r/bash on Reddit: Garbage characters appearing in terminal output when using 'watch'
Posted by u/nshire - No votes and no comments
Sed and Regex question
Hi everyone! I have a brief question regarding sed and regex that's been bothering me for the better part of a day. I'm not the most experienced with Bash and this little problem has been taking much longer than planned.
I have a set of text files containing strings with a decimal and 1-3 digits at the end (ex. RMNT000021.55) I need to remove all the decimals and everything after the decimal (to get RMNT000021).
So far, I've tried to use:
sed -E 's/\.+:digit:+/ /g'
# Wanted something to grab the period and 1+ digits after it
# but the end result is a space where the period was
RMNT000021 55
# And the command below I tried just does more or less the same.
sed "s/\..//"
I've checked on forums but haven't had much luck. Would anyone be able to help me?
https://redd.it/12xuvr9
@r_bash
Hi everyone! I have a brief question regarding sed and regex that's been bothering me for the better part of a day. I'm not the most experienced with Bash and this little problem has been taking much longer than planned.
I have a set of text files containing strings with a decimal and 1-3 digits at the end (ex. RMNT000021.55) I need to remove all the decimals and everything after the decimal (to get RMNT000021).
So far, I've tried to use:
sed -E 's/\.+:digit:+/ /g'
# Wanted something to grab the period and 1+ digits after it
# but the end result is a space where the period was
RMNT000021 55
# And the command below I tried just does more or less the same.
sed "s/\..//"
I've checked on forums but haven't had much luck. Would anyone be able to help me?
https://redd.it/12xuvr9
@r_bash
Reddit
r/bash on Reddit: Sed and Regex question
Posted by u/Rich_Technology8456 - No votes and 2 comments
Syntax error near unexpected token in "while IFS= read" loop
I have a noscript that hundreds of people have used without any issue but yesterday one user has reported they are getting the following error:
syntax error near unexpected token <' synohdddb.sh: line 612: done < <(printf "%s\0" "${hdlist@}" | sort -uz)
The part of the noscript giving the error is:
while IFS= read -r -d '' x; do
hdds+=("$x")
done < <(printf "%s\0" "${hdlist@}" | sort -uz)
What could cause a syntax error in that while loop for 1 person but not for hundreds of other people?
This person does only have 1 HDD but I've tested with just 1 HDD and I could not reproduce the error.
Here's the noscript minus the irrelevant parts. The error in this short noscript occurs on line 53 https://gist.github.com/007revad/e7ca1c185f593b2d93cccf5bd0ccd0c2
In case anyone wants to see the full noscript it is here:: https://github.com/007revad/Synology\_HDD\_db
https://redd.it/12y1wb1
@r_bash
I have a noscript that hundreds of people have used without any issue but yesterday one user has reported they are getting the following error:
syntax error near unexpected token <' synohdddb.sh: line 612: done < <(printf "%s\0" "${hdlist@}" | sort -uz)
The part of the noscript giving the error is:
while IFS= read -r -d '' x; do
hdds+=("$x")
done < <(printf "%s\0" "${hdlist@}" | sort -uz)
What could cause a syntax error in that while loop for 1 person but not for hundreds of other people?
This person does only have 1 HDD but I've tested with just 1 HDD and I could not reproduce the error.
Here's the noscript minus the irrelevant parts. The error in this short noscript occurs on line 53 https://gist.github.com/007revad/e7ca1c185f593b2d93cccf5bd0ccd0c2
In case anyone wants to see the full noscript it is here:: https://github.com/007revad/Synology\_HDD\_db
https://redd.it/12y1wb1
@r_bash
Gist
test.sh
GitHub Gist: instantly share code, notes, and snippets.
Hey, Guys just need your small help!
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/12y7ppm
@r_bash
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/12y7ppm
@r_bash
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/browsinghistory.txt"
echo "Last Visit Time: $date" >> "$extr/browsinghistory.txt"
echo "" >> "$extr/browsinghistory.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
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/browsinghistory.txt"
echo "Last Visit Time: $date" >> "$extr/browsinghistory.txt"
echo "" >> "$extr/browsinghistory.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
RegEx
Guys pls recommend some RegEx books in context of bash noscripting.
https://redd.it/12yclt8
@r_bash
Guys pls recommend some RegEx books in context of bash noscripting.
https://redd.it/12yclt8
@r_bash
Reddit
r/bash on Reddit: RegEx
Posted by u/hashtag_raunak - No votes and no comments