Dear pros, as a newbie to bash noscripting, I wrote some functions to make my postgres life easier, anyone wanna review for best practices, conventions etc?
```
#!/usr/bin/env bash
# shellcheck source=/dev/null
source "${HOME}/Desktop/noscripts/logger.sh"
function run_createdb() {
if [[ -z "$(command -v createdb)" ]]; then
log_error "createdb command not found. Please ensure PostgreSQL client is installed."
return 1
fi
if [[ "$#" -lt 4 ]]; then
log_error "Usage: run_createdb <host> <port> <user> <database> [additional createdb flags]"
return 1
fi
local -r postgres_host="$1"
local -r postgres_port="$2"
local -r postgres_user="$3"
local -r postgres_database="$4"
shift 4
local -a createdb_flags=(
"--host=${postgres_host}"
"--port=${postgres_port}"
"--username=${postgres_user}"
)
createdb_flags+=("$@")
log_info "Executing createdb on database: ${postgres_database}, host: ${postgres_host}, port: ${postgres_port}, username: ${postgres_user} with flags: ${createdb_flags[*]}"
if createdb "${createdb_flags[@]}" "${postgres_database}"; then
log_info "createdb command executed successfully"
return 0
else
log_error "createdb command execution failed"
return 1
fi
}
function run_createuser() {
if [[ -z "$(command -v createuser)" ]]; then
log_error "createuser command not found. Please ensure PostgreSQL client is installed."
return 1
fi
if [[ "$#" -lt 4 ]]; then
log_error "Usage: run_createuser <host> <port> <user> <superuser> [additional createuser flags]"
return 1
fi
local -r postgres_host="$1"
local -r postgres_port="$2"
local -r postgres_user="$3"
local -r postgres_superuser="$4"
shift 4
local -a createuser_flags=(
"--host=${postgres_host}"
"--port=${postgres_port}"
"--username=${postgres_superuser}"
)
createuser_flags+=("$@")
log_info "Executing createuser on host: ${postgres_host}, port: ${postgres_port}, username: ${postgres_superuser} with flags: ${createuser_flags[*]}"
if createuser "${createuser_flags[@]}" "${postgres_user}"; then
log_info "createuser command executed successfully"
return 0
else
log_error "createuser command execution failed"
return 1
fi
}
function run_dropdb() {
if [[ -z "$(command -v dropdb)" ]]; then
log_error "dropdb command not found. Please ensure PostgreSQL client is installed."
return 1
fi
if [[ "$#" -lt 4 ]]; then
log_error "Usage: run_dropdb <host> <port> <user> <database> [additional dropdb flags]"
return 1
fi
local -r postgres_host="$1"
local -r postgres_port="$2"
local -r postgres_user="$3"
local -r postgres_database="$4"
shift 4
local -a dropdb_flags=(
"--host=${postgres_host}"
"--port=${postgres_port}"
"--username=${postgres_user}"
)
dropdb_flags+=("$@")
log_info "Executing dropdb on database: ${postgres_database}, host: ${postgres_host}, port: ${postgres_port}, username: ${postgres_user} with flags: ${dropdb_flags[*]}"
if dropdb "${dropdb_flags[@]}" "${postgres_database}"; then
log_info "dropdb command executed successfully"
return 0
else
log_error "dropdb command execution failed"
return 1
fi
}
function run_pg_dump() {
if [[ -z "$(command -v pg_dump)" ]]; then
log_error "pg_dump command not found. Please ensure PostgreSQL client is installed."
return 1
fi
if [[ "$#" -lt 4 ]]; then
log_error "Usage: run_pg_dump <host> <port> <user> <database> [additional pg_dump flags]"
return 1
fi
local -r postgres_host="$1"
local -r postgres_port="$2"
local -r postgres_user="$3"
local -r postgres_database="$4"
shift 4
local -a pg_dump_flags=(
"--dbname=${postgres_database}"
"--host=${postgres_host}"
"--port=${postgres_port}"
```
#!/usr/bin/env bash
# shellcheck source=/dev/null
source "${HOME}/Desktop/noscripts/logger.sh"
function run_createdb() {
if [[ -z "$(command -v createdb)" ]]; then
log_error "createdb command not found. Please ensure PostgreSQL client is installed."
return 1
fi
if [[ "$#" -lt 4 ]]; then
log_error "Usage: run_createdb <host> <port> <user> <database> [additional createdb flags]"
return 1
fi
local -r postgres_host="$1"
local -r postgres_port="$2"
local -r postgres_user="$3"
local -r postgres_database="$4"
shift 4
local -a createdb_flags=(
"--host=${postgres_host}"
"--port=${postgres_port}"
"--username=${postgres_user}"
)
createdb_flags+=("$@")
log_info "Executing createdb on database: ${postgres_database}, host: ${postgres_host}, port: ${postgres_port}, username: ${postgres_user} with flags: ${createdb_flags[*]}"
if createdb "${createdb_flags[@]}" "${postgres_database}"; then
log_info "createdb command executed successfully"
return 0
else
log_error "createdb command execution failed"
return 1
fi
}
function run_createuser() {
if [[ -z "$(command -v createuser)" ]]; then
log_error "createuser command not found. Please ensure PostgreSQL client is installed."
return 1
fi
if [[ "$#" -lt 4 ]]; then
log_error "Usage: run_createuser <host> <port> <user> <superuser> [additional createuser flags]"
return 1
fi
local -r postgres_host="$1"
local -r postgres_port="$2"
local -r postgres_user="$3"
local -r postgres_superuser="$4"
shift 4
local -a createuser_flags=(
"--host=${postgres_host}"
"--port=${postgres_port}"
"--username=${postgres_superuser}"
)
createuser_flags+=("$@")
log_info "Executing createuser on host: ${postgres_host}, port: ${postgres_port}, username: ${postgres_superuser} with flags: ${createuser_flags[*]}"
if createuser "${createuser_flags[@]}" "${postgres_user}"; then
log_info "createuser command executed successfully"
return 0
else
log_error "createuser command execution failed"
return 1
fi
}
function run_dropdb() {
if [[ -z "$(command -v dropdb)" ]]; then
log_error "dropdb command not found. Please ensure PostgreSQL client is installed."
return 1
fi
if [[ "$#" -lt 4 ]]; then
log_error "Usage: run_dropdb <host> <port> <user> <database> [additional dropdb flags]"
return 1
fi
local -r postgres_host="$1"
local -r postgres_port="$2"
local -r postgres_user="$3"
local -r postgres_database="$4"
shift 4
local -a dropdb_flags=(
"--host=${postgres_host}"
"--port=${postgres_port}"
"--username=${postgres_user}"
)
dropdb_flags+=("$@")
log_info "Executing dropdb on database: ${postgres_database}, host: ${postgres_host}, port: ${postgres_port}, username: ${postgres_user} with flags: ${dropdb_flags[*]}"
if dropdb "${dropdb_flags[@]}" "${postgres_database}"; then
log_info "dropdb command executed successfully"
return 0
else
log_error "dropdb command execution failed"
return 1
fi
}
function run_pg_dump() {
if [[ -z "$(command -v pg_dump)" ]]; then
log_error "pg_dump command not found. Please ensure PostgreSQL client is installed."
return 1
fi
if [[ "$#" -lt 4 ]]; then
log_error "Usage: run_pg_dump <host> <port> <user> <database> [additional pg_dump flags]"
return 1
fi
local -r postgres_host="$1"
local -r postgres_port="$2"
local -r postgres_user="$3"
local -r postgres_database="$4"
shift 4
local -a pg_dump_flags=(
"--dbname=${postgres_database}"
"--host=${postgres_host}"
"--port=${postgres_port}"
"--username=${postgres_user}"
)
pg_dump_flags+=("$@")
log_info "Executing pg_dump on database: ${postgres_database}, host: ${postgres_host}, port: ${postgres_port}, username: ${postgres_user} with flags: ${pg_dump_flags[*]}"
if pg_dump "${pg_dump_flags[@]}" "${postgres_database}"; then
log_info "pg_dump command executed successfully"
return 0
else
log_error "pg_dump command execution failed"
return 1
fi
}
function run_pg_restore() {
if [[ -z "$(command -v pg_restore)" ]]; then
log_error "pg_restore command not found. Please ensure PostgreSQL client is installed."
return 1
fi
if [[ "$#" -lt 4 ]]; then
log_error "Usage: run_pg_restore <host> <port> <user> <database> [additional pg_restore flags]"
return 1
fi
local -r postgres_host="$1"
local -r postgres_port="$2"
local -r postgres_user="$3"
local -r postgres_database="$4"
shift 4
local -a pg_restore_flags=(
"--dbname=${postgres_database}"
"--host=${postgres_host}"
"--port=${postgres_port}"
"--username=${postgres_user}"
)
pg_restore_flags+=("$@")
log_info "Executing pg_restore on database: ${postgres_database}, host: ${postgres_host}, port: ${postgres_port}, username: ${postgres_user} with flags: ${pg_restore_flags[*]}"
if pg_restore "${pg_restore_flags[@]}" "${postgres_database}"; then
log_info "pg_restore command executed successfully"
return 0
else
log_error "pg_restore command execution failed"
return 1
fi
}
function run_psql() {
if [[ -z "$(command -v psql)" ]]; then
log_error "psql command not found. Please ensure PostgreSQL client is installed."
return 1
fi
if [[ "$#" -lt 4 ]]; then
log_error "Usage: run_psql <host> <port> <user> <database> [additional psql flags]"
return 1
fi
local -r postgres_host="$1"
local -r postgres_port="$2"
local -r postgres_user="$3"
local -r postgres_database="$4"
shift 4
local -a psql_flags=(
"--dbname=${postgres_database}"
"--host=${postgres_host}"
"--port=${postgres_port}"
"--username=${postgres_user}"
)
psql_flags+=("$@")
log_info "Executing psql on database: ${postgres_database}, host: ${postgres_host}, port: ${postgres_port}, username: ${postgres_user} with flags: ${psql_flags[*]}"
if psql "${psql_flags[@]}"; then
log_info "psql command executed successfully"
return 0
else
log_error "psql command execution failed"
return 1
fi
}
```
https://redd.it/1qllq3g
@r_bash
)
pg_dump_flags+=("$@")
log_info "Executing pg_dump on database: ${postgres_database}, host: ${postgres_host}, port: ${postgres_port}, username: ${postgres_user} with flags: ${pg_dump_flags[*]}"
if pg_dump "${pg_dump_flags[@]}" "${postgres_database}"; then
log_info "pg_dump command executed successfully"
return 0
else
log_error "pg_dump command execution failed"
return 1
fi
}
function run_pg_restore() {
if [[ -z "$(command -v pg_restore)" ]]; then
log_error "pg_restore command not found. Please ensure PostgreSQL client is installed."
return 1
fi
if [[ "$#" -lt 4 ]]; then
log_error "Usage: run_pg_restore <host> <port> <user> <database> [additional pg_restore flags]"
return 1
fi
local -r postgres_host="$1"
local -r postgres_port="$2"
local -r postgres_user="$3"
local -r postgres_database="$4"
shift 4
local -a pg_restore_flags=(
"--dbname=${postgres_database}"
"--host=${postgres_host}"
"--port=${postgres_port}"
"--username=${postgres_user}"
)
pg_restore_flags+=("$@")
log_info "Executing pg_restore on database: ${postgres_database}, host: ${postgres_host}, port: ${postgres_port}, username: ${postgres_user} with flags: ${pg_restore_flags[*]}"
if pg_restore "${pg_restore_flags[@]}" "${postgres_database}"; then
log_info "pg_restore command executed successfully"
return 0
else
log_error "pg_restore command execution failed"
return 1
fi
}
function run_psql() {
if [[ -z "$(command -v psql)" ]]; then
log_error "psql command not found. Please ensure PostgreSQL client is installed."
return 1
fi
if [[ "$#" -lt 4 ]]; then
log_error "Usage: run_psql <host> <port> <user> <database> [additional psql flags]"
return 1
fi
local -r postgres_host="$1"
local -r postgres_port="$2"
local -r postgres_user="$3"
local -r postgres_database="$4"
shift 4
local -a psql_flags=(
"--dbname=${postgres_database}"
"--host=${postgres_host}"
"--port=${postgres_port}"
"--username=${postgres_user}"
)
psql_flags+=("$@")
log_info "Executing psql on database: ${postgres_database}, host: ${postgres_host}, port: ${postgres_port}, username: ${postgres_user} with flags: ${psql_flags[*]}"
if psql "${psql_flags[@]}"; then
log_info "psql command executed successfully"
return 0
else
log_error "psql command execution failed"
return 1
fi
}
```
https://redd.it/1qllq3g
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Bash Loging
#!/bin/bash
exec 19>/tmp/full_configer.log
export BASH_EXTRACEFD=19
will this send a copy of the output to the log file?
https://redd.it/1qlrtj6
@r_bash
#!/bin/bash
exec 19>/tmp/full_configer.log
export BASH_EXTRACEFD=19
will this send a copy of the output to the log file?
https://redd.it/1qlrtj6
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Most hidden "bug"?
Edit: Ok, maybe the post noscript is a bit pretentious, in hindsight even cringe (cannot edit it anymore). But the behavior is certainly weird!
I've found something truly weird, and maybe someone knowledgeable in bash's source code can help me understand this :D. If you run this command: `a(`, you will likely get ``bash: syntax error near unexpected token `newline'``. Now, run this command `<(`. It will hopefully ask for more input. Abort with Ctrl-C. Now run `a(` again. You will *from now on*, get a different error message! Namely: ``bash: syntax error near unexpected token `newline' while looking for matching `)'``.
Of course this is a niche thing that doesn't really matter, but I'm really interested in bash and maybe someone has a sound explanation for this, as it doesn't really make sense to me. It seems like bash turns a switch or something when you start but not finish a process substitution!
Here's an interactive session of what I mean:
$ a(
bash: syntax error near unexpected token `newline'
$ a((
bash: syntax error near unexpected token `('
$ <(
> ^C
$ a(
bash: syntax error near unexpected token `newline' while looking for matching `)'
$ a((
bash: syntax error near unexpected token `(' while looking for matching `)'
$ a(
bash: syntax error near unexpected token `newline' while looking for matching `)'
https://redd.it/1qly1ha
@r_bash
Edit: Ok, maybe the post noscript is a bit pretentious, in hindsight even cringe (cannot edit it anymore). But the behavior is certainly weird!
I've found something truly weird, and maybe someone knowledgeable in bash's source code can help me understand this :D. If you run this command: `a(`, you will likely get ``bash: syntax error near unexpected token `newline'``. Now, run this command `<(`. It will hopefully ask for more input. Abort with Ctrl-C. Now run `a(` again. You will *from now on*, get a different error message! Namely: ``bash: syntax error near unexpected token `newline' while looking for matching `)'``.
Of course this is a niche thing that doesn't really matter, but I'm really interested in bash and maybe someone has a sound explanation for this, as it doesn't really make sense to me. It seems like bash turns a switch or something when you start but not finish a process substitution!
Here's an interactive session of what I mean:
$ a(
bash: syntax error near unexpected token `newline'
$ a((
bash: syntax error near unexpected token `('
$ <(
> ^C
$ a(
bash: syntax error near unexpected token `newline' while looking for matching `)'
$ a((
bash: syntax error near unexpected token `(' while looking for matching `)'
$ a(
bash: syntax error near unexpected token `newline' while looking for matching `)'
https://redd.it/1qly1ha
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Are there any high leverage ways to get good ctrl r in a terminal?
I have to deal with a lot of minimal containers. Some, I straight up don't control (proprietary cloud simulations). Some I do control technically... but it's a PITA to maintain all my configs and integrate them with the container easily and reliably (especially if dependencies aren't installed on said machine), through version upgrades. Sometimes I just want to spin up a container just cuz.
For reference, another extremely high leverage option is vi mode:
I just copy this in the start of any minimal bash session (or even just set -o vi, but this is automatable with tmux) and I'm basically chilling.
Sure, fzf is great, but it depends on git being installed. I mean, not really a big deal, but still, a dependency (e.g. now you need internet access, remember the package manager for the OS, it needs to have git, etc.) Furthermore, I want to sort of push the limits of bash - are there any wizards that know a lot about obscure bash features that could hack something up that's "simple" (two stages: one is obviously just minimal characters, but any solution that you can just copy paste into a bash terminal in a single line, no matter how hackily, is good enough for me IMO)
Yes, I know normal ctrl r, no, I don't like it mainly because it doesn't show me multiple options at once. My memory is really bad LOL, but maybe I just get used to it (fzf is an actual gamechanger fr tho)
---
EDIT because I think i'm shadowbanned from my own post for some reason but:
the use case is when you spin up various interactive containers potentially hundreds of times a day, don't have control over the exact launch params (or more precisely, maintaining custom configs layered on top of the containers is either hacky as version upgrades happen, or it straight up is impossible like in secure proprietary cloud simulations) and don't want to deal with vanilla bash.
the challenge is to find a good balance
my config in general (if I were say, installing configs fully on a home computer I control) is already very minimal already, but this is going even further.
in general:
- mounting is forbidden in general (if I could mount, I'd just install my configs lol)
- internet is okay, but the point is no internet. yes I am aware git clone fzf + install, the point of the post is that we aren't going this route. take it or leave it lol. that's why I asked specifically on the r/bash subreddit, if there were any bash wizards who had custom ctrl R setups, curious
set -o vi, for example, is a setting on most containers that exists, requires no internet, and is high leverage for me (as someone who lives perma in the command line).
fzf is also very high leverage for me. but I'm saying, assume we aren't allowed to use fzf, what can we do
https://redd.it/1qqo2ce
@r_bash
I have to deal with a lot of minimal containers. Some, I straight up don't control (proprietary cloud simulations). Some I do control technically... but it's a PITA to maintain all my configs and integrate them with the container easily and reliably (especially if dependencies aren't installed on said machine), through version upgrades. Sometimes I just want to spin up a container just cuz.
For reference, another extremely high leverage option is vi mode:
set -o vi; bind 'set vi-ins-mode-string \1\e[6 q\2'; bind 'set vi-cmd-mode-string \1\e[2 q\2';
I just copy this in the start of any minimal bash session (or even just set -o vi, but this is automatable with tmux) and I'm basically chilling.
Sure, fzf is great, but it depends on git being installed. I mean, not really a big deal, but still, a dependency (e.g. now you need internet access, remember the package manager for the OS, it needs to have git, etc.) Furthermore, I want to sort of push the limits of bash - are there any wizards that know a lot about obscure bash features that could hack something up that's "simple" (two stages: one is obviously just minimal characters, but any solution that you can just copy paste into a bash terminal in a single line, no matter how hackily, is good enough for me IMO)
Yes, I know normal ctrl r, no, I don't like it mainly because it doesn't show me multiple options at once. My memory is really bad LOL, but maybe I just get used to it (fzf is an actual gamechanger fr tho)
---
EDIT because I think i'm shadowbanned from my own post for some reason but:
the use case is when you spin up various interactive containers potentially hundreds of times a day, don't have control over the exact launch params (or more precisely, maintaining custom configs layered on top of the containers is either hacky as version upgrades happen, or it straight up is impossible like in secure proprietary cloud simulations) and don't want to deal with vanilla bash.
the challenge is to find a good balance
my config in general (if I were say, installing configs fully on a home computer I control) is already very minimal already, but this is going even further.
in general:
- mounting is forbidden in general (if I could mount, I'd just install my configs lol)
- internet is okay, but the point is no internet. yes I am aware git clone fzf + install, the point of the post is that we aren't going this route. take it or leave it lol. that's why I asked specifically on the r/bash subreddit, if there were any bash wizards who had custom ctrl R setups, curious
set -o vi, for example, is a setting on most containers that exists, requires no internet, and is high leverage for me (as someone who lives perma in the command line).
fzf is also very high leverage for me. but I'm saying, assume we aren't allowed to use fzf, what can we do
https://redd.it/1qqo2ce
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Locked out of local admin account - need to recover Wi-Fi network details
Hi everyone,
I’ve found my old laptop running Windows 10/11, but I’ve completely forgotten the local administrator password. I can log in as a standard user, but I need admin rights to see the Wi-Fi password for the network I'm currently connected to (using the netsh wlan show profile command).
Since it’s a local account not linked to Microsoft, I’m looking for a way to reset the admin password or gain enough privileges to run CMD as admin without wiping my data. Are tools like Hiren’s BootCD or the "utilman" method still working on recent updates?
Thanks for any advice!
https://redd.it/1qqyc1c
@r_bash
Hi everyone,
I’ve found my old laptop running Windows 10/11, but I’ve completely forgotten the local administrator password. I can log in as a standard user, but I need admin rights to see the Wi-Fi password for the network I'm currently connected to (using the netsh wlan show profile command).
Since it’s a local account not linked to Microsoft, I’m looking for a way to reset the admin password or gain enough privileges to run CMD as admin without wiping my data. Are tools like Hiren’s BootCD or the "utilman" method still working on recent updates?
Thanks for any advice!
https://redd.it/1qqyc1c
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Tcl: The Most Underrated, But The Most Productive Programming Language (like Bash)
https://medium.com/gitconnected/tcl-the-most-underrated-but-the-most-productive-programming-language-1f83c99eaab7?sk=de732f41d473339dc31ee7481a8ba526
https://redd.it/1qqyq44
@r_bash
https://medium.com/gitconnected/tcl-the-most-underrated-but-the-most-productive-programming-language-1f83c99eaab7?sk=de732f41d473339dc31ee7481a8ba526
https://redd.it/1qqyq44
@r_bash
Medium
Tcl: The Most Underrated, But The Most Productive Programming Language
The only well-modernized command language that you can use literally for anything
UTKeeper99 a advanced Linux Unreal Tournament and Webservices Tool
\# Features Highlights:
\# - First-Run Auto-Config Detection (should reject critical system paths)
\# - DryRun Mode for safe testing
\# - Recursive Archive Extraction (up to 10 levels deep)
\# - Smart File Collection (gathers all UT files from subdirs)
\# - Disk Space Validation before Backup
\# - Backup Management (List, Delete by age, etc.)
\# - Distribution of Maps to UT Server and Webserver
\# - Cloning Maps (you like CTF-Face? or a MH Map ? now play that as DM/TDM map)
\# - Name fixes (case sensitive for Linux) + chmod/chown defaults for UT/Web
\# - Advanced UT and Webserver Orphan Cleaning Tool
\# - Modular design for easy expansion/customization.
\#
https://github.com/KoDProm/utkeeper99
https://redd.it/1qq6ewo
@r_bash
\# Features Highlights:
\# - First-Run Auto-Config Detection (should reject critical system paths)
\# - DryRun Mode for safe testing
\# - Recursive Archive Extraction (up to 10 levels deep)
\# - Smart File Collection (gathers all UT files from subdirs)
\# - Disk Space Validation before Backup
\# - Backup Management (List, Delete by age, etc.)
\# - Distribution of Maps to UT Server and Webserver
\# - Cloning Maps (you like CTF-Face? or a MH Map ? now play that as DM/TDM map)
\# - Name fixes (case sensitive for Linux) + chmod/chown defaults for UT/Web
\# - Advanced UT and Webserver Orphan Cleaning Tool
\# - Modular design for easy expansion/customization.
\#
https://github.com/KoDProm/utkeeper99
https://redd.it/1qq6ewo
@r_bash
GitHub
GitHub - KoDProm/utkeeper99: UTKeeper99 a linux based Unreal Tournament and local Webdirect Management Service Tool
UTKeeper99 a linux based Unreal Tournament and local Webdirect Management Service Tool - KoDProm/utkeeper99
Limiting internet access on machine through BASH
Okay, I have NO idea where to post this now. Please, if this is NOT relevant to this subreddit, could anyone direct me to an appropriate subreddit.
If anyone can solve it, I will be so grateful!
I am trying to limit internet on my maching from 8AM to 10PM via powershell. I used GPT to help.
So here are some commands that work
To create internet kill switch on laptop:
To kill internet on laptop (test to show that it work)
To enable internet on laptop (test to show that it works)
However, the following does not work. I assume that it doesn't work when the machine is off.
To UNblock internet at 8:00AM, task called "EnableInternet"
I tried to edit it so that it checks the time every minute. That way if the machine is turned on AFTER 8AM, it works. But the following does NOT work
Similar for blocking the internet at midday.
I bet there are other issues, Like if both commands even worked, maybe the internet would just switch on and off?
I am so lost here guys, let me know if you have any solutions.
Inb4 why not just remove the internet: I only need the internet between 8AM and midday.
https://redd.it/1qqoyt0
@r_bash
Okay, I have NO idea where to post this now. Please, if this is NOT relevant to this subreddit, could anyone direct me to an appropriate subreddit.
If anyone can solve it, I will be so grateful!
I am trying to limit internet on my maching from 8AM to 10PM via powershell. I used GPT to help.
So here are some commands that work
To create internet kill switch on laptop:
netsh advfirewall firewall add rule name="InternetKillSwitch" dir=out action=block protocol=anyTo kill internet on laptop (test to show that it work)
netsh advfirewall firewall set rule name="InternetKillSwitch" new enable=yesTo enable internet on laptop (test to show that it works)
netsh advfirewall firewall set rule name="InternetKillSwitch" new enable=noHowever, the following does not work. I assume that it doesn't work when the machine is off.
To UNblock internet at 8:00AM, task called "EnableInternet"
schtasks /create /sc daily /st 08:00 /ru SYSTEM /rl HIGHEST /tn "EnableInternet" /tr "powershell -command \"netsh advfirewall firewall set rule name='InternetKillSwitch' new enable=no\""I tried to edit it so that it checks the time every minute. That way if the machine is turned on AFTER 8AM, it works. But the following does NOT work
schtasks /create /sc daily /st 08:00 /ru SYSTEM /rl HIGHEST /tn "EnableInternet" /tr "powershell -command \"netsh advfirewall firewall set rule name='InternetKillSwitch' new enable=no\"" /ri 1 /du 24:00Similar for blocking the internet at midday.
schtasks /create /sc daily /st 12:00 /ru SYSTEM /rl HIGHEST /tn "EnableInternet" /tr "powershell -command \"netsh advfirewall firewall set rule name='InternetKillSwitch' new enable=no\"" /ri 1 /du 24:00I bet there are other issues, Like if both commands even worked, maybe the internet would just switch on and off?
I am so lost here guys, let me know if you have any solutions.
Inb4 why not just remove the internet: I only need the internet between 8AM and midday.
https://redd.it/1qqoyt0
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to kill a noscript after it runs awhile from another noscript
Hi,
I have a noscript that runs on startup that I will want to kill to run another one(later on) via cron.
Can't figure out how to kill the first noscript programatically.
Say the noscript is: ~/noscripts/default.sh
and I want to kill it, what is a predictable way to kill said noscript. I know of ps and pkill but I hit a wall. I don't know the steps(or commands?) involved to do this accurately.
Thanks in advance.
https://redd.it/1qowblg
@r_bash
Hi,
I have a noscript that runs on startup that I will want to kill to run another one(later on) via cron.
Can't figure out how to kill the first noscript programatically.
Say the noscript is: ~/noscripts/default.sh
and I want to kill it, what is a predictable way to kill said noscript. I know of ps and pkill but I hit a wall. I don't know the steps(or commands?) involved to do this accurately.
Thanks in advance.
https://redd.it/1qowblg
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
SS64
I've been using the command line for 26 years and I've seen lots of good tips and tricks guides. My favorite by far is ss64.com. I actually originally found it when I was looking for help with Windows batch noscripting, but it has good stuff about Linux and Bash, too.
https://redd.it/1qo2bp1
@r_bash
I've been using the command line for 26 years and I've seen lots of good tips and tricks guides. My favorite by far is ss64.com. I actually originally found it when I was looking for help with Windows batch noscripting, but it has good stuff about Linux and Bash, too.
https://redd.it/1qo2bp1
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Code Optimization Suggestions Welcome
Howdy bash friends,
Inspired by the goodwork of people in the ZSA and ploopy communities I whipped together some improvements to the moonlander (keyboard) spin of the ploopy nano (trackball) BTU mod, and I wrote a little noscript and a systemd .service file that use the api ZSA made to manage communication between the trackball and my moonlander, so that moving the trackball activates a mouse layer on my keyboard,
Honestly it's pretty sweet, very snappy and responsive, but I was wondering if some bored soul with a deep knowledge of bash built-in's was willing to take a look and let me know if I missed some low-hanging fruit to optimize my code?
https://preview.redd.it/lgbguzx6jmfg1.jpg?width=4624&format=pjpg&auto=webp&s=57ee3e3b9a0c65e30634b982aed7fb23106a1b1a
Posted on github here
https://redd.it/1qn6hkf
@r_bash
Howdy bash friends,
Inspired by the goodwork of people in the ZSA and ploopy communities I whipped together some improvements to the moonlander (keyboard) spin of the ploopy nano (trackball) BTU mod, and I wrote a little noscript and a systemd .service file that use the api ZSA made to manage communication between the trackball and my moonlander, so that moving the trackball activates a mouse layer on my keyboard,
Honestly it's pretty sweet, very snappy and responsive, but I was wondering if some bored soul with a deep knowledge of bash built-in's was willing to take a look and let me know if I missed some low-hanging fruit to optimize my code?
https://preview.redd.it/lgbguzx6jmfg1.jpg?width=4624&format=pjpg&auto=webp&s=57ee3e3b9a0c65e30634b982aed7fb23106a1b1a
Posted on github here
https://redd.it/1qn6hkf
@r_bash
Format curl output
https://redd.it/1qmprj1
@r_bash
-w for curl can output values like request size. I am printing a few numbers like -w %num_redirects %num_retries. Does it let you format the output with padding how printf has %05d?https://redd.it/1qmprj1
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
A simple noscript to route between different llm providers and models
https://github.com/Jevs21/bash-ai
https://redd.it/1qskmov
@r_bash
https://github.com/Jevs21/bash-ai
https://redd.it/1qskmov
@r_bash
GitHub
GitHub - Jevs21/bash-ai: To easily route between different providers and models
To easily route between different providers and models - Jevs21/bash-ai
FUN.bash
I made public an configuration and function framework I've been using in bash for quite some time already. Do check out :)
Constructive criticism very welcome. Basically what it has is templates and you can have loadable modules for your own functions. A lot can be achieved probably with aliases and some other tools, but I have had fun with this one.
https://github.com/nuin-ctrl/FUN.bash
https://redd.it/1qsuy3g
@r_bash
I made public an configuration and function framework I've been using in bash for quite some time already. Do check out :)
Constructive criticism very welcome. Basically what it has is templates and you can have loadable modules for your own functions. A lot can be achieved probably with aliases and some other tools, but I have had fun with this one.
https://github.com/nuin-ctrl/FUN.bash
https://redd.it/1qsuy3g
@r_bash
GitHub
GitHub - nuin-ctrl/FUN.bash: Bash function module framework
Bash function module framework. Contribute to nuin-ctrl/FUN.bash development by creating an account on GitHub.
Nix: Defining Dependencies with Flakes
What do you think about that? What do you want to add?
## Nix: Defining Dependencies with Flakes
In the Python world, we have virtual environments. They are incredibly handy because they allow you to maintain multiple environments, each with its own custom dependencies and specific versions.
Almost every programming language has a similar concept, but what about Bash noscripts? While you can manually modify your
If you want a declarative way to define dependencies, Nix Flakes is the best solution I’ve found.
Admittedly, some parts of Nix can be difficult for newcomers to grasp. However, Large Language Models (LLMs) and your favorite search engine support you.
Personally, I think it’s time to say "goodbye" to Makefiles and noscripts that manually install tools.
Should you install everything via Nix?
My approach is to install the base tools via Nix and then let language-specific package managers handle the version pinning:
Go: `go.mod` / `go.sum`
JS:
Ruby: `Gemfile` / `Gemfile.lock`
....
https://redd.it/1qwfcnv
@r_bash
What do you think about that? What do you want to add?
## Nix: Defining Dependencies with Flakes
In the Python world, we have virtual environments. They are incredibly handy because they allow you to maintain multiple environments, each with its own custom dependencies and specific versions.
Almost every programming language has a similar concept, but what about Bash noscripts? While you can manually modify your
PATH—and for small projects, that might work—it quickly becomes difficult to manage.If you want a declarative way to define dependencies, Nix Flakes is the best solution I’ve found.
Admittedly, some parts of Nix can be difficult for newcomers to grasp. However, Large Language Models (LLMs) and your favorite search engine support you.
Personally, I think it’s time to say "goodbye" to Makefiles and noscripts that manually install tools.
Should you install everything via Nix?
My approach is to install the base tools via Nix and then let language-specific package managers handle the version pinning:
Go: `go.mod` / `go.sum`
JS:
package.json / package-lock.jsonRuby: `Gemfile` / `Gemfile.lock`
....
https://redd.it/1qwfcnv
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community