Running noscripts from master noscript causes them to fail
I have multiple bash noscripts that run in sequence. Normally they are scheduled as cron jobs and work perfectly. But, we want to change the process in which they are run - basically if one of them fails the others will not execute.
So, I decided to put them in a master noscript which calls the other noscripts in sequence. It checks the exit code from each noscript and only executes the next one if the exit code was 0. It sends an alert via email and SMS if there was an error.
The problem is, the individual jobs run just fine as cron jobs but sometimes fail when run from the master cron job. I added a ton of logging, including the old "$logfile" 2>&1, and there is really no reason for the failure. It just randomly fails. The exit code in the called job is 0, but the master noscript thinks it is not.
Is there some trick to getting something like this to work? Am I doing something stupid here and there is a better way to do it?
#!/bin/bash
logger -s "SCRIPT - FOOBARSCRIPTS - Started at $(date)"
. /home/noscripts/alerts/alerts.function
logfile="/fee/fi/fo.fum"
rm -f /fee/fi/fo.fum
touch /fee/fi/fo.fum
#
/bin/bash /foo/bar/baz.sh >> "$logfile" 2>&1
if [ $? -eq 0 ]; then
logger -s "SCRIPT - FOOBARSCRIPTS - /foo/bar/baz.sh completed successfully"
else
logger -s "SCRIPT - FOOBARSCRIPTS - Error running /foo/bar/baz.sh"
sendalert FOOBARSCRIPTS
exit 99
fi
#
/bin/bash /foo/bar/qux.sh >> "$logfile" 2>&1
if $? -eq 0 ; then
logger -s "SCRIPT - FOOBARSCRIPTS - /foo/bar/qux.sh completed successfully"
else
logger -s "SCRIPT - FOOBARSCRIPTS - Error running /foo/bar/qux.sh"
sendalert FOOBARSCRIPTS
exit 99
fi
logger -s "SCRIPT - FOOBARSCRIPTS - Ended at $(date)"
https://redd.it/1ai2wzg
@r_bash
I have multiple bash noscripts that run in sequence. Normally they are scheduled as cron jobs and work perfectly. But, we want to change the process in which they are run - basically if one of them fails the others will not execute.
So, I decided to put them in a master noscript which calls the other noscripts in sequence. It checks the exit code from each noscript and only executes the next one if the exit code was 0. It sends an alert via email and SMS if there was an error.
The problem is, the individual jobs run just fine as cron jobs but sometimes fail when run from the master cron job. I added a ton of logging, including the old "$logfile" 2>&1, and there is really no reason for the failure. It just randomly fails. The exit code in the called job is 0, but the master noscript thinks it is not.
Is there some trick to getting something like this to work? Am I doing something stupid here and there is a better way to do it?
#!/bin/bash
logger -s "SCRIPT - FOOBARSCRIPTS - Started at $(date)"
. /home/noscripts/alerts/alerts.function
logfile="/fee/fi/fo.fum"
rm -f /fee/fi/fo.fum
touch /fee/fi/fo.fum
#
/bin/bash /foo/bar/baz.sh >> "$logfile" 2>&1
if [ $? -eq 0 ]; then
logger -s "SCRIPT - FOOBARSCRIPTS - /foo/bar/baz.sh completed successfully"
else
logger -s "SCRIPT - FOOBARSCRIPTS - Error running /foo/bar/baz.sh"
sendalert FOOBARSCRIPTS
exit 99
fi
#
/bin/bash /foo/bar/qux.sh >> "$logfile" 2>&1
if $? -eq 0 ; then
logger -s "SCRIPT - FOOBARSCRIPTS - /foo/bar/qux.sh completed successfully"
else
logger -s "SCRIPT - FOOBARSCRIPTS - Error running /foo/bar/qux.sh"
sendalert FOOBARSCRIPTS
exit 99
fi
logger -s "SCRIPT - FOOBARSCRIPTS - Ended at $(date)"
https://redd.it/1ai2wzg
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to get the output of a program as finally seen on the screen?
Hi,
I have a program (foo) that outputs something while in progress, then deletes the current line to write the final output:
in progress foo bar<DELETE WHOLE LINE>done foo bar
So the final string seen on the screen is
I'd like to call this program from a bash noscript. The problem I am facing is:
Instead, the prefixed string "Result: " is deleted:
How can I achieve an output like:
https://redd.it/1aimagi
@r_bash
Hi,
I have a program (foo) that outputs something while in progress, then deletes the current line to write the final output:
in progress foo bar<DELETE WHOLE LINE>done foo bar
So the final string seen on the screen is
[done] foo bar.I'd like to call this program from a bash noscript. The problem I am facing is:
echo "Result: $(foo)" does not result in: Result: [done] foo barInstead, the prefixed string "Result: " is deleted:
[done] foo barHow can I achieve an output like:
Result: [done] foo barhttps://redd.it/1aimagi
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Block, I-beam, or Underscore. What's your kink?
Can't tolerate block, underscore tolerable, but beam is the boss.
https://redd.it/1ain39t
@r_bash
Can't tolerate block, underscore tolerable, but beam is the boss.
https://redd.it/1ain39t
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
[update] forkrun (the insanely fast pure-bash loop parallelizer) just got updated to v1.1 and got a new feature!!!
Earlier today I pushed a larger update to the main [forkrun](https://github.com/jkool702/forkrun) branch on github, bumping it up to forkrun v1.1.
For those that missed it, [here](https://www.reddit.com/r/bash/comments/19985k2/presenting_forkrun_the_fastest_purebash_loop/?utm_source=share&utm_medium=web2x&context=3) is the initial (v1.0) `forkrun` release thread here on /r/bash.
***
**The main "new feature" introduced in forkrun v1.1 is the ability to split up stdin based on the "number of bytes read"**. Previously, you could only split up stdin by the "number of lines read" (or, more generally, by the "number of delimiters read"). Two new flags have been introduced to facilitate this capability: `-b <bytes>` and `-B <bytes>`:
* `-b <bytes>`: this flag causes `forkrun` to read up to `<bytes>` at a time from stdin. However, if less than `<bytes>` is available on stdin when a given worker coproc is reading data it will not wait and will proceed with less than `<bytes>` data
* `-B <bytes>`: this flag causes `forkrun` to read exactly `<bytes>` at a time from stdin. If less than `<bytes>` is available on stdin when a given worker coproc is reading data it will wait and will not proceed until it accumulates `<bytes>` of data or all of stdin has been used.
* for both flags, `<bytes>` can be specified using a trailing `k`, `m`, `g`, `t`, or `p` (for `1000^{1,2,3,4,5}`) or `ki`, `mi`, `gi`, `pi`, or `ti` (for `1024^{1,2,3,4,5}`). Adding the trailing `b` and/or using capital letters is accepted, but does not change anything (e.g., `64kb`, `64KB`, `64kB`, `64Kb`, `64k` and `64K` all mean 64,000 bytes).
There is also a minor enhancement in the `-I` / `--INSERT` flag's functionality, and (of course) a handful of minor bug fixes and even a few more minor optimizations.
***
Its been awesome to hear from a couple of you out there that `forkrun` is being used and is working well! As always, let me know of any bugs you encounter and I'll try to find am squash them ASAP. If `forkrun` is missing a feature that you would find useful feel free to suggest it, and if I can figure out a good way to add it I will.
https://redd.it/1aj2na5
@r_bash
Earlier today I pushed a larger update to the main [forkrun](https://github.com/jkool702/forkrun) branch on github, bumping it up to forkrun v1.1.
For those that missed it, [here](https://www.reddit.com/r/bash/comments/19985k2/presenting_forkrun_the_fastest_purebash_loop/?utm_source=share&utm_medium=web2x&context=3) is the initial (v1.0) `forkrun` release thread here on /r/bash.
***
**The main "new feature" introduced in forkrun v1.1 is the ability to split up stdin based on the "number of bytes read"**. Previously, you could only split up stdin by the "number of lines read" (or, more generally, by the "number of delimiters read"). Two new flags have been introduced to facilitate this capability: `-b <bytes>` and `-B <bytes>`:
* `-b <bytes>`: this flag causes `forkrun` to read up to `<bytes>` at a time from stdin. However, if less than `<bytes>` is available on stdin when a given worker coproc is reading data it will not wait and will proceed with less than `<bytes>` data
* `-B <bytes>`: this flag causes `forkrun` to read exactly `<bytes>` at a time from stdin. If less than `<bytes>` is available on stdin when a given worker coproc is reading data it will wait and will not proceed until it accumulates `<bytes>` of data or all of stdin has been used.
* for both flags, `<bytes>` can be specified using a trailing `k`, `m`, `g`, `t`, or `p` (for `1000^{1,2,3,4,5}`) or `ki`, `mi`, `gi`, `pi`, or `ti` (for `1024^{1,2,3,4,5}`). Adding the trailing `b` and/or using capital letters is accepted, but does not change anything (e.g., `64kb`, `64KB`, `64kB`, `64Kb`, `64k` and `64K` all mean 64,000 bytes).
There is also a minor enhancement in the `-I` / `--INSERT` flag's functionality, and (of course) a handful of minor bug fixes and even a few more minor optimizations.
***
Its been awesome to hear from a couple of you out there that `forkrun` is being used and is working well! As always, let me know of any bugs you encounter and I'll try to find am squash them ASAP. If `forkrun` is missing a feature that you would find useful feel free to suggest it, and if I can figure out a good way to add it I will.
https://redd.it/1aj2na5
@r_bash
GitHub
GitHub - jkool702/forkrun: runs multiple inputs through a noscript/function in parallel using bash coprocs
runs multiple inputs through a noscript/function in parallel using bash coprocs - jkool702/forkrun
bash command overwritten by later command
Under what conditions can a bash command be overwritten by a later command?
https://redd.it/1ajd4je
@r_bash
Under what conditions can a bash command be overwritten by a later command?
https://redd.it/1ajd4je
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
LLUVIA DE IDEAS PARA UN SCRIPT Y CONTRIBUYENTES
Hola soy un novato en bash y me gustaria tener un compañero o gente que quiera contribuir a mi reposito de github (https://github.com/Arbolencio/NetPurge) discord:arbolencio
https://redd.it/1ajit4a
@r_bash
Hola soy un novato en bash y me gustaria tener un compañero o gente que quiera contribuir a mi reposito de github (https://github.com/Arbolencio/NetPurge) discord:arbolencio
https://redd.it/1ajit4a
@r_bash
GitHub
GitHub - Arbolencio/NetPurge: noscript based on the dsniff tool to kick out or block the internet to intruders from a network
noscript based on the dsniff tool to kick out or block the internet to intruders from a network - GitHub - Arbolencio/NetPurge: noscript based on the dsniff tool to kick out or block the internet to in...
Bash noscript that turns on the led on the mute key
I have a working bash noscript, but so far I have not implemented a trigger for it. It also requires sudo privileges which I'm afraid may interfere. How do I trigger this noscript when I press a specific function key (certainly not a bash noscripting question, sorry)? Currently it's in a .noscripts folder in $HOME. Here's the noscript:
I know this is quite a small noscript but any suggestions on making the noscript is appreciated.
Thank you.
https://redd.it/1ajhtyg
@r_bash
I have a working bash noscript, but so far I have not implemented a trigger for it. It also requires sudo privileges which I'm afraid may interfere. How do I trigger this noscript when I press a specific function key (certainly not a bash noscripting question, sorry)? Currently it's in a .noscripts folder in $HOME. Here's the noscript:
echo `amixer get Capture | tail -n 2 | grep -q '\[on\]'; echo $?` | sudo tee /sys/class/leds/platform\:\:micmute/brightness
I know this is quite a small noscript but any suggestions on making the noscript is appreciated.
Thank you.
https://redd.it/1ajhtyg
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
scp-turbo
Speeding up multiple files copy over SSH, uses
This is a bash wrapper for running something like
github gist
https://redd.it/1ajkmvh
@r_bash
Speeding up multiple files copy over SSH, uses
scp syntax, e.g. scp-turbo.sh myremote:/etc/apache2 /backups/apacheconf. (assuming myremote is an alias you have configured in ~/.ssh/config)This is a bash wrapper for running something like
tar -czf - /etc/apache2 | ssh myremote "tar -xzf - -C /backups/apacheconf".#!/usr/bin/env bash
# uses scp syntax e.g.:
#
# REMOTE -> LOCAL
# scp-turbo.sh myremote:/etc/apache2 /tmp/mylocal/dir
#
# LOCAL -> REMOTE
# scp-turbo.sh /tmp/mylocal/dir myremote:/home/user32/
if [[ $# -eq 0 ]]; then
printf "USAGE:\n\t${0##*/} <source> <destination>\n\n"
echo "NOTE: Source and destination can be in the format host:path or just path"
exit 1
fi
source=$1
dest=$2
if [[ $source == *:* ]]; then
source_host=${source%%:*}
source_dir=${source#*:}
else
source_host=""
source_dir=$source
fi
if [[ $dest == *:* ]]; then
dest_host=${dest%%:*}
dest_dir=${dest#*:}
else
dest_host=""
dest_dir=$dest
fi
echo SOURCE_HOST: "$source_host"
echo SOURCE_DIR: "$source_dir"
echo
echo DEST_HOST: "$dest_host"
echo DEST_DIR: "$dest_dir"
read -p "Press any key to start copying..." -n 1 -s
# create target dir if not exist
if [[ ! -d "$dest_dir" ]]; then
mkdir -p "$dest_dir"
fi
# REMOTE -> LOCAL
if [[ -z "$dest_host" ]] && [[ -n "$source_host" ]] && [[ -n "$source_dir" ]] && [[ -n "$dest_dir" ]]; then
ssh "$source_host" tar --ignore-failed-read -cvf - -C "$source_dir" . | tar xvf - -C "${dest_dir}"
echo "Done!"
exit 0
fi
# LOCAL -> REMOTE
if [[ -z "$source_host" ]] && [[ -n "$source_dir" ]] && [[ -n "$dest_host" ]] && [[ -n "$dest_dir" ]]; then
ssh "$dest_host" mkdir -p "$dest_dir"
tar -cvf - -C "${source_dir}" . | ssh "$dest_host" "tar -xvf - -C $dest_dir"
echo "Done!"
exit 0
fi
github gist
https://redd.it/1ajkmvh
@r_bash
Gist
Copy folders between local <=> SSH remote using tar piped over SSH using scp syntax like: `scp-turbo.sh myremote:/etc/apache2 …
Copy folders between local <=> SSH remote using tar piped over SSH using scp syntax like: `scp-turbo.sh myremote:/etc/apache2 /tmp/mylocal/dir` - scp-turbo-ssh-tar.sh
Replace output with next one while running noscript
I have this command that runs a noscript containing functions with wget
$SUDOCOMMAND ./$arg 2>&1 | grep -v ": "
This is a part of the long output I can see (from 1 to 100%)
...
152250K .......... .......... .......... .......... .......... 75% 8,15M 6s
152300K .......... .......... .......... .......... .......... 75% 8,53M 6s
152350K .......... .......... .......... .......... .......... 75% 9,76M 6s
152400K .......... .......... .......... .......... .......... 75% 8,49M 6s
152450K .......... .......... .......... .......... .......... 75% 8,46M 6s
152500K .......... .......... .......... .......... .......... 76% 6,30M 6s
152550K .......... .......... .......... .......... .......... 76% 8,51M 6s
152600K .......... .......... .......... .......... .......... 76% 8,11M 6s
152650K .......... .......... .......... .......... .......... 76% 8,14M 6s
152700K .......... .......... .......... .......... .......... 76% 8,51M 6s
152750K .......... .......... .......... .......... .......... 76% 8,85M 6s
152800K .......... .......... .......... .......... .......... 76% 8,52M 6s
152850K .......... .......... .......... .......... .......... 76% 8,46M 6s
152900K .......... .......... .......... .......... .......... 76% 6,72M 6s
152950K .......... .......... .......... .......... .......... 76% 8,94M 6s
153000K .......... .......... .......... .......... .......... 76% 8,14M 6s
153050K .......... .......... .......... .......... .......... 76% 8,48M 6s
153100K .......... .......... .......... .......... .......... 76% 8,88M 6s
153150K .......... .......... .......... .......... .......... 76% 6,09M 6s
153200K .......... .......... .......... .......... .......... 76% 8,49M 6s
...
How can I overwrite each line with the next one (until it reaches 100%) to have a smaller output (so I can see percentage and countdown on the right increasing/decreasing)?
https://redd.it/1ajxwfs
@r_bash
I have this command that runs a noscript containing functions with wget
$SUDOCOMMAND ./$arg 2>&1 | grep -v ": "
This is a part of the long output I can see (from 1 to 100%)
...
152250K .......... .......... .......... .......... .......... 75% 8,15M 6s
152300K .......... .......... .......... .......... .......... 75% 8,53M 6s
152350K .......... .......... .......... .......... .......... 75% 9,76M 6s
152400K .......... .......... .......... .......... .......... 75% 8,49M 6s
152450K .......... .......... .......... .......... .......... 75% 8,46M 6s
152500K .......... .......... .......... .......... .......... 76% 6,30M 6s
152550K .......... .......... .......... .......... .......... 76% 8,51M 6s
152600K .......... .......... .......... .......... .......... 76% 8,11M 6s
152650K .......... .......... .......... .......... .......... 76% 8,14M 6s
152700K .......... .......... .......... .......... .......... 76% 8,51M 6s
152750K .......... .......... .......... .......... .......... 76% 8,85M 6s
152800K .......... .......... .......... .......... .......... 76% 8,52M 6s
152850K .......... .......... .......... .......... .......... 76% 8,46M 6s
152900K .......... .......... .......... .......... .......... 76% 6,72M 6s
152950K .......... .......... .......... .......... .......... 76% 8,94M 6s
153000K .......... .......... .......... .......... .......... 76% 8,14M 6s
153050K .......... .......... .......... .......... .......... 76% 8,48M 6s
153100K .......... .......... .......... .......... .......... 76% 8,88M 6s
153150K .......... .......... .......... .......... .......... 76% 6,09M 6s
153200K .......... .......... .......... .......... .......... 76% 8,49M 6s
...
How can I overwrite each line with the next one (until it reaches 100%) to have a smaller output (so I can see percentage and countdown on the right increasing/decreasing)?
https://redd.it/1ajxwfs
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Online environment for online demo of bash projects
I'm making a text based adventure game in bash and I'm looking for a way to set up a shareable environment with my git repo cloned and set up to play the game in the browser.
I only need a hand full of shell tools like cat, grep, ls and such.
I tried replit, but idk if I did it wrong or what, but the shared replit doesn't show the bash console so that rules it out.
I've been searching for about an hour now and the only option seems to be to setup xterm.js with some kind of backed that runs bash code in a server.
I'm sure I've seen other repos that had an in-browser demo of their noscripts, but I can't remember what they used.
Is there a (preferably free) service or tool or website that I can use for this purpose?
PS: I could probably redirect people to jslinux but all my pretty boxes break and look like a*s there.
https://redd.it/1ak2sum
@r_bash
I'm making a text based adventure game in bash and I'm looking for a way to set up a shareable environment with my git repo cloned and set up to play the game in the browser.
I only need a hand full of shell tools like cat, grep, ls and such.
I tried replit, but idk if I did it wrong or what, but the shared replit doesn't show the bash console so that rules it out.
I've been searching for about an hour now and the only option seems to be to setup xterm.js with some kind of backed that runs bash code in a server.
I'm sure I've seen other repos that had an in-browser demo of their noscripts, but I can't remember what they used.
Is there a (preferably free) service or tool or website that I can use for this purpose?
PS: I could probably redirect people to jslinux but all my pretty boxes break and look like a*s there.
https://redd.it/1ak2sum
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Pass argument to bash noscript to vary end of a path?
I have a noscript that will do something with a path like:
Launch /home/joe/file1
Launch /home/joe/file2
You'd basically pass the "file2" as an argument to the noscript and it fills in the file1 or file2 or whatever depending on the argument you supply to the noscript.
So typing "somenoscript.sh file1"
Would build the line
Launch /home/joe/file1
If I typed "somenoscript.sh foo" it'll make:
Launch /home/joe/foo
Thanks
https://redd.it/1ak5q8y
@r_bash
I have a noscript that will do something with a path like:
Launch /home/joe/file1
Launch /home/joe/file2
You'd basically pass the "file2" as an argument to the noscript and it fills in the file1 or file2 or whatever depending on the argument you supply to the noscript.
So typing "somenoscript.sh file1"
Would build the line
Launch /home/joe/file1
If I typed "somenoscript.sh foo" it'll make:
Launch /home/joe/foo
Thanks
https://redd.it/1ak5q8y
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Test if variable is a float?
Hi
I test if a variable contains an integer like this
[ $var == ?(-)+([[:digit:]) ]]
Is there a similar test to see if it is a float, say 1.23 or -1.23
Thanks
​
https://redd.it/1ak9a1l
@r_bash
Hi
I test if a variable contains an integer like this
[ $var == ?(-)+([[:digit:]) ]]
Is there a similar test to see if it is a float, say 1.23 or -1.23
Thanks
​
https://redd.it/1ak9a1l
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Any flaws in this noscript that could be potentially bad?
#!/bin/bash
# Check if three arguments are provided
if "$#" -ne 3 ; then
echo "Usage: $0 <begtime> <endtime> <logfilegzipped>"
exit 1
fi
beg=$1
end=$2
logfilegzipped=$3
function nongzipped() {
LCALL=C awk -v beg="$beg" -v end="$end" '
match($0, /0-20-9:0-50-9:0-50-9/) {
t = substr($0, RSTART, 8)
if (t >= end) selected = 0
else if (t >= beg) selected = 1
}
selected' "$logfilegzipped" #ignore the name lol
}
function gzipped() {
zcat "$logfilegzipped" | LCALL=C awk -v beg="$beg" -v end="$end" '
match($0, /[0-2][0-9]:[0-5][0-9]:[0-5][0-9]/) {
t = substr($0, RSTART, 8)
if (t >= end) selected = 0
else if (t >= beg) selected = 1
}
selected'
}
if [[ "$logfilegzipped" == *.gz ]]; then
gzipped
else
nongzipped
fi
I just modified this noscript that I wrote few months ago to accomodate both cases of gzipped and non gzipped log files. Any flaws with this you can notice. This works on my machine.
Any ways to make this better? Please don't post solutions. I'd have asked chatgpt but I like the journey in learning rather than getting answers quickly. Only correct me if there is serious flaw in this.
https://redd.it/1akbuj9
@r_bash
#!/bin/bash
# Check if three arguments are provided
if "$#" -ne 3 ; then
echo "Usage: $0 <begtime> <endtime> <logfilegzipped>"
exit 1
fi
beg=$1
end=$2
logfilegzipped=$3
function nongzipped() {
LCALL=C awk -v beg="$beg" -v end="$end" '
match($0, /0-20-9:0-50-9:0-50-9/) {
t = substr($0, RSTART, 8)
if (t >= end) selected = 0
else if (t >= beg) selected = 1
}
selected' "$logfilegzipped" #ignore the name lol
}
function gzipped() {
zcat "$logfilegzipped" | LCALL=C awk -v beg="$beg" -v end="$end" '
match($0, /[0-2][0-9]:[0-5][0-9]:[0-5][0-9]/) {
t = substr($0, RSTART, 8)
if (t >= end) selected = 0
else if (t >= beg) selected = 1
}
selected'
}
if [[ "$logfilegzipped" == *.gz ]]; then
gzipped
else
nongzipped
fi
I just modified this noscript that I wrote few months ago to accomodate both cases of gzipped and non gzipped log files. Any flaws with this you can notice. This works on my machine.
Any ways to make this better? Please don't post solutions. I'd have asked chatgpt but I like the journey in learning rather than getting answers quickly. Only correct me if there is serious flaw in this.
https://redd.it/1akbuj9
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Any better solutions than this one?
https://redd.it/1akuntp
@r_bash
print_progress(){
local progress_msg="${1}"; shift
local separator_string=
for ((i = 0; i < COLUMNS; i = i + 1)); do
separator_string+='='
done
printf '\n%s\n%s\n%s\n' \
"${separator_string}" \
"${progress_msg}" \
"${separator_string}"
}
print_progress 'Currently doing blablabla...'
https://redd.it/1akuntp
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Help with noscript - creating a 'simple' compose file on remote server via ssh
I run a bash noscript on my local pc. Its configures a remote server by ssh, adding users, installing docker etc. Theres a part in it that writes and then runs a traefik compose file but there is a line in it that bash doent seem to like:
\- "traefik.http.routers.api.rule=Host(`website.com`)"
It ends up writing the line:
\- "traefik.http.routers.api.rule=Host()"
This causes the container to fail.
​
Ive even tried (unsuccessfully) writing the file with commands such as:
printf '%s\\n' " - traefik.http.routers.api.rule=Host('website.com')"
​
How do i get round this problem. GPT is looping on me and getting nowhere. Part of my noscript:
​
su - bob -c "
\# Create and write to the file
cat > docker-compose_traefik.yml << 'EOF'
version: "3.3"
​
services:
traefik:
image: traefik:v3.0
restart: always
container_name: traefik
ports:
\- "80:80"
\- "8080:8080"
\- "443:443"
command:
\- --api.insecure=true
\- --api.dashboard=true
\- --api.debug=true
\- --log.level=DEBUG
\- --providers.docker=true
\- --providers.docker.exposedbydefault=false
\- --providers.file.filename=/dynamic.yaml
\- --providers.docker.network=web
\- --entrypoints.web.address=:80
volumes:
\- /var/run/docker.sock:/var/run/docker.sock
\- ./dynamic.yaml:/dynamic.yaml
networks:
\- web
labels:
\- "traefik.enable=true"
\- "traefik.http.routers.api.rule=Host(`website.com`)"
\- "traefik.http.routers.api.service=api@internal" access
​
networks:
web:
external: true
EOF
​
https://redd.it/1akyrk4
@r_bash
I run a bash noscript on my local pc. Its configures a remote server by ssh, adding users, installing docker etc. Theres a part in it that writes and then runs a traefik compose file but there is a line in it that bash doent seem to like:
\- "traefik.http.routers.api.rule=Host(`website.com`)"
It ends up writing the line:
\- "traefik.http.routers.api.rule=Host()"
This causes the container to fail.
​
Ive even tried (unsuccessfully) writing the file with commands such as:
printf '%s\\n' " - traefik.http.routers.api.rule=Host('website.com')"
​
How do i get round this problem. GPT is looping on me and getting nowhere. Part of my noscript:
​
su - bob -c "
\# Create and write to the file
cat > docker-compose_traefik.yml << 'EOF'
version: "3.3"
​
services:
traefik:
image: traefik:v3.0
restart: always
container_name: traefik
ports:
\- "80:80"
\- "8080:8080"
\- "443:443"
command:
\- --api.insecure=true
\- --api.dashboard=true
\- --api.debug=true
\- --log.level=DEBUG
\- --providers.docker=true
\- --providers.docker.exposedbydefault=false
\- --providers.file.filename=/dynamic.yaml
\- --providers.docker.network=web
\- --entrypoints.web.address=:80
volumes:
\- /var/run/docker.sock:/var/run/docker.sock
\- ./dynamic.yaml:/dynamic.yaml
networks:
\- web
labels:
\- "traefik.enable=true"
\- "traefik.http.routers.api.rule=Host(`website.com`)"
\- "traefik.http.routers.api.service=api@internal" access
​
networks:
web:
external: true
EOF
​
https://redd.it/1akyrk4
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Code review request
I tested the program on 5 machines running on matic 23.10 and cant find any issues. Would like to know if there are any issues with the code. As code is broken down into many functions i cant upload snippets here.
I would like reviewers to point to memory_init function which is an odd ball in the whole hierarchy.
Here is the link.
https://github.com/ioprojecton/CPU-Y
Thanks.
https://redd.it/1al1lw9
@r_bash
I tested the program on 5 machines running on matic 23.10 and cant find any issues. Would like to know if there are any issues with the code. As code is broken down into many functions i cant upload snippets here.
I would like reviewers to point to memory_init function which is an odd ball in the whole hierarchy.
Here is the link.
https://github.com/ioprojecton/CPU-Y
Thanks.
https://redd.it/1al1lw9
@r_bash
GitHub
GitHub - ioprojecton/CPU-Y: System info for Ubuntu
System info for Ubuntu. Contribute to ioprojecton/CPU-Y development by creating an account on GitHub.
Issue with a simple Bash Script for adding an iRule to a list of Virtual Servers.
Hello Community,
I am quite new to Bash noscripting. Though I know the platform I intend the noscript to run on is not relevant to this sub, I would appreciate if you could at least elevate my concern that the problem I am encountering is with my Bash noscript itself and not the environment I'm running it on.
I am having an issue with a bash noscript for an F5 BIG-IP Load Balancer which is intended to:
1. Take as input a .txt file named "vs_list.txt" containing a list of Virtual Server Names, each on a separate row.
2. Prompt the user for the name of the iRule that needs to be added to the Virtual Servers.
3. Iterate over the VS Names from the input list and retreives the partition in which each VS resides (building on F5 Support Solution K59493724: How to get details of the virtual servers in all partitions via TMSH? (https://my.f5.com/manage/s/article/K59493724))
4. Checks for and retrevies the iRules which are currently configured for the given VS# Adds the new iRule to the given VS and coserves pre-existing iRules if any.
When running the noscript I am only hitting the outermost 'else' statement for being unable to find the partition and VS name.
#!/bin/bash
# Prompt the user for the iRule name and read it into the 'new' variable
echo "Please enter the iRule name:"
read new
noneRules='rules none'
while IFS= read -r vsname; do
# Retrieve the partition and virtual server name
fullvsinfo=$(tmsh -c "cd /; list ltm virtual recursive" | grep "$vsname" | grep -m1 "^ltm virtual")
echo "Full VS Info Debug: $fullvsinfo"
# Extract the partition and virtual server name from the retrieved information
if [ $full_vs_info =~ ltm\ virtual\ (.+)/(.+) ]; then
partition="${BASHREMATCH[1]}"
vsname="${BASHREMATCH[2]}"
# Format the tmsh command to include the partition
rule=$(tmsh list ltm virtual /$partition/$vsname rules | egrep -v "\{|\}" | xargs)
if [ "$rule" == "$noneRules" ]; then
tmsh modify ltm virtual /$partition/$vsname rules { $new }
echo "iRule $new was added to $vsname in partition $partition"
else#
tmsh modify ltm virtual /$partition/$vsname rules { $rule $new }
echo "iRules $rule were conserved and added $new to $vsname in partition $partition"
fi
else
echo "Could not find partition and virtual server name for $vsname"
fi
done < /shared/tmp/testlist.txt
tmsh save sys config
As far as I was able to troubleshoot, the problem I am encountering appears to be with line 11 of my noscript where I attempt to assign the string "ltm virtual SomePartition/VS_Example.com {" to the "full_vs_info" variable using:
full_vs_info=$(tmsh -c "cd /; list ltm virtual recursive" | grep "$vs_name" | grep -m1 "\^ltm virtual")
When I run the tmsh command [tmsh -c "cd /; list ltm virtual recursive" | grep "VS_Example.com" | grep -m1 "\^ltm virtual"\] on its own, from the F5's Bash shell, I am getting the output I expect:
"ltm virtual SomePartition/VS_Example.com {"
However, when I run the noscript with the debug echo , it only outputs "Full VS Info Debug:", and ends the noscript with "Could not find partition and virtual server name for $vs_name" and a sys config save.
If at all relevant, I am attempting to run this on a BIG-IP, version (https://15.1.10.2), build 0.44.2.
All feedback and criticism is highly appreciated! Thanks in advance!
https://redd.it/1al6h61
@r_bash
Hello Community,
I am quite new to Bash noscripting. Though I know the platform I intend the noscript to run on is not relevant to this sub, I would appreciate if you could at least elevate my concern that the problem I am encountering is with my Bash noscript itself and not the environment I'm running it on.
I am having an issue with a bash noscript for an F5 BIG-IP Load Balancer which is intended to:
1. Take as input a .txt file named "vs_list.txt" containing a list of Virtual Server Names, each on a separate row.
2. Prompt the user for the name of the iRule that needs to be added to the Virtual Servers.
3. Iterate over the VS Names from the input list and retreives the partition in which each VS resides (building on F5 Support Solution K59493724: How to get details of the virtual servers in all partitions via TMSH? (https://my.f5.com/manage/s/article/K59493724))
4. Checks for and retrevies the iRules which are currently configured for the given VS# Adds the new iRule to the given VS and coserves pre-existing iRules if any.
When running the noscript I am only hitting the outermost 'else' statement for being unable to find the partition and VS name.
#!/bin/bash
# Prompt the user for the iRule name and read it into the 'new' variable
echo "Please enter the iRule name:"
read new
noneRules='rules none'
while IFS= read -r vsname; do
# Retrieve the partition and virtual server name
fullvsinfo=$(tmsh -c "cd /; list ltm virtual recursive" | grep "$vsname" | grep -m1 "^ltm virtual")
echo "Full VS Info Debug: $fullvsinfo"
# Extract the partition and virtual server name from the retrieved information
if [ $full_vs_info =~ ltm\ virtual\ (.+)/(.+) ]; then
partition="${BASHREMATCH[1]}"
vsname="${BASHREMATCH[2]}"
# Format the tmsh command to include the partition
rule=$(tmsh list ltm virtual /$partition/$vsname rules | egrep -v "\{|\}" | xargs)
if [ "$rule" == "$noneRules" ]; then
tmsh modify ltm virtual /$partition/$vsname rules { $new }
echo "iRule $new was added to $vsname in partition $partition"
else#
tmsh modify ltm virtual /$partition/$vsname rules { $rule $new }
echo "iRules $rule were conserved and added $new to $vsname in partition $partition"
fi
else
echo "Could not find partition and virtual server name for $vsname"
fi
done < /shared/tmp/testlist.txt
tmsh save sys config
As far as I was able to troubleshoot, the problem I am encountering appears to be with line 11 of my noscript where I attempt to assign the string "ltm virtual SomePartition/VS_Example.com {" to the "full_vs_info" variable using:
full_vs_info=$(tmsh -c "cd /; list ltm virtual recursive" | grep "$vs_name" | grep -m1 "\^ltm virtual")
When I run the tmsh command [tmsh -c "cd /; list ltm virtual recursive" | grep "VS_Example.com" | grep -m1 "\^ltm virtual"\] on its own, from the F5's Bash shell, I am getting the output I expect:
"ltm virtual SomePartition/VS_Example.com {"
However, when I run the noscript with the debug echo , it only outputs "Full VS Info Debug:", and ends the noscript with "Could not find partition and virtual server name for $vs_name" and a sys config save.
If at all relevant, I am attempting to run this on a BIG-IP, version (https://15.1.10.2), build 0.44.2.
All feedback and criticism is highly appreciated! Thanks in advance!
https://redd.it/1al6h61
@r_bash
F5
How to get details of the virtual servers in all partitions via TMSH?
Denoscription
You would like to get the details of your virtual servers in all partitions and sub-folders using TMSH. Environment BIG-IP LTM Virtual Servers TMSH Partitions Sub-folders Cause
None Recommended Actions Option 1 You can use the following command…
You would like to get the details of your virtual servers in all partitions and sub-folders using TMSH. Environment BIG-IP LTM Virtual Servers TMSH Partitions Sub-folders Cause
None Recommended Actions Option 1 You can use the following command…
Responsive image gallery in three lines of bash
Three lines of bash to generate a responsive HTML image gallery — motivated by having to spend way too much time on getting /r/immich and /r/photoprism to do what I wanted them to do... both are awesome projects btw.
>❗️NOTE: on MacOS this requires the GNU flavour of
echo '<html><head><style>img {max-width: 321px; height: auto; display: table-cell;} body>div {display: grid; grid-template-columns: repeat(auto-fill, minmax(321px, 1fr)); gap: 5px;}</style></head><body><div>' > gallery.html
find -type f ! -name '.*' -a -iregex '.*\.\(jpg\|jpeg\|png\|noscript\|bmp\|webp\|gif\)' -printf '<a href="%P" target="blank" noscript="%P size: %s bytes; created: %c"><img src="%P" loading="lazy"></a>\n' >> gallery.html
echo '</div></body></html>' >> gallery.html
(the only reason I did not extract
https://redd.it/1amkg1n
@r_bash
Three lines of bash to generate a responsive HTML image gallery — motivated by having to spend way too much time on getting /r/immich and /r/photoprism to do what I wanted them to do... both are awesome projects btw.
>❗️NOTE: on MacOS this requires the GNU flavour of
find — use brew install findutils and replace in the noscript find with gfind.echo '<html><head><style>img {max-width: 321px; height: auto; display: table-cell;} body>div {display: grid; grid-template-columns: repeat(auto-fill, minmax(321px, 1fr)); gap: 5px;}</style></head><body><div>' > gallery.html
find -type f ! -name '.*' -a -iregex '.*\.\(jpg\|jpeg\|png\|noscript\|bmp\|webp\|gif\)' -printf '<a href="%P" target="blank" noscript="%P size: %s bytes; created: %c"><img src="%P" loading="lazy"></a>\n' >> gallery.html
echo '</div></body></html>' >> gallery.html
(the only reason I did not extract
gallery.html to a variable was to keep it to 3 lines)https://redd.it/1amkg1n
@r_bash
Reddit
Immich
High performance self-hosted photo and video management solution
What do you call the '-' when used to specify options (like set -x)?
View Poll
https://redd.it/1amlbbo
@r_bash
View Poll
https://redd.it/1amlbbo
@r_bash
Invoke bash noscript in remote server
I'm running a noscript from my jump host to copy a noscript to client servers. From that copied noscript will run on the client server and check for a specific agent is installed or not. If not it will install through that noscript. But before installation happen I want to raise a standard change servicenow.
Standard change raising noscript also in the jumphost. That only can be run from the jumphost.
So I want to know how can we invoke standard change raising noscript with parsing some information to that from the client machine,
https://redd.it/1amqbf8
@r_bash
I'm running a noscript from my jump host to copy a noscript to client servers. From that copied noscript will run on the client server and check for a specific agent is installed or not. If not it will install through that noscript. But before installation happen I want to raise a standard change servicenow.
Standard change raising noscript also in the jumphost. That only can be run from the jumphost.
So I want to know how can we invoke standard change raising noscript with parsing some information to that from the client machine,
https://redd.it/1amqbf8
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community