Looking for some guidance on how to tackle this problem with bash. Had a few ideas that I think can work but would like more experienced opinions.
Hello! For context to the noscript, I'm trying to make a bash noscript(s) that use the ncat util from nmap to capture data being streamed by a phone server, that part I've been able to accomplish no problem. I'm running into an issue when trying to take that data capture and output it to unique daily files, and having those files have only the output for that specific day.
The issues i've ran into are:
* if I move the file where ncat is being redirected to, it keeps appending to that same file even after renaming
* if I try to have the noscript running ncat change the file name to make new output file every day, no dice.
* using a cron job worked to an extent, in that scenario the ncat command was still putting everything in 1 big file and that was what was copied daily.
How would you approach something like this??
I've changed my noscripts around a lot and the concepts are pretty simple so I haven't pasted my code here in the post, but if you'd like to see some of it by all means just ask :)
One thought I had was to make the noscript running ncat in a way where it can be called by a cron job, the only issue I can see there is making sure the ncat process stops after the day's over.
https://redd.it/1gmlz4b
@r_bash
Hello! For context to the noscript, I'm trying to make a bash noscript(s) that use the ncat util from nmap to capture data being streamed by a phone server, that part I've been able to accomplish no problem. I'm running into an issue when trying to take that data capture and output it to unique daily files, and having those files have only the output for that specific day.
The issues i've ran into are:
* if I move the file where ncat is being redirected to, it keeps appending to that same file even after renaming
* if I try to have the noscript running ncat change the file name to make new output file every day, no dice.
* using a cron job worked to an extent, in that scenario the ncat command was still putting everything in 1 big file and that was what was copied daily.
How would you approach something like this??
I've changed my noscripts around a lot and the concepts are pretty simple so I haven't pasted my code here in the post, but if you'd like to see some of it by all means just ask :)
One thought I had was to make the noscript running ncat in a way where it can be called by a cron job, the only issue I can see there is making sure the ncat process stops after the day's over.
https://redd.it/1gmlz4b
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
What terminal app do you use on your Linux distro
Hello everyone,
I am a Mac user, and there is a long time I don't use a Linux distribution. My terminal app is iTerm2. What is the best replacement for iTerm on Linux distro, such as, Ubuntu/Fedora/Alpine ?
My requirements are 256xterm colors and font change ability.
Thanks.
https://redd.it/1gmmjcr
@r_bash
Hello everyone,
I am a Mac user, and there is a long time I don't use a Linux distribution. My terminal app is iTerm2. What is the best replacement for iTerm on Linux distro, such as, Ubuntu/Fedora/Alpine ?
My requirements are 256xterm colors and font change ability.
Thanks.
https://redd.it/1gmmjcr
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Article about Bash Strict Mode
I write an article about Bash Strict Mode.
I would love to hear your feedback:
https://github.com/guettli/bash-strict-mode
https://redd.it/1gmufop
@r_bash
I write an article about Bash Strict Mode.
I would love to hear your feedback:
https://github.com/guettli/bash-strict-mode
https://redd.it/1gmufop
@r_bash
GitHub
GitHub - guettli/bash-strict-mode: Bash Strict Mode
Bash Strict Mode. Contribute to guettli/bash-strict-mode development by creating an account on GitHub.
Filter video files by codec?
How to list and sort/move video files by codec?
Ideally just move all have/x265 files into a subfolder kinda thing.
I've just grabbed mediainfo and am prodding at but don't really know what I'm doing....I suspect with a little bash and some knowledge it should make this simple.
https://redd.it/1gmtgfb
@r_bash
How to list and sort/move video files by codec?
Ideally just move all have/x265 files into a subfolder kinda thing.
I've just grabbed mediainfo and am prodding at but don't really know what I'm doing....I suspect with a little bash and some knowledge it should make this simple.
https://redd.it/1gmtgfb
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
GitHub - helpermethod/up: Climbing the directory tree at the speed of thought.
https://github.com/helpermethod/up
https://redd.it/1gn7r6e
@r_bash
https://github.com/helpermethod/up
https://redd.it/1gn7r6e
@r_bash
GitHub
GitHub - helpermethod/up: Climbing the directory tree at the speed of light.
Climbing the directory tree at the speed of light. - helpermethod/up
Bash noscript to simplify finding Flatpaks via the command line
https://github.com/TDGalea/flatpak-finder
https://redd.it/1gnahqc
@r_bash
https://github.com/TDGalea/flatpak-finder
https://redd.it/1gnahqc
@r_bash
GitHub
GitHub - TDGalea/flatpak-finder: Super simple Bash noscript to save you typing out the entire application ID any time you want to…
Super simple Bash noscript to save you typing out the entire application ID any time you want to use Flatpak via the commandline. - TDGalea/flatpak-finder
I have written a utility to transcribe user-specified media files to subnoscripts using Bash
https://gitlab.com/brlin/media-to-whisper.cpp-subnoscripts
https://redd.it/1gnroro
@r_bash
https://gitlab.com/brlin/media-to-whisper.cpp-subnoscripts
https://redd.it/1gnroro
@r_bash
GitLab
林博仁 Buo-ren Lin / media-to-whisper.cpp-subnoscripts · GitLab
Converting user-specified media files to subnoscripts using the Whisper.cpp utility.
DirDiff: does anyone know to set depht to compare?
Hi, I'd like to use dirdiff with a degree of depht for compare 2 dirs. why? I have some heavy sub-dirs (with lots of pics, vids) and spend lot of time seeing into them! If I can set depht: bingo!
Thank you and regards!
https://redd.it/1goywp9
@r_bash
Hi, I'd like to use dirdiff with a degree of depht for compare 2 dirs. why? I have some heavy sub-dirs (with lots of pics, vids) and spend lot of time seeing into them! If I can set depht: bingo!
Thank you and regards!
https://redd.it/1goywp9
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Can I set bash to automatically start in POSIX mode?
Hi, stupid question: Can I set bash to automatically start in POSIX mode? Could this be done using chsh or .bashrc?
https://redd.it/1goz8x8
@r_bash
Hi, stupid question: Can I set bash to automatically start in POSIX mode? Could this be done using chsh or .bashrc?
https://redd.it/1goz8x8
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How can I replicate this ZSH prompt using Bash?
this is the code:
function fmt_ms() {
local total_ms=$1
local ms=$((total_ms % 1000))
local total_seconds=$((total_ms / 1000))
local seconds=$((total_seconds % 60))
local total_minutes=$((total_seconds / 60))
local minutes=$((total_minutes % 60))
local hours=$((total_minutes / 60))
local formatted=""
[[ $hours -gt 0 ]] && formatted+="${hours}h "
[[ $minutes -gt 0 ]] && formatted+="${minutes}min "
[[ $seconds -gt 0 ]] && formatted+="${seconds}s "
echo "$formatted"
}
function preexec() {
timer=$(($(date +%s%0N)/1000000))
}
function precmd() {
if [ $timer ]; then
now=$(($(date +%s%0N)/1000000))
elapsed="$(($now-$timer))"
formatted=$(fmt_ms $elapsed)
PROMPT="%(?.%F{green}%?%f.%F{red}%?%f) %F{blue}%1~%f %F{8}${formatted:+$formatted}%f%F{yellow}$%f "
unset timer
else
PROMPT="%(?.%F{green}%?%f.%F{red}%?%f) %F{blue}%1~%f %F{yellow}$%f "
fi
}
PROMPT="%(?.%F{green}%?%f.%F{red}%?%f) %F{blue}%1~%f %F{yellow}$%f "
it looks like this:
https://preview.redd.it/regotlo19d0e1.png?width=768&format=png&auto=webp&s=9ecf1f46e5ac9ea31f7442b88c4856b8cb5f98f6
From left to right it shows the status code of the last command, 0 is green, anything else is red, it shows the current directory in blue, the execution time of the last command in gray formatted with hours, minutes and seconds and finally a yellow dollar sign.
https://redd.it/1gp84d9
@r_bash
this is the code:
function fmt_ms() {
local total_ms=$1
local ms=$((total_ms % 1000))
local total_seconds=$((total_ms / 1000))
local seconds=$((total_seconds % 60))
local total_minutes=$((total_seconds / 60))
local minutes=$((total_minutes % 60))
local hours=$((total_minutes / 60))
local formatted=""
[[ $hours -gt 0 ]] && formatted+="${hours}h "
[[ $minutes -gt 0 ]] && formatted+="${minutes}min "
[[ $seconds -gt 0 ]] && formatted+="${seconds}s "
echo "$formatted"
}
function preexec() {
timer=$(($(date +%s%0N)/1000000))
}
function precmd() {
if [ $timer ]; then
now=$(($(date +%s%0N)/1000000))
elapsed="$(($now-$timer))"
formatted=$(fmt_ms $elapsed)
PROMPT="%(?.%F{green}%?%f.%F{red}%?%f) %F{blue}%1~%f %F{8}${formatted:+$formatted}%f%F{yellow}$%f "
unset timer
else
PROMPT="%(?.%F{green}%?%f.%F{red}%?%f) %F{blue}%1~%f %F{yellow}$%f "
fi
}
PROMPT="%(?.%F{green}%?%f.%F{red}%?%f) %F{blue}%1~%f %F{yellow}$%f "
it looks like this:
https://preview.redd.it/regotlo19d0e1.png?width=768&format=png&auto=webp&s=9ecf1f46e5ac9ea31f7442b88c4856b8cb5f98f6
From left to right it shows the status code of the last command, 0 is green, anything else is red, it shows the current directory in blue, the execution time of the last command in gray formatted with hours, minutes and seconds and finally a yellow dollar sign.
https://redd.it/1gp84d9
@r_bash
can I use mv (here only files) dir/
Hi, could I use any flag in command mv for only move files to destiny (a dir is destiny). Not recursive! just first level.
mv -¿...? dir/
= only files (with and without extension)
Thank you and Regards!
https://redd.it/1gp7um4
@r_bash
Hi, could I use any flag in command mv for only move files to destiny (a dir is destiny). Not recursive! just first level.
mv -¿...? dir/
= only files (with and without extension)
Thank you and Regards!
https://redd.it/1gp7um4
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to sequentially execute commands with a bash noscript?
I want to make a simple blocklet for i3's status bar to cycle through ddcutil "presets" for my monitor brightness. Basically, to make it execute the ddcutil command (
I'm fairly sure I'll need to make it read the current brightness value (that is reported with
https://redd.it/1gphkvb
@r_bash
I want to make a simple blocklet for i3's status bar to cycle through ddcutil "presets" for my monitor brightness. Basically, to make it execute the ddcutil command (
ddcutil set 10 100 ) with brightness values in a sequence like 100, 75, 50, 25, 0 (and wrap around after reaching 0) each time the noscript is executed. But I'm really new to bash and I'm not sure how do I do it. Is there an example available?I'm fairly sure I'll need to make it read the current brightness value (that is reported with
ddcutil getvcp 10 with the output looking like VCP code 0x10 (Brightness ): current value = 50, max value = 100 ) to decide which command should it execute next time.https://redd.it/1gphkvb
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Run command after certain time has elapsed
Hi, I'm trying to create a volume/brightness overlay that opens a window and closes it after a certain amount of time. The problem is that if I run my overlay noscript multiple times, the overlay window gets closed at random and flickers a bit. I'm currently doing the following:
Overlay() {
eww update icon="$icon" percent="$percent" && eww open overlay
sleep 2
eww close overlay
}
if $percent -gt 100 ; then
wpctl @ 5%+
Overlay
fi
This is a simplified version of my noscript. The full version can be viewed here.
https://redd.it/1gpg5ki
@r_bash
Hi, I'm trying to create a volume/brightness overlay that opens a window and closes it after a certain amount of time. The problem is that if I run my overlay noscript multiple times, the overlay window gets closed at random and flickers a bit. I'm currently doing the following:
Overlay() {
eww update icon="$icon" percent="$percent" && eww open overlay
sleep 2
eww close overlay
}
if $percent -gt 100 ; then
wpctl @ 5%+
Overlay
fi
This is a simplified version of my noscript. The full version can be viewed here.
https://redd.it/1gpg5ki
@r_bash
GitHub
dots/.config/river/overlay.sh at main · legoraft/dots
My dotfiles. Contribute to legoraft/dots development by creating an account on GitHub.
Naming conventions for constants (readonly variables)
For variables and functions, the naming conventions seems to be snake_case. Is this also the case for all constants?
Or are primitive constants (like int, string) always SCREAMING_SNAKE CASE and non-primitive constants (like arrays) use snake_case?
https://redd.it/1go60ek
@r_bash
For variables and functions, the naming conventions seems to be snake_case. Is this also the case for all constants?
Or are primitive constants (like int, string) always SCREAMING_SNAKE CASE and non-primitive constants (like arrays) use snake_case?
https://redd.it/1go60ek
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Having a lot of problems trying to call Ncat from a noscript. Kinda going crazy trying to find a combination that works as expected, need some guidance.
As the noscript alludes to, I've been trying to make a bash noscript that calls the Ncat util ([from nmap](https://nmap.org/)) to capture phone logs being streamed from our phone server. This works as expected 10/10 times, I run the command as such:
ncat <IP> <PORT>
Boom, expected behavior. Ncat makes connection, immediately starts displaying data.
When I try to put this into a noscript, it also works as expected. The problem comes when I try to redirect the output. I've encountered some odd and unexpected behavior when trying to load the PID into a variable in a noscript by means of VAR=$!
No matter what I do when using the format:
ncat <IP> <PORT> > output.csv & NCAT_PID=$!
the noscript fails immediately. File gets created, but of course nothing inside.
This led me down a rabbit hole of trying many many different variations of this trying to get the noscript to keep alive after calling it, and I tried at least 5 different methods, all ending with the same result.
Based on GPT recommendations I've tried:
* using the -k flag (never expected this to work cause it's not being used in listen mode)
* using nohup
* using disown
* using a basic while loop with "while true; do"
* redirecting stdin to /dev/null
After lots of trial-and-error, the ONLY THING that seemed to yield a different result was using && to get the PID, like so:
`ncat <IP> <PORT> > output.csv && NCAT_PID=$!`
This method does keep the ncat process alive, and appears to correctly load the NCAT\_PID variable.
THE KICKER:
Running ncat in an interactive shell like this
`ncat <IP> <PORT> > test.csv & PID=$!`
Somehow does ALMOST what I'm looking for. It starts an ncat process in the background, and loads A PID into that variable, for some reason it's just never the correct one.
I'm kind of at a loss as to how to proceed.
Part of why I started this was to figure out a way to run this ncat process each day, load the output into a unique file for that day, and kill it and restart at the start of a new day, to create a new file. I thought something like this would be pretty straight forward but it's proving rather difficult.
Any thoughts on how to solve this would be greatly appreciated :)
Thanks in advance!
https://redd.it/1gppan9
@r_bash
As the noscript alludes to, I've been trying to make a bash noscript that calls the Ncat util ([from nmap](https://nmap.org/)) to capture phone logs being streamed from our phone server. This works as expected 10/10 times, I run the command as such:
ncat <IP> <PORT>
Boom, expected behavior. Ncat makes connection, immediately starts displaying data.
When I try to put this into a noscript, it also works as expected. The problem comes when I try to redirect the output. I've encountered some odd and unexpected behavior when trying to load the PID into a variable in a noscript by means of VAR=$!
No matter what I do when using the format:
ncat <IP> <PORT> > output.csv & NCAT_PID=$!
the noscript fails immediately. File gets created, but of course nothing inside.
This led me down a rabbit hole of trying many many different variations of this trying to get the noscript to keep alive after calling it, and I tried at least 5 different methods, all ending with the same result.
Based on GPT recommendations I've tried:
* using the -k flag (never expected this to work cause it's not being used in listen mode)
* using nohup
* using disown
* using a basic while loop with "while true; do"
* redirecting stdin to /dev/null
After lots of trial-and-error, the ONLY THING that seemed to yield a different result was using && to get the PID, like so:
`ncat <IP> <PORT> > output.csv && NCAT_PID=$!`
This method does keep the ncat process alive, and appears to correctly load the NCAT\_PID variable.
THE KICKER:
Running ncat in an interactive shell like this
`ncat <IP> <PORT> > test.csv & PID=$!`
Somehow does ALMOST what I'm looking for. It starts an ncat process in the background, and loads A PID into that variable, for some reason it's just never the correct one.
I'm kind of at a loss as to how to proceed.
Part of why I started this was to figure out a way to run this ncat process each day, load the output into a unique file for that day, and kill it and restart at the start of a new day, to create a new file. I thought something like this would be pretty straight forward but it's proving rather difficult.
Any thoughts on how to solve this would be greatly appreciated :)
Thanks in advance!
https://redd.it/1gppan9
@r_bash
nmap.org
Nmap: the Network Mapper - Free Security Scanner
Nmap Free Security Scanner, Port Scanner, & Network Exploration Tool. Download open source software for Linux, Windows, UNIX, FreeBSD, etc.
for avoid inrtermitent wifi I use a radioonline, I'd like to test doing instead a ping...
Hi, I'd like to do a command with ping during the time I am online, so I will open a terminal and write a command with ping,what will be that command?
ping -time configurable for repeat every ¿1 min, or 2 min 0r 30 seg?...
when I cut wifi close the terminal. just I need that command with config time and where to do the ping.
Thank you and Regards!
https://redd.it/1gpqof0
@r_bash
Hi, I'd like to do a command with ping during the time I am online, so I will open a terminal and write a command with ping,what will be that command?
ping -time configurable for repeat every ¿1 min, or 2 min 0r 30 seg?...
when I cut wifi close the terminal. just I need that command with config time and where to do the ping.
Thank you and Regards!
https://redd.it/1gpqof0
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
do you know if command dmesg has history?
Hi, i'd like to see if I can see the history of command dmesg for see log for a session before ...
command journalctl -p err -b -0 has history changing the number
can I do similar for dmesg?
Thank you and regards!
https://redd.it/1gqpon8
@r_bash
Hi, i'd like to see if I can see the history of command dmesg for see log for a session before ...
command journalctl -p err -b -0 has history changing the number
can I do similar for dmesg?
Thank you and regards!
https://redd.it/1gqpon8
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
why can't I rm "file"
Edited: I did a mistake: hi, doing ls I have some files named "name'", why do not I can rm them?
when I tipe rm name nothing pass. rm nam<tab> nothing pass...
these names have " '" note ' before last "
Thank you and Regards!
https://redd.it/1grgdqz
@r_bash
Edited: I did a mistake: hi, doing ls I have some files named "name'", why do not I can rm them?
when I tipe rm name nothing pass. rm nam<tab> nothing pass...
these names have " '" note ' before last "
Thank you and Regards!
https://redd.it/1grgdqz
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Help needed with noscript
Hello is have noscript, it works when I run it manually. Problem is when I want to run it with cron, backup is not created. From log seems noscript stuck on password. Any help appreciated
https://redd.it/1grwnht
@r_bash
Hello is have noscript, it works when I run it manually. Problem is when I want to run it with cron, backup is not created. From log seems noscript stuck on password. Any help appreciated
#!/usr/bin/expect -flog_file /tmp/debug.logspawn echo "cron started"spawn rm /home/admin/backup-restore/mls_backup/mls-backup.tar.gzset password {password}spawn /usr/sbin/exec /home/admin/backup-restore/backup-restore --target /home/admin/backup-restore/mls_backup/mls-backup.tar.gz --no-encryptionexpect "admin password:"send "$password\r"interacthttps://redd.it/1grwnht
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community