r_bash – Telegram
Curl Timing Confusion

I’m trying to figure out what I’ve done wrong with respect to limiting how much time curl takes to perform a single file upload.

Here’s the code I’m using. 

`for i in {1..3}`
`do`
`echo $'\n'"\`date\`" Upload Attempt  "$i" - $(hostname) >> "$log"`

`curl -s -S -v -u mgnewman: \`
`--connect-timeout 30 \`
`--max-time 30 \`
`--pubkey ~/.ssh/id_rsa.pub \`
`-T $file $host &>>  $log`

`err=$?`

`echo $'\n'"\`date\`" Upload Ended "$err" - $(hostname) >> "$log"`

`touch /home/pi/webcam/webcam.webp`

`if [ $err -eq 0 ] ; then`
`break`
`fi`
`done`

Note that I’m using a “do loop” rather than curl’s retry option because between each iteration I want to touch an existing image file to prevent watchdog from rebooting the machine which it does if the image is not refreshed in ten minutes.

I’m trying to limit each iteration of curl to 30 seconds, but that doesn’t seem to work. Here’s a fragment of my log file:

Wed Jan 21 23:37:24 +07 2026 Upload Attempt 3 - raspcondo

\*   Trying 192.nnn.nnn.101...
\* TCP\_NODELAY set
\* Connected to [xxxxxxx.com](http://xxxxxxx.com/) (192.nnn.nnn.101) port 22 (#0)
\* SSH MD5 fingerprint: 4b17cad500a405c850e118c1deec0f96
\* SSH host check: 0, key: AAAAB3NzaC1yc2EAAAADAQABAAABAQCzCyhhdYNOn5Zgib7qhPKev$
\* SSH authentication methods available: publickey,password,keyboard-interactive
\* Using SSH public key file '/home/pi/.ssh/id\_rsa.pub'
\* Using SSH private key file '/home/pi/.ssh/id\_rsa'
\* Initialized SSH public key authentication
\* Authentication complete
\* Operation timed out after 30000 milliseconds with 0 out of 0 bytes received
\* Closing connection 0
curl: (28) Operation timed out after 30000 milliseconds with 0 out of 0 bytes r$

Wed Jan 21 23:48:09 +07 2026 Upload Ended 28 - raspcondo

My conclusion is that I don’t understand how this works as it seems that around ten minutes elapsed between the time curl started (23:37:24) and the time it failed (23:48:09) with error 28.

Note that I realize the code is rather sloppy, but I’m just a hobbyist and that’s about the best I can do. Sorry.

https://redd.it/1qkjv1r
@r_bash
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}"
"--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
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
A small (misnamed) utility to source bash noscript like activate
https://redd.it/1qltl6m
@r_bash
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
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:

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
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
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
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:

netsh advfirewall firewall add rule name="InternetKillSwitch" dir=out action=block protocol=any

To kill internet on laptop (test to show that it work)

netsh advfirewall firewall set rule name="InternetKillSwitch" new enable=yes

To enable internet on laptop (test to show that it works)

netsh advfirewall firewall set rule name="InternetKillSwitch" new enable=no

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"

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:00



Similar 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:00



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
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
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
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
Format curl output

-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
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