How can I pass a variable to jq in a loop
I am trying to create a loop to create a new object but it seems like "something name": ~~$line~~ throws an error as jq is not able to handle $line in that format. Any clue to how I should wrap it?
bonus: jq also always adds an empty value to my members array. Any clue how to remove it? The input is a line separated list
​
az ad group list --filter "startswith(displayName,'something')" --query ".displayName" -o tsv | \
while read line; \
do az ad group member list \
--group $line \
--query ".mail" -o tsv | \
jq -Rs 'split("\n") | \
{"something name": $line, "members": .}' ; \
done
​
https://redd.it/14flxcg
@r_bash
I am trying to create a loop to create a new object but it seems like "something name": ~~$line~~ throws an error as jq is not able to handle $line in that format. Any clue to how I should wrap it?
bonus: jq also always adds an empty value to my members array. Any clue how to remove it? The input is a line separated list
​
az ad group list --filter "startswith(displayName,'something')" --query ".displayName" -o tsv | \
while read line; \
do az ad group member list \
--group $line \
--query ".mail" -o tsv | \
jq -Rs 'split("\n") | \
{"something name": $line, "members": .}' ; \
done
​
https://redd.it/14flxcg
@r_bash
Reddit
r/bash on Reddit: How can I pass a variable to jq in a loop
Posted by u/blackfalconx - No votes and 2 comments
Whitespace password generator
#!/bin/bash
# Generate a purely whitespace password with 128 bits of symmetric security.
#
# Characters are strictly non-control, non-graphical spaces/blanks. Both
# nonzero- and zero-width characters are used. Two characters are technically
# vertical characters, but aren't interpreted as such in the shell. They are
# "\u2028" and "\u2029". You might need a font with good Unicode support to
# prevent some of these characters creating tofu.
rng() {
# Cryptographically secure RNG
local min=$((2 32 % 30)) # 30 = size of $s below
local r=$SRANDOM
while "$r" -lt "$min" ; do r=$SRANDOM; done # Modulo with rejection
echo "$(($r % 30))"
}
s=(
# Non-zero width characters
"\u0009" # Character tabulation
"\u0020" # Space
"\u00A0" # Non-breaking space
"\u2000" # En quad
"\u2001" # Em quad
"\u2002" # En space
"\u2003" # Em space
"\u2004" # Three-per-em space
"\u2005" # Four-per-em space
"\u2006" # Six-per-em space
"\u2007" # Figure space
"\u2008" # Punctuation space
"\u2009" # Thin space
"\u200A" # Hair space
"\u2028" # Line separator
"\u2029" # Paragraph separator
"\u202F" # Narrow no-break space
"\u205F" # Medium mathematical space
"\u2800" # Braille pattern blank
"\u3000" # Ideographic space
"\u3164" # Hangul filler
"\uFFA0" # Halfwidth hangul filler
# Zero width characters
"\u115F" # Hangul choseong filler
"\u1160" # Hangul jungseong filler
"\u180E" # Mongolian vowel separator
"\u200B" # Zero width space
"\u200C" # Zero width non-joiner
"\u200D" # Zero width joiner
"\u2060" # Word joiner
"\uFEFF" # Zero width non-breaking space
)
p=""
# Generate 27 characters for at least 128 bits security
for i in {1..27}; do
r=$(rng)
c=${s$r}
p="${p}${c}"
done
tabs -1 # Tab width of 1 space
# Wrap the password in braille pattern blanks for correctly handling zero-width
# characters at the edges and to prevent whitespace stripping by the auth form.
echo -e "\"\u2800${p}\u2800\""
Example:
$ bash /tmp/whitespace.bash
"⠀ ⠀ ᅠᅠᅠㅤ ⠀ ⠀"
https://redd.it/14hfrou
@r_bash
#!/bin/bash
# Generate a purely whitespace password with 128 bits of symmetric security.
#
# Characters are strictly non-control, non-graphical spaces/blanks. Both
# nonzero- and zero-width characters are used. Two characters are technically
# vertical characters, but aren't interpreted as such in the shell. They are
# "\u2028" and "\u2029". You might need a font with good Unicode support to
# prevent some of these characters creating tofu.
rng() {
# Cryptographically secure RNG
local min=$((2 32 % 30)) # 30 = size of $s below
local r=$SRANDOM
while "$r" -lt "$min" ; do r=$SRANDOM; done # Modulo with rejection
echo "$(($r % 30))"
}
s=(
# Non-zero width characters
"\u0009" # Character tabulation
"\u0020" # Space
"\u00A0" # Non-breaking space
"\u2000" # En quad
"\u2001" # Em quad
"\u2002" # En space
"\u2003" # Em space
"\u2004" # Three-per-em space
"\u2005" # Four-per-em space
"\u2006" # Six-per-em space
"\u2007" # Figure space
"\u2008" # Punctuation space
"\u2009" # Thin space
"\u200A" # Hair space
"\u2028" # Line separator
"\u2029" # Paragraph separator
"\u202F" # Narrow no-break space
"\u205F" # Medium mathematical space
"\u2800" # Braille pattern blank
"\u3000" # Ideographic space
"\u3164" # Hangul filler
"\uFFA0" # Halfwidth hangul filler
# Zero width characters
"\u115F" # Hangul choseong filler
"\u1160" # Hangul jungseong filler
"\u180E" # Mongolian vowel separator
"\u200B" # Zero width space
"\u200C" # Zero width non-joiner
"\u200D" # Zero width joiner
"\u2060" # Word joiner
"\uFEFF" # Zero width non-breaking space
)
p=""
# Generate 27 characters for at least 128 bits security
for i in {1..27}; do
r=$(rng)
c=${s$r}
p="${p}${c}"
done
tabs -1 # Tab width of 1 space
# Wrap the password in braille pattern blanks for correctly handling zero-width
# characters at the edges and to prevent whitespace stripping by the auth form.
echo -e "\"\u2800${p}\u2800\""
Example:
$ bash /tmp/whitespace.bash
"⠀ ⠀ ᅠᅠᅠㅤ ⠀ ⠀"
https://redd.it/14hfrou
@r_bash
Reddit
r/bash on Reddit: Whitespace password generator
Posted by u/atoponce - 6 votes and 4 comments
What is the "-" called and what is it exactly doing?
hey bashers,
tar -cvzf - some.file | split -b 150M - "some.file-part"
I know what this line does, but I do not really understand the " - " and i don't know how this concept is called. Does this have a name? "Buffer into Terminal"?
​
Best
​
https://redd.it/14jevh3
@r_bash
hey bashers,
tar -cvzf - some.file | split -b 150M - "some.file-part"
I know what this line does, but I do not really understand the " - " and i don't know how this concept is called. Does this have a name? "Buffer into Terminal"?
​
Best
​
https://redd.it/14jevh3
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Keep a Mac awake for any duration with a user friendly easy to setup noscript that uses the native MacOS pmset disablesleep
Hey all,
​
I often need to prevent a Mac from sleeping and Caffeinate & Amphetamine are neither open source not work very well so I created a light user friendly Bash noscript with more advanced options.
​
You can keep your Mac awake indefinitely or for any duration you set. It also works when a MacBook lid is closed and to cancel a sleep you simply press the return key. Can't be easier than that..
​
You can specify a wake duration in seconds, minutes, or hours, and it can even handle multiple arguments at the same time. (e.g. by running ```./stay-awake 1h 30m 15s```)
​
Check out the open-source repository at - [https://github.com/Post2Fix/macos-stay-awake\](https://github.com/Post2Fix/macos-stay-awake)
​
There are simple instructions on how to setup and run a Bash noscript on MacOS which can be handy to know anyway.
​
I'll try to turn it into an executable MacOS app for everyone but until then hopefully some early adopters will find it useful. Let me know if you have any suggestions or issues.
​
Best.
https://redd.it/14mmksd
@r_bash
Hey all,
​
I often need to prevent a Mac from sleeping and Caffeinate & Amphetamine are neither open source not work very well so I created a light user friendly Bash noscript with more advanced options.
​
You can keep your Mac awake indefinitely or for any duration you set. It also works when a MacBook lid is closed and to cancel a sleep you simply press the return key. Can't be easier than that..
​
You can specify a wake duration in seconds, minutes, or hours, and it can even handle multiple arguments at the same time. (e.g. by running ```./stay-awake 1h 30m 15s```)
​
Check out the open-source repository at - [https://github.com/Post2Fix/macos-stay-awake\](https://github.com/Post2Fix/macos-stay-awake)
​
There are simple instructions on how to setup and run a Bash noscript on MacOS which can be handy to know anyway.
​
I'll try to turn it into an executable MacOS app for everyone but until then hopefully some early adopters will find it useful. Let me know if you have any suggestions or issues.
​
Best.
https://redd.it/14mmksd
@r_bash
GitHub
GitHub - Post2Fix/macos-stay-awake: Easily executable noscript file to prevent MacOS sleep for a specified duration
Easily executable noscript file to prevent MacOS sleep for a specified duration - GitHub - Post2Fix/macos-stay-awake: Easily executable noscript file to prevent MacOS sleep for a specified duration
Point me in the right direction, please - writing a bash function involving a user prompt
So I'm trying to make a function that creates the directory structure for ansible roles, example command that works standalone, below:
mkdir -p RoleName/{tasks,handlers,defaults,vars,templates}
I've only really done basic work in bash, so I'm a bit lost.
I initially tried to setup an alias, init-role, to run the above using "read -p" to get the folder name, but that didn't quite work. After searching around online, it seems a function is what I want. Here is a list of commands that work, and would probably work if I threw them into a noscript:
# ask for the name of the role
read -p 'Enter the role name: ' RoleName
# use RoleName as the root folder, and make the subfolders
mkdir -p $RoleName/{tasks,handlers,defaults,vars,templates}
# Remove the alias
unset $RoleName
# Show the directory structure
tree
After configuring my \~/.bashrc to look at \~/.bash_functions, and threw the above into a function, I quickly learned it wasn't correct. This is what I have:
function init-role () {
# ask for the name of the role
read -p 'Enter the role name: ' RoleName
# use RoleName as the root folder, and make the subfolders
mkdir -p $RoleName/{tasks,handlers,defaults,vars,templates}
# Remove the alias
unset $RoleName
# Show the directory structure
tree
}
Right now I'm stuck on getting user input and putting it into a variable. I've tried:
$RoleName = read -p 'Enter the role name: '
$RoleName = read -p "Enter the role name: "
$RoleName = "read -p Enter the role name: "
My search queries aren't getting me anywhere regarding getting user input, and assigning it to a variable, within a function. I'm sure it's out there, I'm just not finding it.
​
It's probably clear that I haven't written a bash function before, and I'm not really looking for an answer to be handed to me, but rather a pointer in the right direction, please.
https://redd.it/14mszdj
@r_bash
So I'm trying to make a function that creates the directory structure for ansible roles, example command that works standalone, below:
mkdir -p RoleName/{tasks,handlers,defaults,vars,templates}
I've only really done basic work in bash, so I'm a bit lost.
I initially tried to setup an alias, init-role, to run the above using "read -p" to get the folder name, but that didn't quite work. After searching around online, it seems a function is what I want. Here is a list of commands that work, and would probably work if I threw them into a noscript:
# ask for the name of the role
read -p 'Enter the role name: ' RoleName
# use RoleName as the root folder, and make the subfolders
mkdir -p $RoleName/{tasks,handlers,defaults,vars,templates}
# Remove the alias
unset $RoleName
# Show the directory structure
tree
After configuring my \~/.bashrc to look at \~/.bash_functions, and threw the above into a function, I quickly learned it wasn't correct. This is what I have:
function init-role () {
# ask for the name of the role
read -p 'Enter the role name: ' RoleName
# use RoleName as the root folder, and make the subfolders
mkdir -p $RoleName/{tasks,handlers,defaults,vars,templates}
# Remove the alias
unset $RoleName
# Show the directory structure
tree
}
Right now I'm stuck on getting user input and putting it into a variable. I've tried:
$RoleName = read -p 'Enter the role name: '
$RoleName = read -p "Enter the role name: "
$RoleName = "read -p Enter the role name: "
My search queries aren't getting me anywhere regarding getting user input, and assigning it to a variable, within a function. I'm sure it's out there, I'm just not finding it.
​
It's probably clear that I haven't written a bash function before, and I'm not really looking for an answer to be handed to me, but rather a pointer in the right direction, please.
https://redd.it/14mszdj
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How can I add this functionality to my Bash?
In this video the presenter installs zsh and is able to type
https://redd.it/14v7kqm
@r_bash
In this video the presenter installs zsh and is able to type
git st, then use the tab key to bring up a list of commands that start with git st (stash, status, stripspace) and brief denoscriptions of each. Is there a way to do this with Bash?https://redd.it/14v7kqm
@r_bash
YouTube
My development environment | From scratch | Ubuntu | 2020
Setting up my Linux development environment from scratch in Ubuntu.
⏱️TIMESTAMPS⏱️
0:00 - My development environment - From scratch - Ubuntu
0:07 - Start of the video
0:50 - Terminals
0:51 - Terminator
2:16 - Alacritty
3:12 - Fundamental tools installation…
⏱️TIMESTAMPS⏱️
0:00 - My development environment - From scratch - Ubuntu
0:07 - Start of the video
0:50 - Terminals
0:51 - Terminator
2:16 - Alacritty
3:12 - Fundamental tools installation…
Execute a command in every sub-directory that contains wav files.
# Problem is solved! Thank you all for Helping! See comments for solution.
Hey there,
I have a collection of Drum Staples for Producing Music. The are Organized in different Folder for every Drum-Machine. In most sub-directories the samples are located directly in this folder. In some directories there are sub-folders for the different sounds (bass drum, snare, hats...).
I need a noscript or command that executes "normalize-audio -b \*.wav" in every sub-directory.
Searching the Web, I found this:
find ./* -type d -execdir echo Doing something in folder {} \; -execdir echo Done something in {} \;
It works well and executes the Echo command in every Sub. So i Changed it to
find ./* -type d -execdir normalize-audio -b {}/*.wav;
I tried it without the {} and put the Normalize Command in ' , But it just gives me error messages, mostly this one:
find: missing argument to `-execdir'
I've been tinkering with this command for 3 hours. Now it's time to admit that this is above my level and ask the community for advice.
Greetings from Germany!
https://redd.it/14v4rtw
@r_bash
# Problem is solved! Thank you all for Helping! See comments for solution.
Hey there,
I have a collection of Drum Staples for Producing Music. The are Organized in different Folder for every Drum-Machine. In most sub-directories the samples are located directly in this folder. In some directories there are sub-folders for the different sounds (bass drum, snare, hats...).
I need a noscript or command that executes "normalize-audio -b \*.wav" in every sub-directory.
Searching the Web, I found this:
find ./* -type d -execdir echo Doing something in folder {} \; -execdir echo Done something in {} \;
It works well and executes the Echo command in every Sub. So i Changed it to
find ./* -type d -execdir normalize-audio -b {}/*.wav;
I tried it without the {} and put the Normalize Command in ' , But it just gives me error messages, mostly this one:
find: missing argument to `-execdir'
I've been tinkering with this command for 3 hours. Now it's time to admit that this is above my level and ask the community for advice.
Greetings from Germany!
https://redd.it/14v4rtw
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
A universal noscript to open Firefox with piped search terms in Bash
#!/bin/bash
set -e
shopt -s lastpipe
read -r input;
getos () {
unames="$(uname -s)"
if echo "$unames" | grep 'Darwin' >/dev/null
then
baseos='osx'
else
if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then
baseos='windows'
else
baseos='linux'
fi
fi
echo $baseos
}
setfirefoxpath () {
if [ "$(getos)" == "windows" ]; then
export FIREFOXBIN="/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
elif [ "$(getos)" == "linux" ]; then
export FIREFOXBIN="firefox"
elif [ "$(getos)" == "osx" ]; then
export FIREFOXBIN="/Applications/Firefox.app/Contents/MacOS/firefox"
else
echo "Unknown OS"
exit 1
fi
}
google () {
TLD=".co.uk"
search=""
for term in "$@"; do
search="${search}%20${term}"
done
"${FIREFOXBIN}" "https://www.google${TLD}/search?q=${search}" &
}
setfirefoxpath
google "${input}"
https://redd.it/14uosqq
@r_bash
#!/bin/bash
set -e
shopt -s lastpipe
read -r input;
getos () {
unames="$(uname -s)"
if echo "$unames" | grep 'Darwin' >/dev/null
then
baseos='osx'
else
if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then
baseos='windows'
else
baseos='linux'
fi
fi
echo $baseos
}
setfirefoxpath () {
if [ "$(getos)" == "windows" ]; then
export FIREFOXBIN="/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
elif [ "$(getos)" == "linux" ]; then
export FIREFOXBIN="firefox"
elif [ "$(getos)" == "osx" ]; then
export FIREFOXBIN="/Applications/Firefox.app/Contents/MacOS/firefox"
else
echo "Unknown OS"
exit 1
fi
}
google () {
TLD=".co.uk"
search=""
for term in "$@"; do
search="${search}%20${term}"
done
"${FIREFOXBIN}" "https://www.google${TLD}/search?q=${search}" &
}
setfirefoxpath
google "${input}"
https://redd.it/14uosqq
@r_bash
Better way to get variables out of file
I have two files:
#config
nextcloud-1="/var/www/nextcloud-1"
nextcloud-2="/var/www/nextcloud-2"
and the actual noscript:
#!/bin/bash
dir="$1"
dir=$(cat /opt/dirs.txt | grep "$dir" | sed -e 's/.*"\(.*\)".*/\1/')
cd $dir
sudo -u www-data php -f occ app:update --all
This noscript updates all Nextcloud apps on the selected instance: `./updateapps.sh nextcloud-1`. Is there a more efficient way of doing this, with error handling in case of a non-existent directory/variable for directory?
https://redd.it/14tzjik
@r_bash
I have two files:
#config
nextcloud-1="/var/www/nextcloud-1"
nextcloud-2="/var/www/nextcloud-2"
and the actual noscript:
#!/bin/bash
dir="$1"
dir=$(cat /opt/dirs.txt | grep "$dir" | sed -e 's/.*"\(.*\)".*/\1/')
cd $dir
sudo -u www-data php -f occ app:update --all
This noscript updates all Nextcloud apps on the selected instance: `./updateapps.sh nextcloud-1`. Is there a more efficient way of doing this, with error handling in case of a non-existent directory/variable for directory?
https://redd.it/14tzjik
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Help me
So i got this problem as summer homework:
I dont know why but it gives an error :( can someone help me?
https://redd.it/14u6cfy
@r_bash
So i got this problem as summer homework:
Write a bash noscript that prompts the user to enter an upper limit. The program will calculate the sum of all prime numbers between 2 and the specified limit. Next, the program will have to generate a text file called "primes.txt" that will contain the prime numbers found, one per line. This is what i wrote:#!/bin/bash # Function that checks if a number is prime function is_prime() { if (( $1 < 2 )); then return 1 fi for (( i=2; i*i<=$1; i++ )); do if (( $1 % $i == 0 )); then return 1 fi done return 0 } # Function that calculates the sum of prime numbers up to a given limit function calculate_prime_sum() { local limit=$1 local sum=0 for (( num=2; num<=limit; num++ )); do if is_prime $num; then (( sum += num )) fi done echo $sum } # Read a number from input read -p "Enter an upper limit: " limit # Calculate the sum of prime numbers up to the limit prime_sum=$(calculate_prime_sum $limit) echo "The sum of prime numbers up to $limit is $prime_sum" # Generate a text file with prime numbers up to the limit echo "Prime numbers up to $limit:" > primes.txt for (( num=2; num<=limit; num++ )); do if is_prime $num; then echo $num >> primes.txt fi done echo "primes.txt file generated successfully." I dont know why but it gives an error :( can someone help me?
https://redd.it/14u6cfy
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Using printf in a function to replace echo
Since I've learned about some drawbacks of the
So I thought, why not write a function that allows me to use
Something like this:
But I'm not sure if this is syntactically correct. Normally, I would write
Thanks in advance.
https://redd.it/14tl682
@r_bash
Since I've learned about some drawbacks of the
echo command, e.g. the lack of support for -- to indicate the end of options, I thought it would be reasonable to just stick with printf.So I thought, why not write a function that allows me to use
printf without having to retype the format strings.Something like this:
output() {
printf '%s\n' "$*"
}
output "$foo is $bar"
But I'm not sure if this is syntactically correct. Normally, I would write
printf '%s is %s\n' foo bar, instead of printf '%s\n' "$foo is $bar". Both seem to work the same; also, output "foo is bar" gives me the expected result. Shellcheck doesn't complain either. But is it safe to use, or are there any edge cases where my function wouldn't work as expected?Thanks in advance.
https://redd.it/14tl682
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
What is a good tool to enable dynamic auto complete as you type in Bash 5.2
I have seen examples as you type, it will display a popup window above the line with the history of the shell.
https://redd.it/14toulb
@r_bash
I have seen examples as you type, it will display a popup window above the line with the history of the shell.
https://redd.it/14toulb
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Part of noscript doesn't execute when launched through cron
Here is my noscript: (tome is my username)
#!/bin/zsh
month_day=$(date -d "$D" '+%d')
week_day=$(date +%u)
if [ $month_day = 07 ] || [ $month_day = 14 ] || [ $month_day = 21 ] || [ $month_day = 28 ]
then
echo "$(date +'%H:%M:%S %d/%m/%y : weekly backup '$month_day' starts')" >> /home/tome/.log/backup.log
weekly_backup
echo "$(date +'%H:%M:%S %d/%m/%y : weekly backup '$month_day' ok')" >> /home/tome/.log/backup.log
else
echo "$(date +'%H:%M:%S %d/%m/%y : daily backup '$week_day' starts')" >> /home/tome/.log/backup.log
daily_backup
echo "$(date +'%H:%M:%S %d/%m/%y : daily backup '$week_day' ok')" >> /home/tome/.log/backup.log
fi
updatedb
and the relevant part of the output of `sudo crontab -e`:
0 1 * * * /home/tome/.noscripts/backup
(btw `/home/tome/.noscripts/` is where I store all my noscripts, including `daily_backup`, but I double-checked it's part of `$PATH` both for tome *and* root - also, the permissions are correct and the noscripts are executable).
However, here's what I get :
* from `~/.log/backup6.log` (6 because it's Saturday and that's how I classify my backups): ***simply nothing.***
* from `~/.log/backup.log`:
​
01:00:01 08/07/23 : daily backup 6 starts
01:00:01 08/07/23 : daily backup 6 ok
Notice how the noscript completed in less than one second.
I don't want to put my whole `daily_backup` code here, I don't think that would be useful. Let's just say that the noscript *always* takes *at least* 10 minutes to run, and *a lot* is supposed to end up in `~/.log/backup6.log`, since evey task completed succesfully by the noscript leaves a message in the log.
My only conclusion is that: `backup` launches normally, but then skips `daily_backup` altogether.
And all this only happen when I run `backup` from root cron, if I do a `sudo backup` in a terminal suddenly it seems to work.
Please help if you can (that's really a background job I need cron to do for me)
-----------
EDIT: I think the issue was that `cron` used its own, minimalistic, $PATH. So I specified my $PATH in the `cron` file's beginning, and it works now.
Thanks to everyone for your help.
https://redd.it/14tp1l4
@r_bash
Here is my noscript: (tome is my username)
#!/bin/zsh
month_day=$(date -d "$D" '+%d')
week_day=$(date +%u)
if [ $month_day = 07 ] || [ $month_day = 14 ] || [ $month_day = 21 ] || [ $month_day = 28 ]
then
echo "$(date +'%H:%M:%S %d/%m/%y : weekly backup '$month_day' starts')" >> /home/tome/.log/backup.log
weekly_backup
echo "$(date +'%H:%M:%S %d/%m/%y : weekly backup '$month_day' ok')" >> /home/tome/.log/backup.log
else
echo "$(date +'%H:%M:%S %d/%m/%y : daily backup '$week_day' starts')" >> /home/tome/.log/backup.log
daily_backup
echo "$(date +'%H:%M:%S %d/%m/%y : daily backup '$week_day' ok')" >> /home/tome/.log/backup.log
fi
updatedb
and the relevant part of the output of `sudo crontab -e`:
0 1 * * * /home/tome/.noscripts/backup
(btw `/home/tome/.noscripts/` is where I store all my noscripts, including `daily_backup`, but I double-checked it's part of `$PATH` both for tome *and* root - also, the permissions are correct and the noscripts are executable).
However, here's what I get :
* from `~/.log/backup6.log` (6 because it's Saturday and that's how I classify my backups): ***simply nothing.***
* from `~/.log/backup.log`:
​
01:00:01 08/07/23 : daily backup 6 starts
01:00:01 08/07/23 : daily backup 6 ok
Notice how the noscript completed in less than one second.
I don't want to put my whole `daily_backup` code here, I don't think that would be useful. Let's just say that the noscript *always* takes *at least* 10 minutes to run, and *a lot* is supposed to end up in `~/.log/backup6.log`, since evey task completed succesfully by the noscript leaves a message in the log.
My only conclusion is that: `backup` launches normally, but then skips `daily_backup` altogether.
And all this only happen when I run `backup` from root cron, if I do a `sudo backup` in a terminal suddenly it seems to work.
Please help if you can (that's really a background job I need cron to do for me)
-----------
EDIT: I think the issue was that `cron` used its own, minimalistic, $PATH. So I specified my $PATH in the `cron` file's beginning, and it works now.
Thanks to everyone for your help.
https://redd.it/14tp1l4
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
sudo su in a bash/zsh noscript (but only part of that noscript)
I'm trying to run some noscripts on openSUSE Tumbleweed (or rather its WSL but it doesn't matter)
Here's what I want to do (mind that this code does not work, I'm trying to get as close as possible to this with a working noscript):
#!/bin/zsh
# some command as normal user:
cp /home/tome/.zshrc /home/tome/.zshrcroot
sed -i 's/agnoster/avit/g' /home/tome/.zshrcroot
# and here comes the part I don't know how to do
read -p "root password:" password
sudo su -p $password <<HERE
# here goes some stuff I want to run as the root user (not just prepending a sudo to the commands, the actual root user!)
cp /home/tome/.zshrcroot /root/.zshrc
cp -r /home/tome/.vim /root/.
cp /home/tome/.zshhistory /home/tome/.vimrc /root/.
cd /root
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
git clone https://github.com/zsh-users/zsh-autosuggestions /root/.oh-my-zsh/custom/plugins/zsh-autosuggestions
source /root/.zshrc
source /root/.vimrc
HERE
# and finally some non-sudo user commands again, could be anything
pwd && echo "I'm not sudo"
I found many ways to "run as root" commands in a bash/zsh noscript, but none of them gave me a satifying result... I know I have done this kind of thing to automate SQL commands, so I don't see why I couldn't do it with
All help will be greatly appreciated!
https://redd.it/14thn0c
@r_bash
I'm trying to run some noscripts on openSUSE Tumbleweed (or rather its WSL but it doesn't matter)
Here's what I want to do (mind that this code does not work, I'm trying to get as close as possible to this with a working noscript):
#!/bin/zsh
# some command as normal user:
cp /home/tome/.zshrc /home/tome/.zshrcroot
sed -i 's/agnoster/avit/g' /home/tome/.zshrcroot
# and here comes the part I don't know how to do
read -p "root password:" password
sudo su -p $password <<HERE
# here goes some stuff I want to run as the root user (not just prepending a sudo to the commands, the actual root user!)
cp /home/tome/.zshrcroot /root/.zshrc
cp -r /home/tome/.vim /root/.
cp /home/tome/.zshhistory /home/tome/.vimrc /root/.
cd /root
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
git clone https://github.com/zsh-users/zsh-autosuggestions /root/.oh-my-zsh/custom/plugins/zsh-autosuggestions
source /root/.zshrc
source /root/.vimrc
HERE
# and finally some non-sudo user commands again, could be anything
pwd && echo "I'm not sudo"
I found many ways to "run as root" commands in a bash/zsh noscript, but none of them gave me a satifying result... I know I have done this kind of thing to automate SQL commands, so I don't see why I couldn't do it with
sudo su...?All help will be greatly appreciated!
https://redd.it/14thn0c
@r_bash
GitHub
GitHub - zsh-users/zsh-autosuggestions: Fish-like autosuggestions for zsh
Fish-like autosuggestions for zsh. Contribute to zsh-users/zsh-autosuggestions development by creating an account on GitHub.
Reverse Shell Cheat Sheet: A guide for reverse shells by providing an in-depth understanding of their workings across various programming languages and techniques
https://www.stationx.net/reverse-shell-cheat-sheet/
https://redd.it/14s98qt
@r_bash
https://www.stationx.net/reverse-shell-cheat-sheet/
https://redd.it/14s98qt
@r_bash
StationX
Reverse Shell Cheat Sheet 2025: A Hacking Guide
Discover our Reverse Shell Cheat Sheet, featuring one-liners, listeners, obfuscation, and expert tips to help you master these essential techniques.
What do you think are the good features a bash prompt should have?
I recently went into customizing my PS1 variable and I noticed that Im not really sure of knowing what I want. Do I want to see the full path of my current directory? Do I want to see my user name and hostname? The only thing I know for sure is the git branch. Does anyone has an opinion of what is and what is not a good PS1 variable? Should I use linebreaks for splitting the prompt line from the input? Thank you in advance.
EDIT: no one is talking about differentiating different prompt inputs by using a linebreak. Imho I think this is really helpful.
https://redd.it/14sg2nw
@r_bash
I recently went into customizing my PS1 variable and I noticed that Im not really sure of knowing what I want. Do I want to see the full path of my current directory? Do I want to see my user name and hostname? The only thing I know for sure is the git branch. Does anyone has an opinion of what is and what is not a good PS1 variable? Should I use linebreaks for splitting the prompt line from the input? Thank you in advance.
EDIT: no one is talking about differentiating different prompt inputs by using a linebreak. Imho I think this is really helpful.
https://redd.it/14sg2nw
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
ppd - a pushd/popd alternative written in bash
I use pushd/popd often, however I felt there was something lacking from the functionality offered by those commands, so I decided to build ppd.
ppd allows you to perform the following actions on a directory stack:
- list directories in the stack
- push directories to the stack
- pop directories from the stack
- navigate to directories in the stack
- add directories to the stack
- remove directories from the stack
- clear directories from the stack
You can find a demo of how it works in the README:
https://github.com/paololazzari/ppd
https://redd.it/14sj1cy
@r_bash
I use pushd/popd often, however I felt there was something lacking from the functionality offered by those commands, so I decided to build ppd.
ppd allows you to perform the following actions on a directory stack:
- list directories in the stack
- push directories to the stack
- pop directories from the stack
- navigate to directories in the stack
- add directories to the stack
- remove directories from the stack
- clear directories from the stack
You can find a demo of how it works in the README:
https://github.com/paololazzari/ppd
https://redd.it/14sj1cy
@r_bash
GitHub
GitHub - paololazzari/ppd: ppd is a pushd/popd alternative written in bash
ppd is a pushd/popd alternative written in bash. Contribute to paololazzari/ppd development by creating an account on GitHub.
Elevating Tasks Over Files in the Runme CLI: Vastly simplify the CLI experience for users
https://runme.dev/blog/tasks-over-files-in-runme-cli
https://redd.it/14sedpz
@r_bash
https://runme.dev/blog/tasks-over-files-in-runme-cli
https://redd.it/14sedpz
@r_bash
runme.dev
Elevating Tasks Over Files in the Runme CLI
In today's Runme CLI release, we're shipping Project Mode. Project Mode elevates tasks simplifying the CLI user experience without requiring authors to sacrifice the structure and organization of their markdown files describing runbooks and common workflows.