...i know ...quite useless, but: ...why not watch /dev/video per bash script ? ;-P
https://redd.it/1s6gif6
@r_bash
https://redd.it/1s6gif6
@r_bash
How to improve bash script which is collecting data every 10 seconds
I wrote a script which is collecting data from solar inverter every 10 seconds for 5 minutes, it does some math and send data to [emoncms](https://github.com/emoncms/emoncms). It does work but is not optimal in term of CPU usage, it is running on SBC and consume roughly 80% of CPU time. My question is how can I initiate next data collection without checking script running time in a loop. Below is simplified script. I need to improve line 7.
#!/bin/bash
set -o pipefail
IFS=$''
samples="0"
nr="0"
while [ $SECONDS -lt 292 ]; do #5min-8s
if [[ (( $(( (samples - 1) * 10 + 10 )) == $SECONDS )) || (( 0 == $SECONDS )) ]]; then
((samples++))
timestart=$SECONDS
output="$(./inverter_poller --run-once)" # get data from inverter
timeend=$SECONDS
echo ${output} > /var/log/inverter.last
rs232time=$((timeend - timestart)) # usually it is 6-7 seconds
if (( rs232time < 17 )); # inverter is not responding if it is 17s or more
then
gridv=`echo ${output} | grep grid_voltage | tr -d " "_\",:[:alpha:]`
***more data extraction and math***
else
echo inverter not responding >> /var/log/inverter.last
fi
looptime=$((SECONDS - timestart))
echo "time": $looptime >> /var/log/inverter.last
fi
done
***boring data processing and sending to emoncms was here***
https://redd.it/1s6dsf2
@r_bash
I wrote a script which is collecting data from solar inverter every 10 seconds for 5 minutes, it does some math and send data to [emoncms](https://github.com/emoncms/emoncms). It does work but is not optimal in term of CPU usage, it is running on SBC and consume roughly 80% of CPU time. My question is how can I initiate next data collection without checking script running time in a loop. Below is simplified script. I need to improve line 7.
#!/bin/bash
set -o pipefail
IFS=$''
samples="0"
nr="0"
while [ $SECONDS -lt 292 ]; do #5min-8s
if [[ (( $(( (samples - 1) * 10 + 10 )) == $SECONDS )) || (( 0 == $SECONDS )) ]]; then
((samples++))
timestart=$SECONDS
output="$(./inverter_poller --run-once)" # get data from inverter
timeend=$SECONDS
echo ${output} > /var/log/inverter.last
rs232time=$((timeend - timestart)) # usually it is 6-7 seconds
if (( rs232time < 17 )); # inverter is not responding if it is 17s or more
then
gridv=`echo ${output} | grep grid_voltage | tr -d " "_\",:[:alpha:]`
***more data extraction and math***
else
echo inverter not responding >> /var/log/inverter.last
fi
looptime=$((SECONDS - timestart))
echo "time": $looptime >> /var/log/inverter.last
fi
done
***boring data processing and sending to emoncms was here***
https://redd.it/1s6dsf2
@r_bash
GitHub
GitHub - emoncms/emoncms: Web-app for processing, logging and visualising energy, temperature and other environmental data
Web-app for processing, logging and visualising energy, temperature and other environmental data - emoncms/emoncms
Function on .bashrc
Hello! I trying to add this function on my bashrc, but because of the quotes and single quotes, it's returning this error:
\-bash: .bashrc: line 142: unexpected EOF while looking for matching `''
\-bash: .bashrc: line 145: syntax error: unexpected end of file
The function is this one:
140 dwdb() {
141 local query="SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME;"
142 sqlcmd -S link -d table -U user -P 'password' -C -Q "$query"
143 }
https://redd.it/1s5emg1
@r_bash
Hello! I trying to add this function on my bashrc, but because of the quotes and single quotes, it's returning this error:
\-bash: .bashrc: line 142: unexpected EOF while looking for matching `''
\-bash: .bashrc: line 145: syntax error: unexpected end of file
The function is this one:
140 dwdb() {
141 local query="SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME;"
142 sqlcmd -S link -d table -U user -P 'password' -C -Q "$query"
143 }
https://redd.it/1s5emg1
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Exact timing of $PS0 and $BASHCOMMAND
I've had this line at the bottom of my ~/.bashrc for a while:
trap 'test "$BASHCOMMAND" == "$PROMPTCOMMAND" && printf "\e]2;$PWD\a" || printf "\e]2;$BASHCOMMAND\a"' DEBUG ;;
It uses a DEBUG trap to print the running command ($BASHCOMMAND) to the terminal emulator's title bar or else print the working directory ($PWD) if nothing is executing. I know some terminal emulators do this for you, but my favorite (urxvt) does not.
This has worked very well for me, but I recently learned about the $PS0 prompt, which is also run before the command executes, like a DEBUG trap, and I thought it might be a better way to implement this same thing.
It doesn't seem to be working, though, and I think the issue is in the timing of when $PS0 is shown and when $BASHCOMMAND is updated. When I add:
PS0="[\e]2;$BASHCOMMAND\a\]"
in my ~/.bashrc, the string in the terminal's title bar does update, but it's always one command behind (and the first is an odd test command). Is there any solution to this, like a way to update the $BASHCOMMAND sooner or an alternative way to get the command (from
Or is the way I've already been doing this with the DEBUG trap likely still the best? I've always wondered how inefficient that is. It's all builtins, so I would hope not very, but I'm not too sure.
https://redd.it/1s4cx2x
@r_bash
I've had this line at the bottom of my ~/.bashrc for a while:
trap 'test "$BASHCOMMAND" == "$PROMPTCOMMAND" && printf "\e]2;$PWD\a" || printf "\e]2;$BASHCOMMAND\a"' DEBUG ;;
It uses a DEBUG trap to print the running command ($BASHCOMMAND) to the terminal emulator's title bar or else print the working directory ($PWD) if nothing is executing. I know some terminal emulators do this for you, but my favorite (urxvt) does not.
This has worked very well for me, but I recently learned about the $PS0 prompt, which is also run before the command executes, like a DEBUG trap, and I thought it might be a better way to implement this same thing.
It doesn't seem to be working, though, and I think the issue is in the timing of when $PS0 is shown and when $BASHCOMMAND is updated. When I add:
PS0="[\e]2;$BASHCOMMAND\a\]"
in my ~/.bashrc, the string in the terminal's title bar does update, but it's always one command behind (and the first is an odd test command). Is there any solution to this, like a way to update the $BASHCOMMAND sooner or an alternative way to get the command (from
readline maybe?).Or is the way I've already been doing this with the DEBUG trap likely still the best? I've always wondered how inefficient that is. It's all builtins, so I would hope not very, but I'm not too sure.
https://redd.it/1s4cx2x
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Functions from my bashrc
My list of functions has gotten pretty long, thought maybe I'd share, [as asked](https://www.reddit.com/r/bash/comments/1s3lo2t/comment/ocgkhi1/). Share some interesting functions of your own, or any feedback you think I could use.
\>> [bashrc excerpt gist](https://gist.github.com/ekipan/1c2e5a6164fbe7601b32e089d889994c), and [permalink at time of post](https://gist.github.com/ekipan/1c2e5a6164fbe7601b32e089d889994c/adac6cb830131238a3666390d7574ec8a95f15be)
# a few of them:
e() { echo >&2 "$@"; "$@"; } # echo and run
hl() { bat -Ppl "${1:-help}"; } # highlight eg: find --help | hl
iftty() { if [[ -t "$1" ]]; then "${@:2}"; else cat; fi; }
opts() { iftty 0 "$@" --help |& rg "^\s*-" | hl; } # eg: opts find
# see gist for the rest.
A few I use _constantly_: gits() h() opts(). A ps1() that puts a newline if the last command didn't, so my prompt is on the left margin while scrolling back. A bit of whimsy like q() that I [adapted from a reddit post](https://www.reddit.com/r/zsh/comments/1rs6gcn/). I like the interface I designed for the path() function but since I only used it exactly once in my bashrc I just took it back out.
My style is definitely a lot more dense and nongeneric than most people or LLMs would like, but I own these functions and dense, direct code is better IMO.
**Background:** After my old Windows Thinkpad started getting a bit sick, I switched to using my Steam Deck as my main PC, with a dock, TV, and bluetooth keyboard. It seems a pretty good Arch flavor, and I wasn't entirely new to Linux, but I've learned a lot. One pain point is lack of manpages, so one of the first things I put in my .bashrc was a bunch of aliases to open my browser or curl from <https://cheat.sh>.
I had a ten-year-old account ended up shadowbanned, presumably because I posted a bashrc excerpt with URLs in it, maybe also because I'd forgotten about the account for years, idk. Thus the pastebin: I'm wary of posting too much code directly.
https://redd.it/1s3u7f5
@r_bash
My list of functions has gotten pretty long, thought maybe I'd share, [as asked](https://www.reddit.com/r/bash/comments/1s3lo2t/comment/ocgkhi1/). Share some interesting functions of your own, or any feedback you think I could use.
\>> [bashrc excerpt gist](https://gist.github.com/ekipan/1c2e5a6164fbe7601b32e089d889994c), and [permalink at time of post](https://gist.github.com/ekipan/1c2e5a6164fbe7601b32e089d889994c/adac6cb830131238a3666390d7574ec8a95f15be)
# a few of them:
e() { echo >&2 "$@"; "$@"; } # echo and run
hl() { bat -Ppl "${1:-help}"; } # highlight eg: find --help | hl
iftty() { if [[ -t "$1" ]]; then "${@:2}"; else cat; fi; }
opts() { iftty 0 "$@" --help |& rg "^\s*-" | hl; } # eg: opts find
# see gist for the rest.
A few I use _constantly_: gits() h() opts(). A ps1() that puts a newline if the last command didn't, so my prompt is on the left margin while scrolling back. A bit of whimsy like q() that I [adapted from a reddit post](https://www.reddit.com/r/zsh/comments/1rs6gcn/). I like the interface I designed for the path() function but since I only used it exactly once in my bashrc I just took it back out.
My style is definitely a lot more dense and nongeneric than most people or LLMs would like, but I own these functions and dense, direct code is better IMO.
**Background:** After my old Windows Thinkpad started getting a bit sick, I switched to using my Steam Deck as my main PC, with a dock, TV, and bluetooth keyboard. It seems a pretty good Arch flavor, and I wasn't entirely new to Linux, but I've learned a lot. One pain point is lack of manpages, so one of the first things I put in my .bashrc was a bunch of aliases to open my browser or curl from <https://cheat.sh>.
I had a ten-year-old account ended up shadowbanned, presumably because I posted a bashrc excerpt with URLs in it, maybe also because I'd forgotten about the account for years, idk. Thus the pastebin: I'm wary of posting too much code directly.
https://redd.it/1s3u7f5
@r_bash
Reddit
ekipan85's comment on "`-x () { local -; set -x; "$@"; }`"
Explore this conversation and more from the bash community
-x () { local -; set -x; "$@"; }Exhibit A in the case for "some kludges are good kludges".
https://redd.it/1s3lo2t
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Could someone please review my scripting and give me criticism?
I made a script to manage my dotfiles on linux (arch btw).
Link to repo
https://codeberg.org/Flan-Angel/Dawtfiles/src/branch/main
Link to script
https://codeberg.org/Flan-Angel/Dawtfiles/src/branch/main/PushToSYS.sh
Tysm if you do end up checking it out :)
https://redd.it/1s42scy
@r_bash
I made a script to manage my dotfiles on linux (arch btw).
Link to repo
https://codeberg.org/Flan-Angel/Dawtfiles/src/branch/main
Link to script
https://codeberg.org/Flan-Angel/Dawtfiles/src/branch/main/PushToSYS.sh
Tysm if you do end up checking it out :)
https://redd.it/1s42scy
@r_bash
Terminal Native API Testing Tool is LIVE!
https://preview.redd.it/gq2fehb401sg1.png?width=1233&format=png&auto=webp&s=84566c1673098db1088664090ad091e0c01a3a0d
Hey guys!
Rust based API Testing Tool is now live,
# Y'all can download it from here: Volt
This is a minimalistic API testing tool right in the terminal itself which has a blazingly fast response window. It scans source files and lists every route instantly — axum, express, fastapi, next.js, and more so that you do not need to write the Endpoints or Base URLs manually.
Do check it out and let me know your thoughts.
The Binaries are available for MacOS, Linux, and Windows on the website. Feel free to drop issues if you find any.
https://redd.it/1s72ksw
@r_bash
https://preview.redd.it/gq2fehb401sg1.png?width=1233&format=png&auto=webp&s=84566c1673098db1088664090ad091e0c01a3a0d
Hey guys!
Rust based API Testing Tool is now live,
# Y'all can download it from here: Volt
This is a minimalistic API testing tool right in the terminal itself which has a blazingly fast response window. It scans source files and lists every route instantly — axum, express, fastapi, next.js, and more so that you do not need to write the Endpoints or Base URLs manually.
Do check it out and let me know your thoughts.
The Binaries are available for MacOS, Linux, and Windows on the website. Feel free to drop issues if you find any.
https://redd.it/1s72ksw
@r_bash