Expect noscript will not run in cron
I have a noscript that I run every night via cron as root. I set the path in the top of the crontab. The noscript kicks off a expect command to spawn a lftp session. Everything works great when I run the noscript via interactive, but when I run it via cron, the file never gets sent. The log doesn't show any errors. The comment from the parent noscript is:
and the content of the expect_noscript.txt is below:
https://redd.it/1me3j2i
@r_bash
I have a noscript that I run every night via cron as root. I set the path in the top of the crontab. The noscript kicks off a expect command to spawn a lftp session. Everything works great when I run the noscript via interactive, but when I run it via cron, the file never gets sent. The log doesn't show any errors. The comment from the parent noscript is:
expect -f expect_noscript.txtand the content of the expect_noscript.txt is below:
set timeout 60set prompt "lftp *"set FTP_HOST "waws-prod-ch9-051.ftp.azurewebsites.windows.net"set LOCAL_FILE "/public/ra_reports/*.html"spawn lftp ftp://$FTP_HOST# send User and Passwordexpect {$prompt { send "user USERID\\PASSWORD\r" }timeout { puts "Timed out"; exit 1}}# change DIR to ra_reportsexpect {$prompt { send "cd /site/wwwroot/ra_reports\r" }timeout { puts "Timed out"; exit 1}}# put HTML filesexpect {$prompt { send "mput $LOCAL_FILE\r" }timeout { puts "Timed out"; exit 1}}send "bye\r"expect eofhttps://redd.it/1me3j2i
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Help, Can't get the code to be running in bash
$ cd "e:\Sculptures\Dustbin\Random\" && g++ sumthin.cpp -o sumthin && ./sumthin
this is the only output
https://redd.it/1mef8v8
@r_bash
$ cd "e:\Sculptures\Dustbin\Random\" && g++ sumthin.cpp -o sumthin && ./sumthin
this is the only output
https://redd.it/1mef8v8
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Any good AI tool that can help generate noscripts?
Hi,
Anyone using a good AI tool to automate noscript generation, testing and implementation? Looking for some suggestions on some good tools.
https://redd.it/1meusjg
@r_bash
Hi,
Anyone using a good AI tool to automate noscript generation, testing and implementation? Looking for some suggestions on some good tools.
https://redd.it/1meusjg
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
An open-source AI that turns plain English into terminal commands
Vity is an open-source terminal assistant that lets you turn natural language instructions into shell commands.
Built for those of you who are not command-line wizards, but still occasionally need to battle the terminal.
In addition to generating commands, Vity also lets you ask questions based on your terminal history.
Vity adds the generated command to terminal history, but NEVER executes it automatically. Instead, it prints the command, and lets you retrieve the command with a simple press on UP ARROW key.
Vity is fully open source, and it supports all OpenAI compatible LLM providers, including Ollama, VLLM and other self-hosted options.
Supports all major providers: Claude, Gemini, OpenAI, Ollama, VLLM etc
Vity is open-source on GitHub – try it out!
Try vity: https://github.com/kaleab-ayenew/vity
https://redd.it/1mf9689
@r_bash
Vity is an open-source terminal assistant that lets you turn natural language instructions into shell commands.
Built for those of you who are not command-line wizards, but still occasionally need to battle the terminal.
In addition to generating commands, Vity also lets you ask questions based on your terminal history.
Vity adds the generated command to terminal history, but NEVER executes it automatically. Instead, it prints the command, and lets you retrieve the command with a simple press on UP ARROW key.
Vity is fully open source, and it supports all OpenAI compatible LLM providers, including Ollama, VLLM and other self-hosted options.
Supports all major providers: Claude, Gemini, OpenAI, Ollama, VLLM etc
Vity is open-source on GitHub – try it out!
Try vity: https://github.com/kaleab-ayenew/vity
https://redd.it/1mf9689
@r_bash
GitHub
GitHub - Kaleab-Ayenew/vity
Contribute to Kaleab-Ayenew/vity development by creating an account on GitHub.
Prompt persistente desde Bash — sin memoria externa, ni RAG, solo texto 🧠
Hay una forma de mantener “memoria” y personalidad en modelos locales (llama.cpp) solo usando Bash. Sin herramientas raras ni cosas externas.
El personaje se llama **R12D12** y responde como si fuera un robot técnico, sin florituras.
Básicamente:
* El comportamiento está dentro del propio prompt .txt
* Se lanza desde Bash con llama.cpp
* Y aunque el modelo no tiene memoria real, se mantiene estable solo por cómo está escrito el texto.
[Sin RAG, sin embeddings, sin API. Todo vive en texto plano.](https://preview.redd.it/6k0jssfwkrgf1.png?width=3456&format=png&auto=webp&s=7b316c9b8384b0394f3e425fd75ce2d95fd187a8)
📎 [https://github.com/BiblioGalactic/Robotsdelamanecer](https://github.com/BiblioGalactic/Robotsdelamanecer)
¿Alguien más jugando con esto en terminal? ¿O soy el raro? 🤖
https://redd.it/1mge63i
@r_bash
Hay una forma de mantener “memoria” y personalidad en modelos locales (llama.cpp) solo usando Bash. Sin herramientas raras ni cosas externas.
El personaje se llama **R12D12** y responde como si fuera un robot técnico, sin florituras.
Básicamente:
* El comportamiento está dentro del propio prompt .txt
* Se lanza desde Bash con llama.cpp
* Y aunque el modelo no tiene memoria real, se mantiene estable solo por cómo está escrito el texto.
[Sin RAG, sin embeddings, sin API. Todo vive en texto plano.](https://preview.redd.it/6k0jssfwkrgf1.png?width=3456&format=png&auto=webp&s=7b316c9b8384b0394f3e425fd75ce2d95fd187a8)
📎 [https://github.com/BiblioGalactic/Robotsdelamanecer](https://github.com/BiblioGalactic/Robotsdelamanecer)
¿Alguien más jugando con esto en terminal? ¿O soy el raro? 🤖
https://redd.it/1mge63i
@r_bash
edit-and-execute-command ignores $VISUAL when
When bash is run in posix and vi mode, it seems
$ set -x -o posix -o vi
$ export EDITOR=vim
$
# press
++ fc -e vi
+++ vi /tmp/bash-fc.kBdfnM
$
But when run in emacs mode with
https://redd.it/1mfvvh2
@r_bash
set -o posix -o viWhen bash is run in posix and vi mode, it seems
edit-and-execute-command ignores both $VISUAL, $EDITOR and $FCEDIT, and instead uses vi. Are anyone able to reproduce this?$ set -x -o posix -o vi
$ export EDITOR=vim
$
# press
v when in command mode++ fc -e vi
+++ vi /tmp/bash-fc.kBdfnM
$
But when run in emacs mode with
set -o emacs, it correctly uses the program specified by the env vars. Is this a bug or expected behavior?https://redd.it/1mfvvh2
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
☄️ Structured Personality AI Experiment (llama.cpp)
previous tests with “Alex” and R12D12, here’s a collection of entities with predefined behavior. These are not general-purpose chatbots, but functional narrative profiles — each with its own internal framework.
Robots:
HAL\_10
Da1ta1
Vender
CC-33PPOO
Each one:
🤖 responds from within its role, not from the user’s intent
🫡 maintains tone, structure, and narrative constraints
🎭 doesn’t improvise, it interprets
🔄 doesn’t hallucinate, it follows internal logic
Designed to run fully offline — no RAG, no embeddings, no external dependencies.
Just prompt engineering, modular structure (prompt.txt, config, README, and per-profile examples).
Repository:
(http://github.com/BiblioGalactic/Robotsdelamanecer)
Can serve as a base for operational simulation, narrative training, or controlled interaction with role-based AIs under local execution.
Signed: Eto Demerzel
Motto: If something can be narrated, it can be replicated.
https://redd.it/1mgunx4
@r_bash
previous tests with “Alex” and R12D12, here’s a collection of entities with predefined behavior. These are not general-purpose chatbots, but functional narrative profiles — each with its own internal framework.
Robots:
HAL\_10
Da1ta1
Vender
CC-33PPOO
Each one:
🤖 responds from within its role, not from the user’s intent
🫡 maintains tone, structure, and narrative constraints
🎭 doesn’t improvise, it interprets
🔄 doesn’t hallucinate, it follows internal logic
Designed to run fully offline — no RAG, no embeddings, no external dependencies.
Just prompt engineering, modular structure (prompt.txt, config, README, and per-profile examples).
Repository:
(http://github.com/BiblioGalactic/Robotsdelamanecer)
Can serve as a base for operational simulation, narrative training, or controlled interaction with role-based AIs under local execution.
Signed: Eto Demerzel
Motto: If something can be narrated, it can be replicated.
https://redd.it/1mgunx4
@r_bash
GitHub
GitHub - BiblioGalactic/Robotsdelamanecer: Saga robots
Saga robots. Contribute to BiblioGalactic/Robotsdelamanecer development by creating an account on GitHub.
Bash 100%
>🧠 Estoy trabajando en un sistema de personalidades IA usando llama.cpp completamente en local. Toda la orquestación está hecha en Bash con modularidad por perfiles (prompt.txt, config, launcher.sh, etc.).
>
>¿Alguien más ha trabajado con Bash para estructurar prompts o manejar memoria contextual? Estoy usando distancia Levenshtein + control de tokens, y me encantaría feedback técnico sobre la arquitectura de los noscripts.
https://redd.it/1mh36rp
@r_bash
>🧠 Estoy trabajando en un sistema de personalidades IA usando llama.cpp completamente en local. Toda la orquestación está hecha en Bash con modularidad por perfiles (prompt.txt, config, launcher.sh, etc.).
>
>¿Alguien más ha trabajado con Bash para estructurar prompts o manejar memoria contextual? Estoy usando distancia Levenshtein + control de tokens, y me encantaría feedback técnico sobre la arquitectura de los noscripts.
https://redd.it/1mh36rp
@r_bash
Cloned Revolut App
🛑 I’m facing some problems with: ExpoModulesCore, some classes and cocoa pods I’ve been stuck for 6h. I would grateful if someone could help me out 🥲
https://redd.it/1mh90v8
@r_bash
🛑 I’m facing some problems with: ExpoModulesCore, some classes and cocoa pods I’ve been stuck for 6h. I would grateful if someone could help me out 🥲
https://redd.it/1mh90v8
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Newbie - Need help understanding an error in my noscript
Hey guys, I have a basic bash noscript I made for the purpose of checking for any disconnected file shares (missing mount points) on my proxmox VE host and automatically attempting to re-map the missing shares. This is so that if my NAS turns on after my proxmox VE host for any reason, I won't have to log into the host manually and run "mount -a" myself.
This is literally my first bash noscript beyond the usual "Hello World!" (and first noscript of any kind outside of basic AutoHotkey noscripts and some light PowerShell). At this stage, my noscript is working and serving its intended purpose along with an appropriate cron job schedule to run this noscript every 5 minutes, however I am noting an error "./Auto-Mount.sh: line 59: : command not found" every time the noscript runs and finds that a file share is missing and needs to be reconnected. If the noscript exits after finding that all file shares are already connected, this error is not logged. Regardless of this error, the noscript functions as expected.
I have identified which line (line 59: if "$any_still_false"; then) is throwing the error but I can't for the life of me understand why? Any help you guys could offer would be awesome... Feel free to constructively critique my code or documentation as well since it's my first go!
Side note: I'm hoping entering the code into this post with a code block is sufficient to make this as readable as possible. If there's a better way of formatting this in a reddit post, please tell me so I can edit the post.
\- - - - - - - - - -
"$mount1"
"$mount2"
https://redd.it/1mhf7f1
@r_bash
Hey guys, I have a basic bash noscript I made for the purpose of checking for any disconnected file shares (missing mount points) on my proxmox VE host and automatically attempting to re-map the missing shares. This is so that if my NAS turns on after my proxmox VE host for any reason, I won't have to log into the host manually and run "mount -a" myself.
This is literally my first bash noscript beyond the usual "Hello World!" (and first noscript of any kind outside of basic AutoHotkey noscripts and some light PowerShell). At this stage, my noscript is working and serving its intended purpose along with an appropriate cron job schedule to run this noscript every 5 minutes, however I am noting an error "./Auto-Mount.sh: line 59: : command not found" every time the noscript runs and finds that a file share is missing and needs to be reconnected. If the noscript exits after finding that all file shares are already connected, this error is not logged. Regardless of this error, the noscript functions as expected.
I have identified which line (line 59: if "$any_still_false"; then) is throwing the error but I can't for the life of me understand why? Any help you guys could offer would be awesome... Feel free to constructively critique my code or documentation as well since it's my first go!
Side note: I'm hoping entering the code into this post with a code block is sufficient to make this as readable as possible. If there's a better way of formatting this in a reddit post, please tell me so I can edit the post.
\- - - - - - - - - -
#!/bin/bash# Define the list of mount points to be checked as statementsmount1="mountpoint -q "/mnt/nas-media""mount2="mountpoint -q "/mnt/nas2-media""#mount3="mountpoint -q "/mnt/nas3-backup""#mount4="mountpoint -q "/mnt/something-else""# Store the mount point statements in an array# Be sure to only include current mount points that should be checked# Any old or invalid mount points defined as statements in the array will eval to falsemount_points=("$mount1"
"$mount2"
)any_false=false# Check if each mount point exists and print to the console any that do notfor stmt in "${mount_points[@]}"; doif ! eval "$stmt"; thensleep 1echo "Mount point not found: $stmt"any_false=truefidone# Evalute whether all mount points exist or not, and attempt to re-stablish missing mountsif "$any_false"; thensleep 1echo "Not all mount points exist."sleep 1echo "Attempting to re-establish mount points in fstab..."mount -asleep 2elsesleep 1echo "All mount points already exist."any_still_false=falseexit 0fi# Check again and report any mount points still missingfor stmt in "${mount_points[@]}"; doif ! eval "$stmt"; thensleep 1echo "Mount point still not found: $stmt"any_still_false=truefidone# Report on the final outcome of the programif "$any_still_false"; thensleep 1echo "Failed to establish one or more mount points."exit 1elsesleep 1echo "All mount points now exist."exit 0fihttps://redd.it/1mhf7f1
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Personality system
🧠 I'm working on an AI personality system using llama.cpp completely locally. All orchestration is done in Bash with modularity by profiles (prompt.txt, config, launcher.sh, etc.).
Has anyone else worked with Bash to structure prompts or handle contextual memory? I'm using Levenshtein distance + token control, and I would love technical feedback on the architecture of the noscripts.
https://redd.it/1mhpciq
@r_bash
🧠 I'm working on an AI personality system using llama.cpp completely locally. All orchestration is done in Bash with modularity by profiles (prompt.txt, config, launcher.sh, etc.).
Has anyone else worked with Bash to structure prompts or handle contextual memory? I'm using Levenshtein distance + token control, and I would love technical feedback on the architecture of the noscripts.
https://redd.it/1mhpciq
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Read command resulting in a lack of logs.
In my bash noscript, I have a function that logs some stuff and then requests a user input based on the content logged before it. The issue is that those logs don't get logged until I do the user input first, which is obviously not intended. Am I doing something wrong?
I'm using:
Also, if it helps, I'm using Git Bash for Windows.
Thanks for the help in advance!
https://redd.it/1mhmikx
@r_bash
In my bash noscript, I have a function that logs some stuff and then requests a user input based on the content logged before it. The issue is that those logs don't get logged until I do the user input first, which is obviously not intended. Am I doing something wrong?
I'm using:
read -p "Input: " choiceAlso, if it helps, I'm using Git Bash for Windows.
Thanks for the help in advance!
https://redd.it/1mhmikx
@r_bash
How to make bash noscript to archive each folder to separate rar/zip and retain the name?
The folder structure is
\- Main Folder
\-- Subfolder
\---Subsubfolder
\---Subsubfolder
\-- Subfolder
\---Subsubfolder
\---Subsubfolder
I want to archieve each subsubfolder that have different name and retain the rar name same as the original folder name. I tried by using this video noscript, this comment noscript, this noscript, and using chat gpt but still no clue.
https://redd.it/1mie7d3
@r_bash
The folder structure is
\- Main Folder
\-- Subfolder
\---Subsubfolder
\---Subsubfolder
\-- Subfolder
\---Subsubfolder
\---Subsubfolder
I want to archieve each subsubfolder that have different name and retain the rar name same as the original folder name. I tried by using this video noscript, this comment noscript, this noscript, and using chat gpt but still no clue.
https://redd.it/1mie7d3
@r_bash
YouTube
Batch Script: Zip and Unzip Files
█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█▀█
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
[Synopsis] }
▄▄▄▄▄▄▄▄▄▄▄▄
This video shows you how to use a batch noscript to zip and unzip files.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄…
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
[Synopsis] }
▄▄▄▄▄▄▄▄▄▄▄▄
This video shows you how to use a batch noscript to zip and unzip files.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄…
Process Priority Manager
# nicemgr
## The Story
I am ashamed to admit, despite years doing sysadmin work/software development, it wasn't until today that I learned about nice values for running processes. For those of you that also are unaware, a nice value tells your OS which programs to prioritize, and by what weights, when resources are constrained.
My relevant example, a long running ffmpeg process, making it impossible to use my computer for days, but me desperately desiring to play BG3 in the evening after work. Solution: nice values. Nice indicates how willing a process is to share CPU cycles with other programs. They range from -20 through 20. Negative nice values are greedy and unwilling to share. Positive values are happy to get whatever CPU cycles are available. The higher the nice value, the happier they are to let other processes use all of your CPU resources.
The solution worked great, but I was finding it a bit of a chore going through all the steps to find the PID, check the current nice value, or adjust them as the syntax isn't the most memorable. I'm attaching a wrapper below for those interested. This can be used across macOS and most linux distros. Hope you find this helpful!!
## TLDR;
- **What “nice” is:** process priority from –20 (greedy) to +20 (polite)
- **Why it matters:** lets CPU-hog jobs yield to interactive apps
- **My use-case:** reniced ffmpeg so I could finally play Baldur’s Gate 3
- Wrapper noscript below to simplify use of this nifty tool
## Script
```
#!/usr/bin/env bash
# nicer: Check or adjust the nice values of specific processes or list all processes sorted by nice.
#
# Usage:
# nicer checkALL
# nicer <process-name> check
# nicer <process-name> <niceValue>
#
# checkALL List PID, nice, and command for all processes sorted by nice (asc).
# check Show current nice value(s) for <process-name>.
# niceValue Integer from -20 (highest) to 20 (lowest) to renice matching processes.
#
# Note: Negative nice values require root or the process owner.
set -euo pipefail
# Ensure required commands are available
for cmd in pgrep ps sort renice uname; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: '$cmd' command not found. Please install it." >&2
exit 1
fi
done
# Describe a nice value in human-friendly terms
priority_desc() {
local nv=$1
case $nv in
-20) echo "top priority." ;;
-19|-18|-17|-16|-15|-14|-13|-12|-11|-10)
echo "high priority level \"$nv\"." ;;
-9|-8|-7|-6|-5|-4|-3|-2|-1)
echo "priority level \"$nv\"." ;;
0) echo "standard priority." ;;
1|2|3|4|5|6|7|8|9|10)
echo "background priority \"$nv\"." ;;
11|12|13|14|15|16|17|18|19)
echo "low priority \"$nv\"." ;;
20) echo "lowest priority." ;;
*) echo "nice value \"$nv\" out of range." ;;
esac
}
# Print usage and exit
usage() {
cat <<EOF >&2
Usage: $(basename "$0") checkALL
$(basename "$0") <process-name> check
$(basename "$0") <process-name> <niceValue>
checkALL List PID, nice, and command for all processes sorted by nice (asc).
check Show current nice value(s) for <process-name>.
niceValue Integer from -20 (highest) to 20 (lowest) to renice matching processes.
Note: Negative nice values require root or the process owner.
EOF
exit 1
}
# Detect OS for ps options
OS=$(uname)
if [ "$OS" = "Linux" ]; then
PS_LIST_OPTS=( -eo pid,ni,comm ) # GNU ps
elif [ "$OS" = "Darwin" ]; then
PS_LIST_OPTS=( axo pid,ni,comm ) # BSD ps on macOS
else
echo "Unsupported OS: $OS" >&2
exit 1
fi
# Must have at least one argument
if [ $# -lt 1 ]; then
usage
fi
# Global all-process check
if [ "$1" = "checkALL" ]; then
ps "${PS_LIST_OPTS[@]}" | sort -n -k2
exit 0
fi
# Per-process operations expect exactly two arguments
if [ $# -ne 2 ]; then
usage
fi
proc_name=$1
action=$2
# Find PIDs matching process name (exact match)
# Using read -a for compatibility with Bash 3.x
read -r -a pids <<< "$(pgrep -x "$proc_name" || echo)"
# Ensure we have at least one non-empty
# nicemgr
## The Story
I am ashamed to admit, despite years doing sysadmin work/software development, it wasn't until today that I learned about nice values for running processes. For those of you that also are unaware, a nice value tells your OS which programs to prioritize, and by what weights, when resources are constrained.
My relevant example, a long running ffmpeg process, making it impossible to use my computer for days, but me desperately desiring to play BG3 in the evening after work. Solution: nice values. Nice indicates how willing a process is to share CPU cycles with other programs. They range from -20 through 20. Negative nice values are greedy and unwilling to share. Positive values are happy to get whatever CPU cycles are available. The higher the nice value, the happier they are to let other processes use all of your CPU resources.
The solution worked great, but I was finding it a bit of a chore going through all the steps to find the PID, check the current nice value, or adjust them as the syntax isn't the most memorable. I'm attaching a wrapper below for those interested. This can be used across macOS and most linux distros. Hope you find this helpful!!
## TLDR;
- **What “nice” is:** process priority from –20 (greedy) to +20 (polite)
- **Why it matters:** lets CPU-hog jobs yield to interactive apps
- **My use-case:** reniced ffmpeg so I could finally play Baldur’s Gate 3
- Wrapper noscript below to simplify use of this nifty tool
## Script
```
#!/usr/bin/env bash
# nicer: Check or adjust the nice values of specific processes or list all processes sorted by nice.
#
# Usage:
# nicer checkALL
# nicer <process-name> check
# nicer <process-name> <niceValue>
#
# checkALL List PID, nice, and command for all processes sorted by nice (asc).
# check Show current nice value(s) for <process-name>.
# niceValue Integer from -20 (highest) to 20 (lowest) to renice matching processes.
#
# Note: Negative nice values require root or the process owner.
set -euo pipefail
# Ensure required commands are available
for cmd in pgrep ps sort renice uname; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: '$cmd' command not found. Please install it." >&2
exit 1
fi
done
# Describe a nice value in human-friendly terms
priority_desc() {
local nv=$1
case $nv in
-20) echo "top priority." ;;
-19|-18|-17|-16|-15|-14|-13|-12|-11|-10)
echo "high priority level \"$nv\"." ;;
-9|-8|-7|-6|-5|-4|-3|-2|-1)
echo "priority level \"$nv\"." ;;
0) echo "standard priority." ;;
1|2|3|4|5|6|7|8|9|10)
echo "background priority \"$nv\"." ;;
11|12|13|14|15|16|17|18|19)
echo "low priority \"$nv\"." ;;
20) echo "lowest priority." ;;
*) echo "nice value \"$nv\" out of range." ;;
esac
}
# Print usage and exit
usage() {
cat <<EOF >&2
Usage: $(basename "$0") checkALL
$(basename "$0") <process-name> check
$(basename "$0") <process-name> <niceValue>
checkALL List PID, nice, and command for all processes sorted by nice (asc).
check Show current nice value(s) for <process-name>.
niceValue Integer from -20 (highest) to 20 (lowest) to renice matching processes.
Note: Negative nice values require root or the process owner.
EOF
exit 1
}
# Detect OS for ps options
OS=$(uname)
if [ "$OS" = "Linux" ]; then
PS_LIST_OPTS=( -eo pid,ni,comm ) # GNU ps
elif [ "$OS" = "Darwin" ]; then
PS_LIST_OPTS=( axo pid,ni,comm ) # BSD ps on macOS
else
echo "Unsupported OS: $OS" >&2
exit 1
fi
# Must have at least one argument
if [ $# -lt 1 ]; then
usage
fi
# Global all-process check
if [ "$1" = "checkALL" ]; then
ps "${PS_LIST_OPTS[@]}" | sort -n -k2
exit 0
fi
# Per-process operations expect exactly two arguments
if [ $# -ne 2 ]; then
usage
fi
proc_name=$1
action=$2
# Find PIDs matching process name (exact match)
# Using read -a for compatibility with Bash 3.x
read -r -a pids <<< "$(pgrep -x "$proc_name" || echo)"
# Ensure we have at least one non-empty
PID
if [ ${#pids[@]} -eq 0 ] || [ -z "${pids[0]:-}" ]; then
echo "No processes found matching '$proc_name'." >&2
exit 1
fi
# Show current nice values
if [ "$action" = "check" ]; then
for pid in "${pids[@]}"; do
nice_val=$(ps -o ni= -p "$pid" | tr -d ' ')
echo "$proc_name \"PID: $pid\" is currently set to $(priority_desc "$nice_val")"
done
exit 0
fi
# Renice if numeric argument
if [[ "$action" =~ ^-?[0-9]+$ ]]; then
if (( action < -20 || action > 20 )); then
echo "Error: nice value must be between -20 and 20." >&2
exit 1
fi
for pid in "${pids[@]}"; do
if renice "$action" -p "$pid" &>/dev/null; then
echo "$proc_name \"PID: $pid\" has been adjusted to $(priority_desc "$action")"
else
echo "Failed to renice PID $pid (permission denied?)" >&2
fi
done
exit 0
fi
# Invalid action provided
echo "Invalid action: must be 'check' or a numeric nice value." >&2
usage
```
https://redd.it/1migur6
@r_bash
if [ ${#pids[@]} -eq 0 ] || [ -z "${pids[0]:-}" ]; then
echo "No processes found matching '$proc_name'." >&2
exit 1
fi
# Show current nice values
if [ "$action" = "check" ]; then
for pid in "${pids[@]}"; do
nice_val=$(ps -o ni= -p "$pid" | tr -d ' ')
echo "$proc_name \"PID: $pid\" is currently set to $(priority_desc "$nice_val")"
done
exit 0
fi
# Renice if numeric argument
if [[ "$action" =~ ^-?[0-9]+$ ]]; then
if (( action < -20 || action > 20 )); then
echo "Error: nice value must be between -20 and 20." >&2
exit 1
fi
for pid in "${pids[@]}"; do
if renice "$action" -p "$pid" &>/dev/null; then
echo "$proc_name \"PID: $pid\" has been adjusted to $(priority_desc "$action")"
else
echo "Failed to renice PID $pid (permission denied?)" >&2
fi
done
exit 0
fi
# Invalid action provided
echo "Invalid action: must be 'check' or a numeric nice value." >&2
usage
```
https://redd.it/1migur6
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Writing Your Own Simple Tab-Completions for Bash and Zsh
https://mill-build.org/blog/14-bash-zsh-completion.html
https://redd.it/1mjrifb
@r_bash
https://mill-build.org/blog/14-bash-zsh-completion.html
https://redd.it/1mjrifb
@r_bash
Reddit
From the bash community on Reddit: Writing Your Own Simple Tab-Completions for Bash and Zsh
Posted by lihaoyi - 1 vote and 0 comments
Practicing bash
Hello folks, I have started to learn bash for DevOps, what are some ways I can practice bash noscripts to get a good hands-on and become comfortable using it
https://redd.it/1ml24gb
@r_bash
Hello folks, I have started to learn bash for DevOps, what are some ways I can practice bash noscripts to get a good hands-on and become comfortable using it
https://redd.it/1ml24gb
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
using parenthesis for execution
Is there any advantage or disadvantage to using parenthesis for the following execution of the "find" command:
as opposed to using the same command without the parenthesis like so:
Both seem to produce the same result, so don't fully understand the parenthesis in the first "find". I am trying to make sure that I understand when and when not to use the parenthesis considering that it can affect the flow of evaluation. Just thought in this example it would not have mattered.
thanks for the help
https://redd.it/1ml3au5
@r_bash
Is there any advantage or disadvantage to using parenthesis for the following execution of the "find" command:
sudo find / \( -mtime +30 -iname '*.zip' \) -exec cp {} /home/donnie \;as opposed to using the same command without the parenthesis like so:
sudo find / -mtime +30 -iname '*.zip' -exec cp {} /home/donnie \;Both seem to produce the same result, so don't fully understand the parenthesis in the first "find". I am trying to make sure that I understand when and when not to use the parenthesis considering that it can affect the flow of evaluation. Just thought in this example it would not have mattered.
thanks for the help
https://redd.it/1ml3au5
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
how do we use the flag "-F" (-F from ls -Fla) in find?
Hi, I'd like to know if we can use a "highligt" for dirs in the output of find ./ -name 'something' for diff between dirs and files ...
Thank you and regards!
https://redd.it/1mls1tg
@r_bash
Hi, I'd like to know if we can use a "highligt" for dirs in the output of find ./ -name 'something' for diff between dirs and files ...
Thank you and regards!
https://redd.it/1mls1tg
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
I can't see the advantage of vdir vs. ls -l cmd
**Hi**, I was reading about vdir (https://www.reddit.com/r/vim/comments/1midti4/vidir_and_vipe_command_utilities_that_use_vim/) and reading man vdir it is like ls -l
*What is the use of vdir cmd? what is its advantage?
*Thank you and Regards!*
https://redd.it/1mmknd6
@r_bash
**Hi**, I was reading about vdir (https://www.reddit.com/r/vim/comments/1midti4/vidir_and_vipe_command_utilities_that_use_vim/) and reading man vdir it is like ls -l
*What is the use of vdir cmd? what is its advantage?
*Thank you and Regards!*
https://redd.it/1mmknd6
@r_bash
Reddit
From the vim community on Reddit
Explore this post and more from the vim community