Overwritten bashprofile?
I think I accidentally overwrote my bashprofile when I tried to add a path for something. I wrote something like export PATH=something and then I saved it. Now none of my commands work in my bash (emulator, for windows) terminal. I'm not sure what to do? Please make answers beginner friendly.
https://redd.it/1bfqf9q
@r_bash
I think I accidentally overwrote my bashprofile when I tried to add a path for something. I wrote something like export PATH=something and then I saved it. Now none of my commands work in my bash (emulator, for windows) terminal. I'm not sure what to do? Please make answers beginner friendly.
https://redd.it/1bfqf9q
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
I'm currently working on customizing my terminal under ~/.bashrc but I stuck on how can i replace the slash seperating my directories with another character.
​
https://preview.redd.it/biv943fryooc1.png?width=651&format=png&auto=webp&s=0cd17aaa81f51241bdbab419de836d38f45d2cbd
https://preview.redd.it/xzxkdizfyooc1.png?width=1816&format=png&auto=webp&s=972964fbf1bd40094a28ed5dc95c309b7e8de1c9
https://redd.it/1bg578x
@r_bash
​
https://preview.redd.it/biv943fryooc1.png?width=651&format=png&auto=webp&s=0cd17aaa81f51241bdbab419de836d38f45d2cbd
https://preview.redd.it/xzxkdizfyooc1.png?width=1816&format=png&auto=webp&s=972964fbf1bd40094a28ed5dc95c309b7e8de1c9
https://redd.it/1bg578x
@r_bash
SNMPGET, multiple OIDs, single line output with delimeter?
Hi, I am trying to pull together a noscript which will allow me to use snmpget to get multiple OID values and output to a CSV file with something like a comma as a delimeter. At the moment I have the following but this outputs to multiple lines:
​
​
This outputs as the following:
Any thoughts?
Thanks.
https://redd.it/1bg4rix
@r_bash
Hi, I am trying to pull together a noscript which will allow me to use snmpget to get multiple OID values and output to a CSV file with something like a comma as a delimeter. At the moment I have the following but this outputs to multiple lines:
#!/bin/bash​
### Synology VeriablesSynologyOID_Name='.1.3.6.1.2.1.1.5.0'SynologyOID_Model='.1.3.6.1.4.1.6574.1.5.1.0'SynologyOID_Serial='.1.3.6.1.4.1.6574.1.5.2.0'SynologyOID_Firmware='.1.3.6.1.4.1.6574.1.5.3.0'​
### Synology SNMPGETsnmpget -Oqv -v 2c -c 'public' `192.168.50.10` $SynologyOID_Name $SynologyOID_Model $SynologyOID_Serial $SynologyOID_Firmware | tr -d '"'This outputs as the following:
DS415PlusDS415+1512MIN750113DSM 7.1-42962Any thoughts?
Thanks.
https://redd.it/1bg4rix
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Share & Improve: A Bash Script for Streamlining Math Calculations
Hey everyone,
I've put together a bash noscript aimed at simplifying a wide array of math calculations. From quick percentage figures to solving algebraic equations, this tool is designed to help those who prefer working within the terminal or need a quick, noscriptable solution to common math problems. It's a project born out of a desire to assist and provide value to our community.
# Script Highlights:
Broad Coverage: Includes calculations for percentages, geometry, algebra, and more.
User-Friendly: Offers a straightforward selection menu for different formulas, designed with ease of use in mind.
# I Need Your Insight:
This noscript isn't just for me; it's for all of us. I'm reaching out to you for two main reasons:
Efficiency and Optimization: If you have suggestions on how to make the noscript run smoother or cleaner, I'm all ears.
Expanding the Toolkit: I want this to be as useful as possible. If there's a calculation you find yourself needing that's not included, let me know. Let's build something great together.
# Why This Matters:
I believe in the power of sharing knowledge and tools. This noscript is a small contribution to that ethos. It's about more than just solving equations; it's about empowering each other with the resources to tackle our challenges more efficiently. I believe there are people, especially students, who could benefit from a noscript like this.
# Contribute:
Whether it's suggesting new features, optimizing current ones, or just sharing your thoughts on the approach, your input is invaluable. This noscript is open for improvement, and with your help, we can make it an even more useful resource for everyone.
I look forward to seeing your feedback.
GitHub Script
https://redd.it/1bgjjx5
@r_bash
Hey everyone,
I've put together a bash noscript aimed at simplifying a wide array of math calculations. From quick percentage figures to solving algebraic equations, this tool is designed to help those who prefer working within the terminal or need a quick, noscriptable solution to common math problems. It's a project born out of a desire to assist and provide value to our community.
# Script Highlights:
Broad Coverage: Includes calculations for percentages, geometry, algebra, and more.
User-Friendly: Offers a straightforward selection menu for different formulas, designed with ease of use in mind.
# I Need Your Insight:
This noscript isn't just for me; it's for all of us. I'm reaching out to you for two main reasons:
Efficiency and Optimization: If you have suggestions on how to make the noscript run smoother or cleaner, I'm all ears.
Expanding the Toolkit: I want this to be as useful as possible. If there's a calculation you find yourself needing that's not included, let me know. Let's build something great together.
# Why This Matters:
I believe in the power of sharing knowledge and tools. This noscript is a small contribution to that ethos. It's about more than just solving equations; it's about empowering each other with the resources to tackle our challenges more efficiently. I believe there are people, especially students, who could benefit from a noscript like this.
# Contribute:
Whether it's suggesting new features, optimizing current ones, or just sharing your thoughts on the approach, your input is invaluable. This noscript is open for improvement, and with your help, we can make it an even more useful resource for everyone.
I look forward to seeing your feedback.
GitHub Script
https://redd.it/1bgjjx5
@r_bash
GitHub
noscript-repo/Bash/Misc/math-formula-solver.sh at main · slyfox1186/noscript-repo
My personal noscript repository with multiple languages supported. AHK v1+v2 | BASH | BATCH | JSON | PERL | POWERSHELL | PYTHON | WINDOWS REGISTRY | XML - slyfox1186/noscript-repo
Your go-to companion for Unix file operations
https://github.com/thesarfo/link
https://redd.it/1bgl0ee
@r_bash
https://github.com/thesarfo/link
https://redd.it/1bgl0ee
@r_bash
GitHub
GitHub - thesarfo/link: your go-to companion for unix file operations
your go-to companion for unix file operations. Contribute to thesarfo/link development by creating an account on GitHub.
Writing some bash noscripts to check and restart Emby server on Devuan 5 as soon as it closes...
Hello to everyone.
I'm trying to keep up one Emby server on my ARM Chromebook arm 32 bit aka SNOW. The real problem is that it is able to be up only for some time and then closes. To fix this problem,I've created a couple of bash noscripts that act as a sentinel. As soon as it goes down,they detect it and they try to restart the process. I created 3 bash noscripts that should do the trick :
check-emby :
while :
do
if pgrep Emby > /dev/null
then
echo "Emby Server is running..."
sleep 10s
else
echo "Emby Server is not running...but now it will run again"
/opt/emby-server/bin/./emby-server &
fi
done
check-check-emby :
while :
do
if pgrep Emby > /dev/null
then
echo "Emby Server is running..."
sleep 10s
else
echo "Emby Server is not running...but now it will run again"
/opt/emby-server/bin/./check-emby &
fi
done
This is what happens when "emby-server &" is invoked :
# ps ax | grep emby
9202 pts/1 Sl+ 1:06 /opt/emby-server/system/EmbyServer
-programdata /var/lib/emby -ffdetect /opt/emby-server/bin/ffdetect
-ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe
-restartexitcode 3 -updatepackage emby-server-deb{version}armhf.deb
I had to create two bash noscripts because when EmbyServer stops working,even check-emby closes. I don't understand why. Inside my sick mind the check-check-emby noscript should restart both. I don't know if it will work. For the moment it is still up and running.
Well. I have a couple of questions to ask you :
1. Can you imagine a better method than mine to achieve the same goal ?
2. Do you think that it will work ? I ask this because Emby is not yet closed by itself. It did the first time and it didn't work (but at that time I hadn't created the check-check-emby noscript). I have already checked what happens if I close it by myself. It works. But I want to see what happens if it naturally closes.
3. When Emby closes I would like to hear a beep coming from the Chromebook and I would like that it is produced by the bash noscript.
Can you help me ? thanks.
https://redd.it/1bh0gzd
@r_bash
Hello to everyone.
I'm trying to keep up one Emby server on my ARM Chromebook arm 32 bit aka SNOW. The real problem is that it is able to be up only for some time and then closes. To fix this problem,I've created a couple of bash noscripts that act as a sentinel. As soon as it goes down,they detect it and they try to restart the process. I created 3 bash noscripts that should do the trick :
check-emby :
while :
do
if pgrep Emby > /dev/null
then
echo "Emby Server is running..."
sleep 10s
else
echo "Emby Server is not running...but now it will run again"
/opt/emby-server/bin/./emby-server &
fi
done
check-check-emby :
while :
do
if pgrep Emby > /dev/null
then
echo "Emby Server is running..."
sleep 10s
else
echo "Emby Server is not running...but now it will run again"
/opt/emby-server/bin/./check-emby &
fi
done
This is what happens when "emby-server &" is invoked :
# ps ax | grep emby
9202 pts/1 Sl+ 1:06 /opt/emby-server/system/EmbyServer
-programdata /var/lib/emby -ffdetect /opt/emby-server/bin/ffdetect
-ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe
-restartexitcode 3 -updatepackage emby-server-deb{version}armhf.deb
I had to create two bash noscripts because when EmbyServer stops working,even check-emby closes. I don't understand why. Inside my sick mind the check-check-emby noscript should restart both. I don't know if it will work. For the moment it is still up and running.
Well. I have a couple of questions to ask you :
1. Can you imagine a better method than mine to achieve the same goal ?
2. Do you think that it will work ? I ask this because Emby is not yet closed by itself. It did the first time and it didn't work (but at that time I hadn't created the check-check-emby noscript). I have already checked what happens if I close it by myself. It works. But I want to see what happens if it naturally closes.
3. When Emby closes I would like to hear a beep coming from the Chromebook and I would like that it is produced by the bash noscript.
Can you help me ? thanks.
https://redd.it/1bh0gzd
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to fix unbound variables?
I've been using the following noscript for several years without issues.
https://github.com/Cody-Learner/aurch/blob/main/aurch
When I try to implement
Trying to see how many unbound variables there are, I comment out line 23, and it fails on line 45 now. Comment out line 45 and 46, it still exits with
1) I don't understand why
2) I have no idea how to fix these unbound variables, because they work, without them the noscript would be broken, and they're obviously being set or the noscript would fail to work properly.
What am I not getting with "unbound variables" and possibly provide an alternate method to noscript a problematic lines for an example?
https://redd.it/1bh6fwj
@r_bash
I've been using the following noscript for several years without issues.
https://github.com/Cody-Learner/aurch/blob/main/aurch
When I try to implement
set -euo pipefail in the noscript, specifically the set -u exits with line 23: 2: unbound variable.Trying to see how many unbound variables there are, I comment out line 23, and it fails on line 45 now. Comment out line 45 and 46, it still exits with
line 45: package: unbound variable1) I don't understand why
set -u won't ignore line 45/46 being commented out. 2) I have no idea how to fix these unbound variables, because they work, without them the noscript would be broken, and they're obviously being set or the noscript would fail to work properly.
What am I not getting with "unbound variables" and possibly provide an alternate method to noscript a problematic lines for an example?
https://redd.it/1bh6fwj
@r_bash
GitHub
aurch/aurch at main · Cody-Learner/aurch
Sets up aurutils inside a chroot for building Arch Linux AUR packages. - Cody-Learner/aurch
How to play a beep when the emby server process die using a bash noscript.
Hello to everyone.
I'm trying to keep up one Emby server on my ARM Chromebook arm 32 bit aka SNOW where I have installed Devuan 5.
The real problem is that it is up only for some time and then it closes.
To fix this problem,I've added this line :
​
7:2345:respawn:/opt/emby-server/bin/emby-server
to /etc/inittab.
Furthermore,for the sake of my curiosity I would like to hear a beep when the emby server process dies. I tried some noscripts written in bash found on Internet,but none of them worked.
​
​
https://redd.it/1bheafr
@r_bash
Hello to everyone.
I'm trying to keep up one Emby server on my ARM Chromebook arm 32 bit aka SNOW where I have installed Devuan 5.
The real problem is that it is up only for some time and then it closes.
To fix this problem,I've added this line :
​
7:2345:respawn:/opt/emby-server/bin/emby-server
to /etc/inittab.
Furthermore,for the sake of my curiosity I would like to hear a beep when the emby server process dies. I tried some noscripts written in bash found on Internet,but none of them worked.
​
​
https://redd.it/1bheafr
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Pass arguments to other noscript
In bash noscript
su - usr -c "VAR1=text VAR2=text command --options"
I want if I call like
su - usr -c "VAR1=text VAR2=text command --options --outside-option outside-value"
So in noscript I changed line to
su - usr -c "VAR1=text VAR2=text command --options $@"
But that isn't working. command shows error like it is detecting
It is recommended to always surround
https://redd.it/1bhdx6b
@r_bash
In bash noscript
./noscript there is such linesu - usr -c "VAR1=text VAR2=text command --options"
I want if I call like
./noscript --outside-option outside-value then inside noscript will be called likesu - usr -c "VAR1=text VAR2=text command --options --outside-option outside-value"
So in noscript I changed line to
su - usr -c "VAR1=text VAR2=text command --options $@"
But that isn't working. command shows error like it is detecting
--outside-option without outside-value.It is recommended to always surround
$@ with quotes like "$@". Is that the cause for error? I can't see how to escape it properly inside quotes in the noscript.https://redd.it/1bhdx6b
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Command not Found in Script Only
Hi,
I recently starting learning bash. I thought to create a bash noscript to automate installing and configuring
Once it reach line 3, it says command not found: ollama and the noscript fails from that point. What could be the problem?
https://redd.it/1bhr4yi
@r_bash
Hi,
I recently starting learning bash. I thought to create a bash noscript to automate installing and configuring
ollama.#!/usr/bin/bash
curl -fsSL https://ollama.com/install.sh | sh // This is for installing ollama
ollama run llama2
touch Modelfile
// rest of file
Once it reach line 3, it says command not found: ollama and the noscript fails from that point. What could be the problem?
https://redd.it/1bhr4yi
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Securely Store API Key & Use Crontab
Hi, I have a bash noscript which requires an API key for SendGrid to send an email. I am planning on calling this noscript every 6hrs so adding to crontab.
What are the best practices for storing the API key? Obviously not in the noscript itself but I have read that environment variables is also not great and the fact that I want to call via crontab.
Thoughts? Thanks.
https://redd.it/1bhs5zh
@r_bash
Hi, I have a bash noscript which requires an API key for SendGrid to send an email. I am planning on calling this noscript every 6hrs so adding to crontab.
What are the best practices for storing the API key? Obviously not in the noscript itself but I have read that environment variables is also not great and the fact that I want to call via crontab.
Thoughts? Thanks.
https://redd.it/1bhs5zh
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
i am running rsync in a while loop and it isn't releasing when finished.
Everything runs as it should, but at the end of the program rsync isn't signalling that it is finished and the "Working" stays in an infinite loop until I shut it down. What am I missing? I should be simple enough, print out the stuff while the program runs, when finished, stop.
​
Edit: I have tried not using != 0, and using just the process itself, and there is the same issue
https://redd.it/1bhuqn4
@r_bash
Everything runs as it should, but at the end of the program rsync isn't signalling that it is finished and the "Working" stays in an infinite loop until I shut it down. What am I missing? I should be simple enough, print out the stuff while the program runs, when finished, stop.
​
RUN_RSYNC() { tput sc ; tput civis ; tput ed ; size=5 ; host=$1 ; dest=$2 ; declare exitcode ; printf '\t%s\r\t' "One moment. Checking destination drive..." ; while [[ $( rsync "${RSYNC_FLAGS[*]}" -- "${host}/" "${dest}" | sed "s/^/$(date +%m-%d-%Y_%H%M)\t>>\t" |& tee -a "${RSYNC_LOG}" ) != 0 ]] ; do unset i ; tput el ; printf '\r\tWorking' ; for (( i=1 ; i<="${size}" ; i++ )) ; do printf '%s' "." ; sleep 0.5 ; done ; printf '\r\tWorking' ; for (( i=1 ; i<="${size}" ; i++ )) ; do printf '%s' " " ; sleep 0.5 ; done ; printf '\r' ; done ; exitcode=$? ; return "${exitcode}" ; tput cnorm ; tput rc ; } ;Edit: I have tried not using != 0, and using just the process itself, and there is the same issue
https://redd.it/1bhuqn4
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
what are favorite commands in bash?
so i searched "what are favorite commands in bash?" in reddit and i was surprised to find that this question doesn't seem to have ever been asked in r/bash
so i wanted to take this opportunity, what are your favorite commands in the bash shell and why?
doesn't matter why you like them, or what their purpose is, just what are your flat out favorite commands and why?
thank you
https://redd.it/1biemu1
@r_bash
so i searched "what are favorite commands in bash?" in reddit and i was surprised to find that this question doesn't seem to have ever been asked in r/bash
so i wanted to take this opportunity, what are your favorite commands in the bash shell and why?
doesn't matter why you like them, or what their purpose is, just what are your flat out favorite commands and why?
thank you
https://redd.it/1biemu1
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Anyone know of a pure-bash hack to read 1 byte *before* a file denoscriptor's current byte offset?
Im trying to find a [better] solution to a very specific and unusual problem.
I have two processes using the same file. One is appending data to the end of this file
cat >>file &
The other is reading from the start of the file in chunks of `N` lines using
{ while true; do
...
mapfile [-t] -d $delim -n $N -u $fd A
...
done; } {fd}<file
Problem is that the reading process can occasionally "catch up" to the writing process while it is buffering data. When this happens it hits an EOF and returns, often in the middle of a line. The code this is in requires lines to be read as complete lines (not partial ones), making this a problem.
Unfortunately, `mapfile` (unlike `read`) does not change its exit status / return value depending on whether or not returned because you hit an EOF. As such, the only way ive thought of to detect this is to check if the last byte read was a `$delim` or not. Hense this question.
Any ideas? I have a working approach right now, but being able to, say, rewind the file denoscriptor 1 byte and then read 1 byte would be a considerably faster and more efficient solution. (this is going in my [forkrun](https://github.com/jkool702/forkrun/blob/main/forkrun.bash) utility, which I am always trying to make faster and more efficient).
Thanks in advance.
Side note: The ${fd} file denoscriptor cannot be closed between reads, as it is shared with other processes. ponly 1 process reads at a given time, but when 1 is done the next picks up where it left off, requiring the file denoscriptor to stay open. It could, perhaps, be locally overwritten for the current reading process though.
***
***
### CURRENT APPROACH
My current approach is typically to drop the `-t` from mapfile, then check if the last char of the last element in `A` is a `$delim`, and if not loop `read` until i hit one and append to the last element.
mapfile -d $delim -n $N -u $fd A
[[ "${A[-1]: -1}" == "$delim" ]] || {
until read -r -d $delim -u $fd; do
A[-1]+="$REPLY"
done
}
A=("${A%"$delim"}")
# note that `read` returns `false` if it hits an EOF (or times out) and `true` otherwise
I say "typically" because this doesnt work if the delimiter is a NULL, since bash drop's NULL's regardless if you use mapfile's `-t` flag. In this case I get the last byte read by figuring out the byte position using procfs, then using `dd` to skip to that byte position in the file and read 1 byte:
mapfile -t -d '' -n $N -u $fd A
read -r fd_pos </proc/self/fdinfo/$fd
fd_pos="${fd_pos%%$'\t'*}"
dd if=file bs=1 count=1 skip=$((fd_pos-1)) status=none | read -r -d '' || {
until read -r -d '' -u $fd; do
A[-1]+="$REPLY"
done
}
***
***
Id love to replace these both with something like
mapfile -t -d $delim -n $N -u $fd A
rewind_FD_1_byte $fd
read -r -n 1 -u $fd
[[ ${REPLY} ]] || {
until read -r -d $delim -u $fd; do
A[-1]+="$REPLY"
done
}
https://redd.it/1bilrb2
@r_bash
Im trying to find a [better] solution to a very specific and unusual problem.
I have two processes using the same file. One is appending data to the end of this file
cat >>file &
The other is reading from the start of the file in chunks of `N` lines using
{ while true; do
...
mapfile [-t] -d $delim -n $N -u $fd A
...
done; } {fd}<file
Problem is that the reading process can occasionally "catch up" to the writing process while it is buffering data. When this happens it hits an EOF and returns, often in the middle of a line. The code this is in requires lines to be read as complete lines (not partial ones), making this a problem.
Unfortunately, `mapfile` (unlike `read`) does not change its exit status / return value depending on whether or not returned because you hit an EOF. As such, the only way ive thought of to detect this is to check if the last byte read was a `$delim` or not. Hense this question.
Any ideas? I have a working approach right now, but being able to, say, rewind the file denoscriptor 1 byte and then read 1 byte would be a considerably faster and more efficient solution. (this is going in my [forkrun](https://github.com/jkool702/forkrun/blob/main/forkrun.bash) utility, which I am always trying to make faster and more efficient).
Thanks in advance.
Side note: The ${fd} file denoscriptor cannot be closed between reads, as it is shared with other processes. ponly 1 process reads at a given time, but when 1 is done the next picks up where it left off, requiring the file denoscriptor to stay open. It could, perhaps, be locally overwritten for the current reading process though.
***
***
### CURRENT APPROACH
My current approach is typically to drop the `-t` from mapfile, then check if the last char of the last element in `A` is a `$delim`, and if not loop `read` until i hit one and append to the last element.
mapfile -d $delim -n $N -u $fd A
[[ "${A[-1]: -1}" == "$delim" ]] || {
until read -r -d $delim -u $fd; do
A[-1]+="$REPLY"
done
}
A=("${A%"$delim"}")
# note that `read` returns `false` if it hits an EOF (or times out) and `true` otherwise
I say "typically" because this doesnt work if the delimiter is a NULL, since bash drop's NULL's regardless if you use mapfile's `-t` flag. In this case I get the last byte read by figuring out the byte position using procfs, then using `dd` to skip to that byte position in the file and read 1 byte:
mapfile -t -d '' -n $N -u $fd A
read -r fd_pos </proc/self/fdinfo/$fd
fd_pos="${fd_pos%%$'\t'*}"
dd if=file bs=1 count=1 skip=$((fd_pos-1)) status=none | read -r -d '' || {
until read -r -d '' -u $fd; do
A[-1]+="$REPLY"
done
}
***
***
Id love to replace these both with something like
mapfile -t -d $delim -n $N -u $fd A
rewind_FD_1_byte $fd
read -r -n 1 -u $fd
[[ ${REPLY} ]] || {
until read -r -d $delim -u $fd; do
A[-1]+="$REPLY"
done
}
https://redd.it/1bilrb2
@r_bash
GitHub
forkrun/forkrun.bash at main · jkool702/forkrun
runs multiple inputs through a noscript/function in parallel using bash coprocs - jkool702/forkrun
get return code of command in new process
hello
im currently writing (or rather improving) a noscript i wrote in bash. its basically an alarm timer, that automatically pauses media playback, so you can actually hear the notification sound. over the time i included more features, the latest being the option to launch a program, when the timer is finished.
i want the noscript to continue after launching the progam and display a notification if launching fails.
the way i solved it is this
( eval "$command" || info_window "command '${command}' could not be executed" ) &
but i am not content with this, since the or statement also runs in the new process. however i couldnt find a way to get this right. yesterday i tried to find a solution, but i wasnt really successful.
i thought something like this
eval "$command" &
wait $! || info_window "command '${command}' could not be executed"
could be the solution, but its not. wait does what it says, it waits until the program is finished. i wanna get the return code, not the exit code.
i would really like to find a clean solution, but the only other option i could think of is creating a tempfile
( eval "$command" || temp=$(mktemp) ) &
[[ -f "$temp" ]] && info_window "command '${command}' could not be executed"
this should work i think, i didnt actually try it yet. theres got to be a cleaner solution for this!
thanks in advance
https://redd.it/1biqz5b
@r_bash
hello
im currently writing (or rather improving) a noscript i wrote in bash. its basically an alarm timer, that automatically pauses media playback, so you can actually hear the notification sound. over the time i included more features, the latest being the option to launch a program, when the timer is finished.
i want the noscript to continue after launching the progam and display a notification if launching fails.
the way i solved it is this
( eval "$command" || info_window "command '${command}' could not be executed" ) &
but i am not content with this, since the or statement also runs in the new process. however i couldnt find a way to get this right. yesterday i tried to find a solution, but i wasnt really successful.
i thought something like this
eval "$command" &
wait $! || info_window "command '${command}' could not be executed"
could be the solution, but its not. wait does what it says, it waits until the program is finished. i wanna get the return code, not the exit code.
i would really like to find a clean solution, but the only other option i could think of is creating a tempfile
( eval "$command" || temp=$(mktemp) ) &
[[ -f "$temp" ]] && info_window "command '${command}' could not be executed"
this should work i think, i didnt actually try it yet. theres got to be a cleaner solution for this!
thanks in advance
https://redd.it/1biqz5b
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to kill a process identifying it with the maximum precision...
Hello.
I'm trying to create a menu to be able to connect to the gateways offered by the VPN provider that I use,in realtime,because this feature is not present for the FreeBSD users. I've almost finished the noscript. It works,but it needs only a little bit more refining. This is the structure that I use to select the gateways :
select opt in "${options[@]}"
do
case $opt in
"1. Cairo")
/usr/local/sbin/openvpn --cd /usr/local/etc/
openvpn --daemon openvpn --config /home/marietto/Desktop/
Files/Gateways/openvpn.conf
echo "Tryng to connect..." && sleep 3
VPN_IP="$(curl api.ipify.org)"
echo $PUBLIC_IP
echo $VPN_IP
if [ "${PUBLIC_IP}" = "${VPN_IP}" ]; then
echo "This gateway didn't work. Try another
one."
ps ax | grep openvpn
ps ax | grep openvpn | awk '{ print $1; }' |
xargs kill -9
else
echo "Now you are connected to Cairo."
fi
;;
This is what happens when I run it :
==> ./start-vpn
kill: 6281: No such process
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13 100 13 0 0 50 0 --:--:-- --:--:-- --:--:-- 50
1) 1. Cairo
Please enter your choice: 1
Tryng to connect...
This gateway didn't work. Try another one.
6287 - Ss 0:00,00 /usr/local/sbin/openvpn --cd /usr/local/etc/openvpn --daemon openvpn --config /
6291 1 R+ 0:00,00 grep openvpn (ggrep)
kill: 6293: No such process
I want to suppress this error : ---> kill: 6293: No such process
I think that it happens because this command :
ps ax | grep openvpn | awk '{ print $1; }' | xargs kill -9
should be modified because it kills the two processes above (6287 and 6291) but it should kill only the first one. Can someone help me ?
https://redd.it/1bix3a5
@r_bash
Hello.
I'm trying to create a menu to be able to connect to the gateways offered by the VPN provider that I use,in realtime,because this feature is not present for the FreeBSD users. I've almost finished the noscript. It works,but it needs only a little bit more refining. This is the structure that I use to select the gateways :
select opt in "${options[@]}"
do
case $opt in
"1. Cairo")
/usr/local/sbin/openvpn --cd /usr/local/etc/
openvpn --daemon openvpn --config /home/marietto/Desktop/
Files/Gateways/openvpn.conf
echo "Tryng to connect..." && sleep 3
VPN_IP="$(curl api.ipify.org)"
echo $PUBLIC_IP
echo $VPN_IP
if [ "${PUBLIC_IP}" = "${VPN_IP}" ]; then
echo "This gateway didn't work. Try another
one."
ps ax | grep openvpn
ps ax | grep openvpn | awk '{ print $1; }' |
xargs kill -9
else
echo "Now you are connected to Cairo."
fi
;;
This is what happens when I run it :
==> ./start-vpn
kill: 6281: No such process
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13 100 13 0 0 50 0 --:--:-- --:--:-- --:--:-- 50
1) 1. Cairo
Please enter your choice: 1
Tryng to connect...
This gateway didn't work. Try another one.
6287 - Ss 0:00,00 /usr/local/sbin/openvpn --cd /usr/local/etc/openvpn --daemon openvpn --config /
6291 1 R+ 0:00,00 grep openvpn (ggrep)
kill: 6293: No such process
I want to suppress this error : ---> kill: 6293: No such process
I think that it happens because this command :
ps ax | grep openvpn | awk '{ print $1; }' | xargs kill -9
should be modified because it kills the two processes above (6287 and 6291) but it should kill only the first one. Can someone help me ?
https://redd.it/1bix3a5
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Favorite PS1 in .bashrc?
I read this post asking for people's favorite bash commands, and it got me thinking about what people like to use for their PS1. And the last time it was asked was 9 years ago (here), so there surely have to be newer ones people have created, right?
PS2 suggestions are obviously welcome as well.
https://redd.it/1bj3mm0
@r_bash
I read this post asking for people's favorite bash commands, and it got me thinking about what people like to use for their PS1. And the last time it was asked was 9 years ago (here), so there surely have to be newer ones people have created, right?
PS2 suggestions are obviously welcome as well.
https://redd.it/1bj3mm0
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Help with automation noscript!
Hello guys! I am trying to make an automated installer for my tool, I have only 2 problems.
​
function configurervm() {
createcwuser
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
export rvmpath="$HOME/.rvm"
source /etc/profile.d/rvm.sh
adduser folder rvm
}
function setupfolder() {
local secret=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 63 ; echo '')
local RAILSENV=production
getpgpass
sudo -i -u folder << EOF
rvm --version
rvm autolibs disable
rvm install "ruby-3.2.2"
rvm use 3.2.2 --default
git clone https://gitlab.com/xxxx/xxxx.git folder
echo "GitLab login successful."
cd folder
git folder "$BRANCH"
bundle
yarn
cp .env.example .env
sed -i -e "/SECRETKEYBASE/ s/=.*/=$secret/" .env
sed -i -e '/REDISURL/ s/=./=redis:\/\/localhost:6379/' .env
sed -i -e '/POSTGRES_HOST/ s/=./=localhost/' .env
sed -i -e '/POSTGRESUSERNAME/ s/=.*/=folder/' .env
sed -i -e "/POSTGRESPASSWORD/ s/=./=$pg_pass/" .env
sed -i -e '/RAILS_ENV/ s/=./=$RAILSENV/' .env
echo -en "\nINSTALLATIONENV=linuxnoscript" >> ".env"
rake assets:precompile RAILSENV=production NODEOPTIONS=--openssl-legacy-provider
EOF
}
this step source /etc/profile.d/rvm.shThe other problem I have, something exactly similar happens to me... which is here:
​
function installdependencies() {
apt update && apt upgrade -y
apt list --upgradable -a
apt --fix-broken install
apt install -y curl gnupg gnupg1 gnupg2
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb signed-by=/usr/share/keyrings/redis-archive-keyring.gpg https://packages.redis.io/deb $(lsbrelease -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODEMAJOR=20
echo "deb signed-by=/etc/apt/keyrings/nodesource.gpg https://deb.nodesource.com/node$NODEMAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
apt update
apt install -y \
git software-properties-common ca-certificates imagemagick libpq-dev \
libxml2-dev libxslt1-dev file g++ gcc autoconf build-essential \
libssl-dev libyaml-dev libreadline-dev gnupg2 \
postgresql-client redis-tools \
nodejs yarn patch ruby-dev zlib1g-dev liblzma-dev \
libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev sudo \
libvips python3-pip
}
once it is finishing it throws spanpd firefox pkg error... but here again if I manually run the apt --fix-broken install and run the noscript again everything works perfectly... this apt --fix I already have -broken install in the noscript but it doesn't seem to run.
https://redd.it/1bj2s55
@r_bash
Hello guys! I am trying to make an automated installer for my tool, I have only 2 problems.
​
function configurervm() {
createcwuser
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
export rvmpath="$HOME/.rvm"
source /etc/profile.d/rvm.sh
adduser folder rvm
}
function setupfolder() {
local secret=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 63 ; echo '')
local RAILSENV=production
getpgpass
sudo -i -u folder << EOF
rvm --version
rvm autolibs disable
rvm install "ruby-3.2.2"
rvm use 3.2.2 --default
git clone https://gitlab.com/xxxx/xxxx.git folder
echo "GitLab login successful."
cd folder
git folder "$BRANCH"
bundle
yarn
cp .env.example .env
sed -i -e "/SECRETKEYBASE/ s/=.*/=$secret/" .env
sed -i -e '/REDISURL/ s/=./=redis:\/\/localhost:6379/' .env
sed -i -e '/POSTGRES_HOST/ s/=./=localhost/' .env
sed -i -e '/POSTGRESUSERNAME/ s/=.*/=folder/' .env
sed -i -e "/POSTGRESPASSWORD/ s/=./=$pg_pass/" .env
sed -i -e '/RAILS_ENV/ s/=./=$RAILSENV/' .env
echo -en "\nINSTALLATIONENV=linuxnoscript" >> ".env"
rake assets:precompile RAILSENV=production NODEOPTIONS=--openssl-legacy-provider
EOF
}
this step source /etc/profile.d/rvm.shThe other problem I have, something exactly similar happens to me... which is here:
​
function installdependencies() {
apt update && apt upgrade -y
apt list --upgradable -a
apt --fix-broken install
apt install -y curl gnupg gnupg1 gnupg2
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb signed-by=/usr/share/keyrings/redis-archive-keyring.gpg https://packages.redis.io/deb $(lsbrelease -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODEMAJOR=20
echo "deb signed-by=/etc/apt/keyrings/nodesource.gpg https://deb.nodesource.com/node$NODEMAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
apt update
apt install -y \
git software-properties-common ca-certificates imagemagick libpq-dev \
libxml2-dev libxslt1-dev file g++ gcc autoconf build-essential \
libssl-dev libyaml-dev libreadline-dev gnupg2 \
postgresql-client redis-tools \
nodejs yarn patch ruby-dev zlib1g-dev liblzma-dev \
libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev sudo \
libvips python3-pip
}
once it is finishing it throws spanpd firefox pkg error... but here again if I manually run the apt --fix-broken install and run the noscript again everything works perfectly... this apt --fix I already have -broken install in the noscript but it doesn't seem to run.
https://redd.it/1bj2s55
@r_bash
Planetary hours in Shell Script
Greetings to all,
I have developed a Shell Script named AstroICON, a straightforward noscript that displays the weekday in relation to the planet and the planetary hour. I am sharing this code as I am aware that there are individuals in this community who are engaged in astrology and utilize Linux. This noscript operates seamlessly on i3blocks and, I believe, should also function correctly on polybar.
To use it, the process is quite simple: grant execution permission with chmod +x AstroICON\_v1.2A.sh
. Then, set the variables for sunrise, sunset, and the following day's sunrise times in the 24-hour format. After these steps, you can run the noscript using ./AstroICON\_v1.2A.sh
. It is worth noting that the noscript accepts parameters from 1 to 8, and if no parameter is provided, it automatically determines the current day and planetary hour.
If anyone is interested in enhancing the noscript, please feel free to do so; just get in touch. Warm regards to everyone.
Below is the code:
#!/bin/bash
# Configuration section: Enables or disables functionality for each day of the week and for the planetary hours chart.
# Set to 1 to enable or 0 to disable the functionality for the respective day or feature.
#IMPORTANT (The day variables must not exceed line 15): this version of the program is automatic and uses sed to configure the variables according to the day of the week, it does not require manual configuration, only the sunrise, sunset and next sunrise times must be configured manually.
MONDAY_MOON_=0
TUESDAY_MARS_=0
WEDNESDAY_MERCURY_=0
THURSDAY_JUPITER_=0
FRIDAY_VENUS_=0
SATURDAY_SATURN_=0
SUNDAY_SUN_=0
PLANETARY_HOURS_CHART_=0
# The name defined by the FILE variable must be the same as the file name
FILE="AstroICON_v1.2A.sh"
# Variable to control the display of the current day's planet symbol.
DAY_OF_WEEK_=1
# Time configuration: Define sunrise and sunset times in 24-hour format.
HOUR_SUNRISE="06"
MINUTES_SUNRISE="11"
HOUR_SUNSET="18"
MINUTES_SUNSET="30"
HOUR_SUNRISE_OF_NEXT_DAY="06"
MINUTES_SUNRISE_OF_NEXT_DAY="11"
# Planet symbols: Assigns icons for each planet.
MOON="☽"
MARS="♂"
MERCURY="☿"
JUPITER="♃"
VENUS="♀"
SATURN="♄"
SUN="☉"
# always resets variables to 0
sed -i '1,15s/MONDAY_MOON_=1/MONDAY_MOON_=0/' "$FILE"
sed -i '1,15s/TUESDAY_MARS_=1/TUESDAY_MARS_=0/' "$FILE"
sed -i '1,15s/WEDNESDAY_MERCURY_=1/WEDNESDAY_MERCURY_=0/' "$FILE"
sed -i '1,15s/THURSDAY_JUPITER_=1/THURSDAY_JUPITER_=0/' "$FILE"
sed -i '1,15s/FRIDAY_VENUS_=1/FRIDAY_VENUS_=1/' "$FILE"
sed -i '1,15s/SATURDAY_SATURN_=1/SATURDAY_SATURN_=0/' "$FILE"
sed -i '1,15s/SUNDAY_SUN_=1/SUNDAY_SUN_=0/' "$FILE"
# Conditional reset: Checks if any command-line argument is passed and resets the configuration.
if [[ $# -gt 0 ]]; then
MONDAY_MOON_=0
TUESDAY_MARS_=0
WEDNESDAY_MERCURY_=0
THURSDAY_JUPITER_=0
FRIDAY_VENUS_=0
SATURDAY_SATURN_=0
SUNDAY_SUN_=0
PLANETARY_HOURS_CHART_=0
DAY_OF_WEEK_=0
fi
# Total minutes in a day
TOTAL_MINUTES_IN_DAY=1440
# Convert sunrise and sunset times to total minutes from midnight
MINUTES_SUNRISE_TOTAL=$((HOUR_SUNRISE * 60 + MINUTES_SUNRISE))
MINUTES_SUNSET_TOTAL=$((HOUR_SUNSET * 60 + MINUTES_SUNSET))
# Calculate total daylight minutes
DAYLIGHT_MINUTES=$((MINUTES_SUNSET_TOTAL - MINUTES_SUNRISE_TOTAL))
# Calculate daylight period per hour
DAYLIGHT_PERIOD=$((DAYLIGHT_MINUTES / 12))
# Calculate total night minutes
# Note: This calculation assumes that the sunrise of the next day is the end of the night period
MINUTES_SUNRISE_NEXT_DAY_TOTAL=$((HOUR_SUNRISE_OF_NEXT_DAY * 60 + MINUTES_SUNRISE_OF_NEXT_DAY))
NIGHT_MINUTES=$((TOTAL_MINUTES_IN_DAY - MINUTES_SUNSET_TOTAL + MINUTES_SUNRISE_NEXT_DAY_TOTAL))
# Calculate night period per hour
NIGHT_PERIOD=$((NIGHT_MINUTES /
Greetings to all,
I have developed a Shell Script named AstroICON, a straightforward noscript that displays the weekday in relation to the planet and the planetary hour. I am sharing this code as I am aware that there are individuals in this community who are engaged in astrology and utilize Linux. This noscript operates seamlessly on i3blocks and, I believe, should also function correctly on polybar.
To use it, the process is quite simple: grant execution permission with chmod +x AstroICON\_v1.2A.sh
. Then, set the variables for sunrise, sunset, and the following day's sunrise times in the 24-hour format. After these steps, you can run the noscript using ./AstroICON\_v1.2A.sh
. It is worth noting that the noscript accepts parameters from 1 to 8, and if no parameter is provided, it automatically determines the current day and planetary hour.
If anyone is interested in enhancing the noscript, please feel free to do so; just get in touch. Warm regards to everyone.
Below is the code:
#!/bin/bash
# Configuration section: Enables or disables functionality for each day of the week and for the planetary hours chart.
# Set to 1 to enable or 0 to disable the functionality for the respective day or feature.
#IMPORTANT (The day variables must not exceed line 15): this version of the program is automatic and uses sed to configure the variables according to the day of the week, it does not require manual configuration, only the sunrise, sunset and next sunrise times must be configured manually.
MONDAY_MOON_=0
TUESDAY_MARS_=0
WEDNESDAY_MERCURY_=0
THURSDAY_JUPITER_=0
FRIDAY_VENUS_=0
SATURDAY_SATURN_=0
SUNDAY_SUN_=0
PLANETARY_HOURS_CHART_=0
# The name defined by the FILE variable must be the same as the file name
FILE="AstroICON_v1.2A.sh"
# Variable to control the display of the current day's planet symbol.
DAY_OF_WEEK_=1
# Time configuration: Define sunrise and sunset times in 24-hour format.
HOUR_SUNRISE="06"
MINUTES_SUNRISE="11"
HOUR_SUNSET="18"
MINUTES_SUNSET="30"
HOUR_SUNRISE_OF_NEXT_DAY="06"
MINUTES_SUNRISE_OF_NEXT_DAY="11"
# Planet symbols: Assigns icons for each planet.
MOON="☽"
MARS="♂"
MERCURY="☿"
JUPITER="♃"
VENUS="♀"
SATURN="♄"
SUN="☉"
# always resets variables to 0
sed -i '1,15s/MONDAY_MOON_=1/MONDAY_MOON_=0/' "$FILE"
sed -i '1,15s/TUESDAY_MARS_=1/TUESDAY_MARS_=0/' "$FILE"
sed -i '1,15s/WEDNESDAY_MERCURY_=1/WEDNESDAY_MERCURY_=0/' "$FILE"
sed -i '1,15s/THURSDAY_JUPITER_=1/THURSDAY_JUPITER_=0/' "$FILE"
sed -i '1,15s/FRIDAY_VENUS_=1/FRIDAY_VENUS_=1/' "$FILE"
sed -i '1,15s/SATURDAY_SATURN_=1/SATURDAY_SATURN_=0/' "$FILE"
sed -i '1,15s/SUNDAY_SUN_=1/SUNDAY_SUN_=0/' "$FILE"
# Conditional reset: Checks if any command-line argument is passed and resets the configuration.
if [[ $# -gt 0 ]]; then
MONDAY_MOON_=0
TUESDAY_MARS_=0
WEDNESDAY_MERCURY_=0
THURSDAY_JUPITER_=0
FRIDAY_VENUS_=0
SATURDAY_SATURN_=0
SUNDAY_SUN_=0
PLANETARY_HOURS_CHART_=0
DAY_OF_WEEK_=0
fi
# Total minutes in a day
TOTAL_MINUTES_IN_DAY=1440
# Convert sunrise and sunset times to total minutes from midnight
MINUTES_SUNRISE_TOTAL=$((HOUR_SUNRISE * 60 + MINUTES_SUNRISE))
MINUTES_SUNSET_TOTAL=$((HOUR_SUNSET * 60 + MINUTES_SUNSET))
# Calculate total daylight minutes
DAYLIGHT_MINUTES=$((MINUTES_SUNSET_TOTAL - MINUTES_SUNRISE_TOTAL))
# Calculate daylight period per hour
DAYLIGHT_PERIOD=$((DAYLIGHT_MINUTES / 12))
# Calculate total night minutes
# Note: This calculation assumes that the sunrise of the next day is the end of the night period
MINUTES_SUNRISE_NEXT_DAY_TOTAL=$((HOUR_SUNRISE_OF_NEXT_DAY * 60 + MINUTES_SUNRISE_OF_NEXT_DAY))
NIGHT_MINUTES=$((TOTAL_MINUTES_IN_DAY - MINUTES_SUNSET_TOTAL + MINUTES_SUNRISE_NEXT_DAY_TOTAL))
# Calculate night period per hour
NIGHT_PERIOD=$((NIGHT_MINUTES /