How to start with this problem
Hello guys
​
So I have these 4 variables:
A=40
B=50
C=60
Z=100
If I would try to calculate/addition Variable A, B, and C together. Which combination would bring me to the nearest Value of Variable Z, without exceeding the value of Variable Z.
So the answer obviously would be A + C.
How would I do this in a bash noscript? I don't even know how to start because I don't understand the algorithm behind. What would you guys call this problem?
Thank you all!
https://redd.it/zxh3a0
@r_bash
Hello guys
​
So I have these 4 variables:
A=40
B=50
C=60
Z=100
If I would try to calculate/addition Variable A, B, and C together. Which combination would bring me to the nearest Value of Variable Z, without exceeding the value of Variable Z.
So the answer obviously would be A + C.
How would I do this in a bash noscript? I don't even know how to start because I don't understand the algorithm behind. What would you guys call this problem?
Thank you all!
https://redd.it/zxh3a0
@r_bash
reddit
How to start with this problem
Hello guys So I have these 4 variables: A=40 B=50 C=60 Z=100 If I would try to calculate/addition Variable A, B, and C together....
Help with Bash Script
Here is what we currently have and the output:
Any advice would be amazing
Script:
u/echo off
if exist membership.txt del membership.txt
dsquery group -name *splk* >groups.txt
::The FOR command is one single line
for /f "tokens=*" %%g in (groups.txt) do u/echo %%g >>membership.txt && echo Members: >>membership.txt && dsget group %%g -members >>membership.txt && echo **************************************** >>membership.txt
Output
"CN=NERP-Splk-Admin,OU=splunk,OU=Security,OU=Group,DC=erp,DC=navy,DC=mil"
Members:
"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
****************************************
"CN=NERP-SPLK-Citrix,OU=splunk,OU=Security,OU=Group,DC=erp,DC=navy,DC=mil"
Members:
"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
****************************************
​
What we want the output to look like:
"CN=NERP-Splk-Admin,OU=splunk,OU=Security,OU=Group,DC=erp,DC=navy,DC=mil"-"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
"CN=NERP-Splk-Admin,OU=splunk,OU=Security,OU=Group,DC=erp,DC=navy,DC=mil"-"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
"CN=NERP-SPLK-Citrix,OU=splunk,OU=Security,OU=Group,DC=erp,DC=navy,DC=mil"-"CN=Name ,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
"CN=NERP-SPLK-Citrix,OU=splunk,OU=Security,OU=Group,DC=erp,DC=navy,DC=mil"-"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
Etc.. we want the output on one line
https://redd.it/zxihr6
@r_bash
Here is what we currently have and the output:
Any advice would be amazing
Script:
u/echo off
if exist membership.txt del membership.txt
dsquery group -name *splk* >groups.txt
::The FOR command is one single line
for /f "tokens=*" %%g in (groups.txt) do u/echo %%g >>membership.txt && echo Members: >>membership.txt && dsget group %%g -members >>membership.txt && echo **************************************** >>membership.txt
Output
"CN=NERP-Splk-Admin,OU=splunk,OU=Security,OU=Group,DC=erp,DC=navy,DC=mil"
Members:
"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
****************************************
"CN=NERP-SPLK-Citrix,OU=splunk,OU=Security,OU=Group,DC=erp,DC=navy,DC=mil"
Members:
"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
****************************************
​
What we want the output to look like:
"CN=NERP-Splk-Admin,OU=splunk,OU=Security,OU=Group,DC=erp,DC=navy,DC=mil"-"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
"CN=NERP-Splk-Admin,OU=splunk,OU=Security,OU=Group,DC=erp,DC=navy,DC=mil"-"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
"CN=NERP-SPLK-Citrix,OU=splunk,OU=Security,OU=Group,DC=erp,DC=navy,DC=mil"-"CN=Name ,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
"CN=NERP-SPLK-Citrix,OU=splunk,OU=Security,OU=Group,DC=erp,DC=navy,DC=mil"-"CN=Name,OU=Users,OU=Accounts,DC=erp,DC=navy,DC=mil"
Etc.. we want the output on one line
https://redd.it/zxihr6
@r_bash
reddit
Help with Bash Script
Here is what we currently have and the output: Any advice would be amazing Script: u/echo off if exist membership.txt del...
(noscript request) automate your server to send this message after a successful backup, or after service restart
https://redd.it/zy57yi
@r_bash
https://redd.it/zy57yi
@r_bash
Comment-out (prefix with '#') every line in a file that is not already commented-out?
Hi everyone,
I am struggling for a couple of days with this one.
I cannot figure it out by myself and googling for hours on end did not help either.
What I am looking for:
There is a file, test.cfg for example.
It's contents:
lineone
\#linetwo
\#linethree
linefour
I want my noscript to do the following after executing it:
\#lineone
\#linetwo
\#linethree
\#linefour
Does anyone know a solution for this?
Thanks in advance
https://redd.it/zy8ztv
@r_bash
Hi everyone,
I am struggling for a couple of days with this one.
I cannot figure it out by myself and googling for hours on end did not help either.
What I am looking for:
There is a file, test.cfg for example.
It's contents:
lineone
\#linetwo
\#linethree
linefour
I want my noscript to do the following after executing it:
\#lineone
\#linetwo
\#linethree
\#linefour
Does anyone know a solution for this?
Thanks in advance
https://redd.it/zy8ztv
@r_bash
reddit
Comment-out (prefix with '#') every line in a file that is not...
Hi everyone, I am struggling for a couple of days with this one. I cannot figure it out by myself and googling for hours on end did not help...
Why I keep getting a nonsense value?
In the following noscript `p` and `q` are at least 2048 bit long numbers, when multiplying both values (`p`\*`q`) the product in this case `n` keeps giving a smaller value than the expected, instead of getting a 4096 bit value it returns a value around 160 bit long.
#!/bin/bash
generate_random() {
hex=$(head -c 256 /dev/urandom | xxd -p -u | tr -d '\n')
bc <<< "ibase=16; $hex"
}
p="$(generate_random | sed -z 's=\\\n==g')"
q="$(generate_random | sed -z 's=\\\n==g')"
n=$((p * q))
echo "$n"
What is causing this? How can I fix it?
https://redd.it/zyb6xv
@r_bash
In the following noscript `p` and `q` are at least 2048 bit long numbers, when multiplying both values (`p`\*`q`) the product in this case `n` keeps giving a smaller value than the expected, instead of getting a 4096 bit value it returns a value around 160 bit long.
#!/bin/bash
generate_random() {
hex=$(head -c 256 /dev/urandom | xxd -p -u | tr -d '\n')
bc <<< "ibase=16; $hex"
}
p="$(generate_random | sed -z 's=\\\n==g')"
q="$(generate_random | sed -z 's=\\\n==g')"
n=$((p * q))
echo "$n"
What is causing this? How can I fix it?
https://redd.it/zyb6xv
@r_bash
reddit
Why I keep getting a nonsense value?
In the following noscript `p` and `q` are at least 2048 bit long numbers, when multiplying both values (`p`\*`q`) the product in this case `n` keeps...
How can I tell when a forked process finishes?
Im trying to figure out a good and reliable way to fork processes off in a loop but limit the maximum number of "active" forked processes. right now I figure this out by keeping track of the number of started and completed forked processes (which means that every completed forked process needs to be accounted for, or else the count of currently active processes gets off). Currently, I use something like this:
p0=0 # number of started forked processes
p1=0 # number of finished forked processes
maxParallelThreads=$(nproc)
parFunc() {
# some function
sha256sum "$1"
}
# load inputs to parallelize over into array
mapfile -t inArgs < <(find ./ -type f)
for nn in "${inArgs@}"; do
parFunc "$nn" &
((p0++))
(( ( p0 - p1 ) >= maxParallelThreads )) && wait -nf && ((p1++))
done
The problem with this is that
Ive tried a number of ways to increment
The only thing Ive tried that seems like it might work is keeping
Any suggestions on how I might accomplish this? Thanks in advance.
https://redd.it/zypo1c
@r_bash
Im trying to figure out a good and reliable way to fork processes off in a loop but limit the maximum number of "active" forked processes. right now I figure this out by keeping track of the number of started and completed forked processes (which means that every completed forked process needs to be accounted for, or else the count of currently active processes gets off). Currently, I use something like this:
p0=0 # number of started forked processes
p1=0 # number of finished forked processes
maxParallelThreads=$(nproc)
parFunc() {
# some function
sha256sum "$1"
}
# load inputs to parallelize over into array
mapfile -t inArgs < <(find ./ -type f)
for nn in "${inArgs@}"; do
parFunc "$nn" &
((p0++))
(( ( p0 - p1 ) >= maxParallelThreads )) && wait -nf && ((p1++))
done
The problem with this is that
p1 (which counts the number of finished forked processes) only gets incremented if the process finishes while the wait -nf call is active. If it finishes in between wait -nf calls it doesnt get counted in p1, which makes (( p0 - p1 )) (which is the count of currently active forked processes) 1 higher than it should be. If you have a bunch of inputs this loop will slowly fork fewer and fewer processes simultaneously until it is only forking one at a time.Ive tried a number of ways to increment
p1 from within the forked process (modifying it normally, exporting it, etc.), but as best as I can tell bash wont allow this. That said, if anyone here knows how you can modify a variable in the parent shell from a forked process please do share.The only thing Ive tried that seems like it might work is keeping
p1 in a file (on a tmpfs), but im concerned about what would happen when multiple forked processes try to modify the file at the same time. I also could probably keep track on the pid's oof the started forked processes, and replace the wait -nf call with one that continually loops through checking that each process pid still exists until one of them doesnt, but that seems like a really inefficient and unsatisfying solution.Any suggestions on how I might accomplish this? Thanks in advance.
https://redd.it/zypo1c
@r_bash
reddit
How can I tell when a forked process finishes?
Im trying to figure out a good and reliable way to fork processes off in a loop but limit the maximum number of "active" forked processes. right...
bashrc inspiration - your favorit trick
I'm looking for inspiration for my bashrc to imporve interactive shell experience.
Especially I'm interesetd in smart completion, history and navigation hacks - everything that makes your life more easy. Feel free to also post gits of otheres that you learned from.
https://redd.it/zyxihb
@r_bash
I'm looking for inspiration for my bashrc to imporve interactive shell experience.
Especially I'm interesetd in smart completion, history and navigation hacks - everything that makes your life more easy. Feel free to also post gits of otheres that you learned from.
https://redd.it/zyxihb
@r_bash
reddit
bashrc inspiration - your favorit trick
I'm looking for inspiration for my bashrc to imporve interactive shell experience. Especially I'm interesetd in smart completion, history and...
Trying to make a noscript that find if multiple packages are installed.
I'm not having any luck getting it to work.
I clearly have the packages on my system but dnf is saying there are no matches.
​
Here is my noscript
https://preview.redd.it/0gtlgb51f29a1.png?width=1198&format=png&auto=webp&s=af0a166afbf586761cb28774d35e04ef2917997e
Here is my result
https://preview.redd.it/60m65a5af29a1.png?width=1196&format=png&auto=webp&s=67331b5872b423493c340262417987e261d33cd6
https://redd.it/zz5c87
@r_bash
I'm not having any luck getting it to work.
I clearly have the packages on my system but dnf is saying there are no matches.
​
Here is my noscript
https://preview.redd.it/0gtlgb51f29a1.png?width=1198&format=png&auto=webp&s=af0a166afbf586761cb28774d35e04ef2917997e
Here is my result
https://preview.redd.it/60m65a5af29a1.png?width=1196&format=png&auto=webp&s=67331b5872b423493c340262417987e261d33cd6
https://redd.it/zz5c87
@r_bash
Scripting and licensing - Do bash noscripts need a license?
I've noticed that some folks license their noscripts. Specifically, I recently found some licensed under the GPLv3.
This didn't make much sense to me, as the "Script" in question amounted to a number of bashisms, with common commands that could easily be run in the terminal.
I have no issue if someone wants to do that for convenvience, however, it's strange to me to license something that uses commands that everyone uses daily. I could understand licensing a complicated noscript with some functions and procedural steps, such as cloning a few git repos and building each. If something like that had some error correction and iteration, great.
Or if someone needed to combine custom regex, or parsing a file signature; maybe some complex math, etc.
What are your thoughts on licensing daily tasks in a noscript, as opposed to some original and specific code tailored to what might be a unqiue use case?
https://redd.it/zz61yl
@r_bash
I've noticed that some folks license their noscripts. Specifically, I recently found some licensed under the GPLv3.
This didn't make much sense to me, as the "Script" in question amounted to a number of bashisms, with common commands that could easily be run in the terminal.
I have no issue if someone wants to do that for convenvience, however, it's strange to me to license something that uses commands that everyone uses daily. I could understand licensing a complicated noscript with some functions and procedural steps, such as cloning a few git repos and building each. If something like that had some error correction and iteration, great.
Or if someone needed to combine custom regex, or parsing a file signature; maybe some complex math, etc.
What are your thoughts on licensing daily tasks in a noscript, as opposed to some original and specific code tailored to what might be a unqiue use case?
https://redd.it/zz61yl
@r_bash
reddit
Scripting and licensing - Do bash noscripts need a license?
I've noticed that some folks license their noscripts. Specifically, I recently found some licensed under the GPLv3. This didn't make much sense to...
How to use file for list of variables?
I've written noscript that checks when an item has come into stock and triggers a webhook to Discord to notify me. It does a CURL on the web page, GREPs for the 'Add to basket' button and uses the -c switch to return either 0 or 1 (for matched number of lines)
Presently I have the item URL defined as a variable at the top of the noscript, and for multiple items I just use multiple noscripts. I would like this to instead be called from a file with a list of URLs, one on each line. This would allow me to just
I am a newbie so go easy on me! Here is what I have at the moment, any advice appreciated
URL=https://www.com
DISCORDWEBHOOK=https://discord.com
STOCKCHECK=$(curl -s $URL | grep -c "Add to basket")
if "$STOCKCHECK" -eq "1" ; then
curl -X POST -H "Content-Type: application/json" -d '{"username":"Stock","content":"'$URL' IN STOCK - ORDER NOW"}' $DISCORDWEBHOOK;
fi
Thanks
https://redd.it/zz39y0
@r_bash
I've written noscript that checks when an item has come into stock and triggers a webhook to Discord to notify me. It does a CURL on the web page, GREPs for the 'Add to basket' button and uses the -c switch to return either 0 or 1 (for matched number of lines)
Presently I have the item URL defined as a variable at the top of the noscript, and for multiple items I just use multiple noscripts. I would like this to instead be called from a file with a list of URLs, one on each line. This would allow me to just
echo https://itemurl.com >> urlfile to add a new item, and just use a single noscript for multiple items.I am a newbie so go easy on me! Here is what I have at the moment, any advice appreciated
URL=https://www.com
DISCORDWEBHOOK=https://discord.com
STOCKCHECK=$(curl -s $URL | grep -c "Add to basket")
if "$STOCKCHECK" -eq "1" ; then
curl -X POST -H "Content-Type: application/json" -d '{"username":"Stock","content":"'$URL' IN STOCK - ORDER NOW"}' $DISCORDWEBHOOK;
fi
Thanks
https://redd.it/zz39y0
@r_bash
Discord
Discord - Group Chat That’s All Fun & Games
Discord is great for playing games and chilling with friends, or even building a worldwide community. Customize your own space to talk, play, and hang out.
Shell Scripting for Beginners – How to Write Bash Scripts in Linux
https://www.codelivly.com/shell-noscripting-for-beginners-how-to-write-bash-noscripts-in-linux/
https://redd.it/zz0ris
@r_bash
https://www.codelivly.com/shell-noscripting-for-beginners-how-to-write-bash-noscripts-in-linux/
https://redd.it/zz0ris
@r_bash
dyetide/dye - convert color codes from the terminal
Hi All!
I recently finished up a bash noscript project called dyetide/dye. dye is a simple utility that converts hex, rgb, and hsl color codes in the terminal. dyetide uses dye to search through a (css) file and convert said color codes throughout the whole file.
This was an educational project, I know there are better tools (python) out there that could have accomplished this. I just wanted to see what was possible with bash. It turned out...okay! Feel free to try it out. Constructive criticism and suggestions are always welcome, but this will probably be my last extensive bash noscript for a while, so don't expect much more work on this going forward (we'll see, I've come to really enjoy bash noscripting).
Special thanks are specified in the README, comments, and man pages. Thanks to all in r/bash that helped me hash out some of the details and made helpful suggestions along the way!
P.S. If you'd rather not get the noscript from github for some reason, here is the mirror repo on codeberg.
https://redd.it/zzlkdm
@r_bash
Hi All!
I recently finished up a bash noscript project called dyetide/dye. dye is a simple utility that converts hex, rgb, and hsl color codes in the terminal. dyetide uses dye to search through a (css) file and convert said color codes throughout the whole file.
This was an educational project, I know there are better tools (python) out there that could have accomplished this. I just wanted to see what was possible with bash. It turned out...okay! Feel free to try it out. Constructive criticism and suggestions are always welcome, but this will probably be my last extensive bash noscript for a while, so don't expect much more work on this going forward (we'll see, I've come to really enjoy bash noscripting).
Special thanks are specified in the README, comments, and man pages. Thanks to all in r/bash that helped me hash out some of the details and made helpful suggestions along the way!
P.S. If you'd rather not get the noscript from github for some reason, here is the mirror repo on codeberg.
https://redd.it/zzlkdm
@r_bash
GitHub
GitHub - tomit4/dyetide: a bash noscript that replaces hex, rgb, or hsl color codes out for other color codes. either within a file…
a bash noscript that replaces hex, rgb, or hsl color codes out for other color codes. either within a file or from the terminal! - GitHub - tomit4/dyetide: a bash noscript that replaces hex, rgb, or hs...
Bashop - A bash framework
I wrote a small bash framework a while ago (omg seven years passed 😅). Maybe it's useful for someone.
https://github.com/GM-Alex/bashop
https://redd.it/zzprwb
@r_bash
I wrote a small bash framework a while ago (omg seven years passed 😅). Maybe it's useful for someone.
https://github.com/GM-Alex/bashop
https://redd.it/zzprwb
@r_bash
GitHub
GitHub - GM-Alex/bashop: Bash framework to write bash applications, including argument parser and automated help pages.
Bash framework to write bash applications, including argument parser and automated help pages. - GitHub - GM-Alex/bashop: Bash framework to write bash applications, including argument parser and au...
I need to change this noscript so that if nothing is selected it stops
I have this noscript that I use to get a list of pdfs and view them in dmenu or fzf and then open the selected in Evince. The problem is that its gonna open Evince even if I don't select a noscript. I don't know how to fix it, I know its bound to be simple but I couldn't find anything in my bash bible.
I know that : means do nothing in bash but I have no idea how to tell the noscript that if the user didn't select anything do :
Thank you for your time and any help is appreciated.
https://redd.it/10051kd
@r_bash
I have this noscript that I use to get a list of pdfs and view them in dmenu or fzf and then open the selected in Evince. The problem is that its gonna open Evince even if I don't select a noscript. I don't know how to fix it, I know its bound to be simple but I couldn't find anything in my bash bible.
I know that : means do nothing in bash but I have no idea how to tell the noscript that if the user didn't select anything do :
Thank you for your time and any help is appreciated.
# List PDFs in given directory and opens selection in Evince
# Change to PDFs path
cd $HOME/Downloads/Documents/ || return
# List only the files with .pdf format
book=$(find . -name "*.pdf" | dmenu -p "Select Book")
# Open selected file in Evince
evince "$book" &
# Get terminal PPID and close terminal when the noscript is done
PPPID=$(awk '{print $4}' "/proc/$PPID/stat")
kill "$PPPID"
https://redd.it/10051kd
@r_bash
reddit
I need to change this noscript so that if nothing is selected it stops
I have this noscript that I use to get a list of pdfs and view them in dmenu or fzf and then open the selected in Evince. The problem is that its...
Anyone with bash get shopt -s lithist to work?
I'm running 4.4.12 under Cygwin (latest version as of this writing) and can't get lithist to work. cmdhist is also set.
Under Linux running bash 5.0.17 it works for that login session. If I log off then log back in, the multiline commands are broken out into different commands again.
https://redd.it/100jdbu
@r_bash
I'm running 4.4.12 under Cygwin (latest version as of this writing) and can't get lithist to work. cmdhist is also set.
Under Linux running bash 5.0.17 it works for that login session. If I log off then log back in, the multiline commands are broken out into different commands again.
https://redd.it/100jdbu
@r_bash
reddit
Anyone with bash get shopt -s lithist to work?
I'm running 4.4.12 under Cygwin (latest version as of this writing) and can't get lithist to work. cmdhist is also set. Under Linux running bash...
Standard or simplified way to pass all parameters of a function to a command
I have a few functions where I'd like to easily pass 0 or more arguments to a function and have those passed to a single command with quoting and escaping intact.
For example:
function useless()
{
less $*
}
But if I call:
useless 'this is first' 'this is second'
It effectively calls less with 6 arguments instead of two:
less this is first this is second
What I want is:
less 'this is first' 'this is second'
Of course I can write a loop in `useless()` to build the command line, but I'm wondering if there's something built-in I'm missing that would be simpler.
https://redd.it/100kev0
@r_bash
I have a few functions where I'd like to easily pass 0 or more arguments to a function and have those passed to a single command with quoting and escaping intact.
For example:
function useless()
{
less $*
}
But if I call:
useless 'this is first' 'this is second'
It effectively calls less with 6 arguments instead of two:
less this is first this is second
What I want is:
less 'this is first' 'this is second'
Of course I can write a loop in `useless()` to build the command line, but I'm wondering if there's something built-in I'm missing that would be simpler.
https://redd.it/100kev0
@r_bash
reddit
Standard or simplified way to pass all parameters of a function to...
I have a few functions where I'd like to easily pass 0 or more arguments to a function and have those passed to a single command with quoting and...
Bash noscripts for basic use.
I wrote some tiny bash :/(pure) to do terminal tasks.
Here it is https://github.com/codedsprit/bin
https://redd.it/100m5t2
@r_bash
I wrote some tiny bash :/(pure) to do terminal tasks.
Here it is https://github.com/codedsprit/bin
https://redd.it/100m5t2
@r_bash
GitHub
GitHub - codedsprit/bin: 🗑️ noscripts that i use in my daily basics
🗑️ noscripts that i use in my daily basics. Contribute to codedsprit/bin development by creating an account on GitHub.
[Help] Bash Array Question(s)
I'm parsing the content of a file or files. There will always be at least one (1), and up to four (4) of these files, ordered sequentially, e.g. **syno_mac_address1**, **syno_mac_address2**. The content of each file will always be a unique MAC address, e.g.: **001132623d3f**, **001132623d40**
Here's my approach to extracting these MAC addresses:
# GNU bash, version 4.4.23(1)-release (x86_64-pc-linux-gnu)
mac_address=( $(cat /proc/sys/kernel/syno_mac_address{1..4}))
and then printing these address:
for i in "${!mac_address[@]}"; do
printf '%s\n' "LAN $i ${mac_address[$i]}"
done
Here's sample output:
**LAN 0 001132623d3f**
**LAN 1 001132623d40**
This almost does what I'd like, except there's mismatch between the LAN number (the OS counts from `1`, **not** `0`). The desired output would be:
**LAN 1 001132623d3f**
**LAN 2 001132623d40**
But I'm not sure how to approach that. In addition, (ShellCheck)[shellcheck.net] complains about the way I declare the array, e.g.: **Prefer mapfile or read -a to split command output (or quote to avoid splitting)**, but the proposed solutions don't give me the output I expect.
I am also wondering if there's a more succinct way to handle this e.g.:
mac_address() {
MAC=$(cat /proc/sys/kernel/syno_mac_address{1..4})
printf "%s\n" "$MAC"
}
with some slight modification, e.g.: `printf '%s\n' "${mac_address[@]/LAN/ }"`. The problem I have there is that I am not sure how to add a count.
Thanks.
https://redd.it/100woy5
@r_bash
I'm parsing the content of a file or files. There will always be at least one (1), and up to four (4) of these files, ordered sequentially, e.g. **syno_mac_address1**, **syno_mac_address2**. The content of each file will always be a unique MAC address, e.g.: **001132623d3f**, **001132623d40**
Here's my approach to extracting these MAC addresses:
# GNU bash, version 4.4.23(1)-release (x86_64-pc-linux-gnu)
mac_address=( $(cat /proc/sys/kernel/syno_mac_address{1..4}))
and then printing these address:
for i in "${!mac_address[@]}"; do
printf '%s\n' "LAN $i ${mac_address[$i]}"
done
Here's sample output:
**LAN 0 001132623d3f**
**LAN 1 001132623d40**
This almost does what I'd like, except there's mismatch between the LAN number (the OS counts from `1`, **not** `0`). The desired output would be:
**LAN 1 001132623d3f**
**LAN 2 001132623d40**
But I'm not sure how to approach that. In addition, (ShellCheck)[shellcheck.net] complains about the way I declare the array, e.g.: **Prefer mapfile or read -a to split command output (or quote to avoid splitting)**, but the proposed solutions don't give me the output I expect.
I am also wondering if there's a more succinct way to handle this e.g.:
mac_address() {
MAC=$(cat /proc/sys/kernel/syno_mac_address{1..4})
printf "%s\n" "$MAC"
}
with some slight modification, e.g.: `printf '%s\n' "${mac_address[@]/LAN/ }"`. The problem I have there is that I am not sure how to add a count.
Thanks.
https://redd.it/100woy5
@r_bash
reddit
[Help] Bash Array Question(s)
I'm parsing the content of a file or files. There will always be at least one (1), and up to four (4) of these files, ordered sequentially, e.g....
Howto measure uptime of hosts in local network (lightweight)?
Hi,I'm looking for a simple lightweight tool that can measure hosts uptime in hours/minutes per day in my local network (I guess ping can be used for that). I'm just looking for a simple report (HostA: X hours/minutes up on Monday, etc...) The remote hosts are windows so Im looking for a solution that doesn't require running a client on the host.
I need to get insight in uptime hours per day on a few hosts in my network.I'm planning to use my Raspberry PI (running Rasbian/pihole) for that.
I have Nagios running now but that's not really reporting what I'm looking for (it's just polling every now and then).
Could you please advise what to use? I discovered 'monitorr' on the web but that was written for windows.
Thanks in advance for your help
https://redd.it/1019dra
@r_bash
Hi,I'm looking for a simple lightweight tool that can measure hosts uptime in hours/minutes per day in my local network (I guess ping can be used for that). I'm just looking for a simple report (HostA: X hours/minutes up on Monday, etc...) The remote hosts are windows so Im looking for a solution that doesn't require running a client on the host.
I need to get insight in uptime hours per day on a few hosts in my network.I'm planning to use my Raspberry PI (running Rasbian/pihole) for that.
I have Nagios running now but that's not really reporting what I'm looking for (it's just polling every now and then).
Could you please advise what to use? I discovered 'monitorr' on the web but that was written for windows.
Thanks in advance for your help
https://redd.it/1019dra
@r_bash
reddit
Howto measure uptime of hosts in local network (lightweight)?
Hi,I'm looking for a simple lightweight tool that can measure hosts uptime in hours/minutes per day in my local network (I guess ping can be used...
Script to delete specific files
I have a directory with the following files:
file1.txt
file1.txt.old
file2.txt.old
file3.txt
file3.txt.old
file4.txt.old
My goal is to write a noscript that deletes all
How can I achieve this with a bash noscript?
https://redd.it/1019c5d
@r_bash
I have a directory with the following files:
file1.txt
file1.txt.old
file2.txt.old
file3.txt
file3.txt.old
file4.txt.old
My goal is to write a noscript that deletes all
*.old files, except if there is a non-old file with the same name. So it would keep file1.txt, file1.txt.old, file3.txt, file3.txt.old in this example. The filenames can contain spaces and letters from A-Z (with accents).How can I achieve this with a bash noscript?
https://redd.it/1019c5d
@r_bash
reddit
Script to delete specific files
I have a directory with the following files: file1.txt file1.txt.old file2.txt.old file3.txt file3.txt.old ...