case statement
what if i use exit instead of break in this case statement when do and cat are selected what are the difference if this was my noscript ?
echo "Please select an animal"
select animal in dog cat; do
case $animal in
dog)
echo "dog selected break"
break ;;
cat)
echo "cat selected"
break ;;
*)
echo "I don't recognize this animal" ;;
esac
done
https://redd.it/1c8n4lt
@r_bash
what if i use exit instead of break in this case statement when do and cat are selected what are the difference if this was my noscript ?
echo "Please select an animal"
select animal in dog cat; do
case $animal in
dog)
echo "dog selected break"
break ;;
cat)
echo "cat selected"
break ;;
*)
echo "I don't recognize this animal" ;;
esac
done
https://redd.it/1c8n4lt
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Can I run my noscript with options ?
I have my noscript, that I want to use it with options. Should I create functions indead of those cases ?
#!/bin/env bash
# Customize Console
PROMPT_COMMAND='echo -en "\033]0;$(FBD|cut -d "/" -f 4-100)\a"'
now=$(date)
echo "Undertale Jokes, that's all. Mainly. You know, as ya want."
while true
do
#Input
VHS=$(gum input --placeholder " Enter Command")
# Treat Input
case $VHS in
exit | q | esc | bye)
exit
;;
clear | cls)
clear
;;
puns | under)
gum pager < ./src/under.txt
;;
nintendo)
gum pager < ./src/nintendo.txt
;;
help)
gum pager < ./doc.md
;;
edit | text | txt | file | editor | nano | vim | vi)
$EDITOR "$(gum file "$FBD")"
;;
issue)
gum log --level info "Report issue at github.com/FBD/issues"
;;
time | date)
gum log --level info "$now"
;;
duck | goose)
gum pager < ./src/duck.txt
;;
annoy | dog)
gum pager < ./src/dog.txt
;;
*)
echo -n "Command not found or not implemented yet."
;;
esac
done
https://redd.it/1c8n90e
@r_bash
I have my noscript, that I want to use it with options. Should I create functions indead of those cases ?
#!/bin/env bash
# Customize Console
PROMPT_COMMAND='echo -en "\033]0;$(FBD|cut -d "/" -f 4-100)\a"'
now=$(date)
echo "Undertale Jokes, that's all. Mainly. You know, as ya want."
while true
do
#Input
VHS=$(gum input --placeholder " Enter Command")
# Treat Input
case $VHS in
exit | q | esc | bye)
exit
;;
clear | cls)
clear
;;
puns | under)
gum pager < ./src/under.txt
;;
nintendo)
gum pager < ./src/nintendo.txt
;;
help)
gum pager < ./doc.md
;;
edit | text | txt | file | editor | nano | vim | vi)
$EDITOR "$(gum file "$FBD")"
;;
issue)
gum log --level info "Report issue at github.com/FBD/issues"
;;
time | date)
gum log --level info "$now"
;;
duck | goose)
gum pager < ./src/duck.txt
;;
annoy | dog)
gum pager < ./src/dog.txt
;;
*)
echo -n "Command not found or not implemented yet."
;;
esac
done
https://redd.it/1c8n90e
@r_bash
Having trouble writing bash noscript to management multiple git repos
Hello everyone, I have multiple git repos, let's say /home/plugin/, /home/core/, /home/tempate/.
I'm trying to write a bash noscript that will run git add . && git commit -m $msg && git push origin main on each of them. However my attempt to use cd to get into the appropriate repo isn't working
#!/bin/bash
read -p 'Message: ' msg
declare -a location=(
"core/"
"plugin/"
"template/"
)
dir=$(pwd)
for var in "${location@}"
do
cd "$dir/$var"
git add .
git commit -m "$msg" .
git push origin main --quiet
done
Can anyone point me in the right direction?
https://redd.it/1c8v0ym
@r_bash
Hello everyone, I have multiple git repos, let's say /home/plugin/, /home/core/, /home/tempate/.
I'm trying to write a bash noscript that will run git add . && git commit -m $msg && git push origin main on each of them. However my attempt to use cd to get into the appropriate repo isn't working
#!/bin/bash
read -p 'Message: ' msg
declare -a location=(
"core/"
"plugin/"
"template/"
)
dir=$(pwd)
for var in "${location@}"
do
cd "$dir/$var"
git add .
git commit -m "$msg" .
git push origin main --quiet
done
Can anyone point me in the right direction?
https://redd.it/1c8v0ym
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to create loop?
create a folder structure for each user, in the first folder create as many folders as uid +1, in each folder with a lower level uid -1 etc.
https://redd.it/1c8wsh0
@r_bash
create a folder structure for each user, in the first folder create as many folders as uid +1, in each folder with a lower level uid -1 etc.
https://redd.it/1c8wsh0
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Which command using this file denoscriptor?
I can write to first shell, using new shell.
This command sequence works but i really dont know how and what happened.
What is /dev/fd/0 here? Is it subshell or cat command?
And why PID(BASHPID) worked in the next command. I am so confused. Please help.
https://redd.it/1c92pmw
@r_bash
(echo "$BASHPID" ; cat /dev/fd/0)I can write to first shell, using new shell.
echo "hello" >> /proc/PID(BASHPID)/fd/0 This command sequence works but i really dont know how and what happened.
What is /dev/fd/0 here? Is it subshell or cat command?
And why PID(BASHPID) worked in the next command. I am so confused. Please help.
https://redd.it/1c92pmw
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Why is this stack not empty?
Interestingly, this noscript doesn't give me the output I would expect.
#!/usr/bin/env bash
stack=""
push() {
stack+="$1"
}
pop() {
if [ -z "$stack" ]; then
echo ""
else
local len=${#stack}
local last=${stack:len-1:1}
stack=${stack:0:len-1}
echo "$last"
fi
}
push ""
result=$(pop)
if [[ "$result" != "[" ]; then
echo "false"
else
echo "true"
fi
echo "$stack"
Output:
>true
[
https://redd.it/1c9hcnw
@r_bash
Interestingly, this noscript doesn't give me the output I would expect.
#!/usr/bin/env bash
stack=""
push() {
stack+="$1"
}
pop() {
if [ -z "$stack" ]; then
echo ""
else
local len=${#stack}
local last=${stack:len-1:1}
stack=${stack:0:len-1}
echo "$last"
fi
}
push ""
result=$(pop)
if [[ "$result" != "[" ]; then
echo "false"
else
echo "true"
fi
echo "$stack"
Output:
>true
[
https://redd.it/1c9hcnw
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
can you help me the issue with this noscript?
I have to create a new accounts_new.csv file based on accounts.csv file and modify like that.
was
2,1,Christina Gonzalez,Director,,
8,6,Bart charlow,Executive Director,,
9,7,Bart Charlow,Executive Director,,
# should become:
2,1,Christina ,
8,6,Bart Charlow,Executive ,
9,7,Bart Charlow,Executive ,Gonzalez,Director,cgonzalez@abc.comDirector,bcharlow6@abc.comDirector,bcharlow7@abc.com
here is the code:
#!/bin/bash
# Check if the correct number of arguments is provided
if "$#" -ne 1 ; then
echo "Usage: $0 <pathtoaccounts.csv>"
exit 1
fi
# Check if the input file exists
if ! -f "$1" ; then
echo "File $1 not found!"
exit 1
fi
# Function to process each line of the input file
processline() {
IFS=',' read -r -a fields <<< "$1"
id="${fields[0]}"
name="${fields[2]}"
position="${fields[3]}"
locationid="${fields1}"
# Format name: first letter uppercase, rest lowercase
formattedname=$(echo "$name" | awk '{print toupper(substr($1,1,1)) tolower(substr($1,2)) " " toupper(substr($NF,1,1)) tolower(substr($NF,2))}')
# Format email: lowercase first letter of name, full lowercase surname, followed by @abc.com
formattedemail=$(echo "$name" | awk '{print tolower(substr($1,1,1)) tolower($NF)}')
formattedemail+="@abc.com"
# Append locationid to email if available
if -n "$location_id" ; then
# Check if the email already contains a number
if [ "$formatted_email" =~ [0-9$ ]]; then
formattedemail="${formattedemail%,}@abc.com"
fi
formattedemail="${formattedemail%,}${locationid}@abc.com"
fi
# Output the formatted line
echo "${id},${fields[1]},${formattedname},${position},${formattedemail},"
}
# Process the header row and write it to accountsnew.csv
head -n 0 "$1" > accountsnew.csv
# Add a newline character to the end of the file if it's missing
sed -i -e '$a\' "$1"
# Process each line (excluding the header) of the input file and append to accountsnew.csv
while IFS= read -r line || -n "$line" ; do
if -n "$line" ; then
processline "$line"
fi
done < "$1" >> accountsnew.csv
echo "Processing completed. Check accountsnew.csv for the updated accounts."
# Ensure the output file exists and is readable
if [ -f "accountsnew.csv" ]; then
echo "File accountsnew.csv created successfully."
else
echo "Error: Failed to create accountsnew.csv."
exit 1
fi
the test case says that accounts_new.csv is not found in the directory
https://redd.it/1ca748j
@r_bash
I have to create a new accounts_new.csv file based on accounts.csv file and modify like that.
was
2,1,Christina Gonzalez,Director,,
8,6,Bart charlow,Executive Director,,
9,7,Bart Charlow,Executive Director,,
# should become:
2,1,Christina ,
8,6,Bart Charlow,Executive ,
9,7,Bart Charlow,Executive ,Gonzalez,Director,cgonzalez@abc.comDirector,bcharlow6@abc.comDirector,bcharlow7@abc.com
here is the code:
#!/bin/bash
# Check if the correct number of arguments is provided
if "$#" -ne 1 ; then
echo "Usage: $0 <pathtoaccounts.csv>"
exit 1
fi
# Check if the input file exists
if ! -f "$1" ; then
echo "File $1 not found!"
exit 1
fi
# Function to process each line of the input file
processline() {
IFS=',' read -r -a fields <<< "$1"
id="${fields[0]}"
name="${fields[2]}"
position="${fields[3]}"
locationid="${fields1}"
# Format name: first letter uppercase, rest lowercase
formattedname=$(echo "$name" | awk '{print toupper(substr($1,1,1)) tolower(substr($1,2)) " " toupper(substr($NF,1,1)) tolower(substr($NF,2))}')
# Format email: lowercase first letter of name, full lowercase surname, followed by @abc.com
formattedemail=$(echo "$name" | awk '{print tolower(substr($1,1,1)) tolower($NF)}')
formattedemail+="@abc.com"
# Append locationid to email if available
if -n "$location_id" ; then
# Check if the email already contains a number
if [ "$formatted_email" =~ [0-9$ ]]; then
formattedemail="${formattedemail%,}@abc.com"
fi
formattedemail="${formattedemail%,}${locationid}@abc.com"
fi
# Output the formatted line
echo "${id},${fields[1]},${formattedname},${position},${formattedemail},"
}
# Process the header row and write it to accountsnew.csv
head -n 0 "$1" > accountsnew.csv
# Add a newline character to the end of the file if it's missing
sed -i -e '$a\' "$1"
# Process each line (excluding the header) of the input file and append to accountsnew.csv
while IFS= read -r line || -n "$line" ; do
if -n "$line" ; then
processline "$line"
fi
done < "$1" >> accountsnew.csv
echo "Processing completed. Check accountsnew.csv for the updated accounts."
# Ensure the output file exists and is readable
if [ -f "accountsnew.csv" ]; then
echo "File accountsnew.csv created successfully."
else
echo "Error: Failed to create accountsnew.csv."
exit 1
fi
the test case says that accounts_new.csv is not found in the directory
https://redd.it/1ca748j
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
My first bash noscript - Hide.me VPN Linux CLI Server Switcher
Hi guys n girl,
i wrote my first bash noscript because i had a neat usecase and wanted to try out bash for some time.
In my case i wanted to have a easier and more elegant way to switch my VPN Server. I use hide.me atm and they provide a CLI Client for that purpose, but its not the most userfriendly and comfortable implementation.
I am not a dev so dont throw rocks at me :-P
Github/hide.me-server-switch
https://redd.it/1cabqgd
@r_bash
Hi guys n girl,
i wrote my first bash noscript because i had a neat usecase and wanted to try out bash for some time.
In my case i wanted to have a easier and more elegant way to switch my VPN Server. I use hide.me atm and they provide a CLI Client for that purpose, but its not the most userfriendly and comfortable implementation.
I am not a dev so dont throw rocks at me :-P
Github/hide.me-server-switch
https://redd.it/1cabqgd
@r_bash
hide.me VPN
World's Fastest VPN and Privacy Protection
Hide.me VPN offers privacy protection, wi-fi security, and encryption for a truly private web browser experience, regardless of your location. Try for free!
Can I define something like '~' (tilda)
Is it possible to define '~~' (or some other symbol) to behave like '~' ?
For example define '~~' to be
Motivation: inside a docker container i have
https://redd.it/1cabhz0
@r_bash
Is it possible to define '~~' (or some other symbol) to behave like '~' ?
For example define '~~' to be
/host_fs/home/user and then it will be possible to do things like cd ~~/Downloads etc.Motivation: inside a docker container i have
/host_fs/ I want that '~~' be some path in it and users can type stuff like vim ~~/config.txthttps://redd.it/1cabhz0
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Bashcord - Discord in bash (Not exactly discord)
https://github.com/gitipedras/bashcord
I don't know why I decided to make it.
Any Ideas on how to improve?
Not features that discord has.
Feedback PLS.
https://redd.it/1cbcbq5
@r_bash
https://github.com/gitipedras/bashcord
I don't know why I decided to make it.
Any Ideas on how to improve?
Not features that discord has.
Feedback PLS.
https://redd.it/1cbcbq5
@r_bash
GitHub
GitHub - gitipedras/bashcord: A Crazy project of making discord in bash!!! It works :)
A Crazy project of making discord in bash!!! It works :) - gitipedras/bashcord
How to override a specific autocomplete?
I used to be able to type
But now some additional commands that start with that start with
Is there a way to customize the completion to pretend that "unzip" is the only match (other than deleting the other commands?)
https://redd.it/1cblqcd
@r_bash
I used to be able to type
unz and hit tab, bash would recognize that unzip was the only match, and it would complete it, and add a space after , and I could continue.But now some additional commands that start with that start with
unzip and its really annoying that I have to type it, and then manually add the space. Is there a way to customize the completion to pretend that "unzip" is the only match (other than deleting the other commands?)
https://redd.it/1cblqcd
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Print files whose line of text appear more than once across the files
I have several dozens of text files of a couple of thousands of lines each. I would like to find all the lines that appear more than once across all the files. For example:
# FileA.txt:
cat
dog
bird
horse
# FileB.txt:
elephant
bird
cat
# FileC.txt:
bird
raccoon
lizard
horse
Desired output would be something like:
cat
FileA.txt
FileB.txt
horse
FileA.txt
FileC.txt
bird
FileA.txt
FileB.txt
FileC.txt
Anyone know a performant way to do this? It's straightforward to do it between only 2 files but I have way more than that. Combine all the lines into one file, find duplicate lines in that file, then search for the files for these duplicate lines is the best approach?
https://redd.it/1cbnzf1
@r_bash
I have several dozens of text files of a couple of thousands of lines each. I would like to find all the lines that appear more than once across all the files. For example:
# FileA.txt:
cat
dog
bird
horse
# FileB.txt:
elephant
bird
cat
# FileC.txt:
bird
raccoon
lizard
horse
Desired output would be something like:
cat
FileA.txt
FileB.txt
horse
FileA.txt
FileC.txt
bird
FileA.txt
FileB.txt
FileC.txt
Anyone know a performant way to do this? It's straightforward to do it between only 2 files but I have way more than that. Combine all the lines into one file, find duplicate lines in that file, then search for the files for these duplicate lines is the best approach?
https://redd.it/1cbnzf1
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Changing keywords?
I want to recompile bash with adjustments to the keywords and names of certain built ins.
Ideally, I want them to be single characters. Has anyone done this? Are there any gotchas? My Google fu is failing.
I'm interested in compacting the syntax of one liners for the purpose of playing code golf. So I'm not worried about readability.
https://redd.it/1cbp3it
@r_bash
I want to recompile bash with adjustments to the keywords and names of certain built ins.
Ideally, I want them to be single characters. Has anyone done this? Are there any gotchas? My Google fu is failing.
I'm interested in compacting the syntax of one liners for the purpose of playing code golf. So I'm not worried about readability.
https://redd.it/1cbp3it
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Send a program receiving piped input into a debugger (gdb)?
Hello. I have a small
So far I've tried every combination of piping, redirection and command substitution that I can think of, but it either hangs or the program finishes executing before gdb can open it.
I've also read in gdb's pages that it can open a program based on a pid, so I tried that with a split screen terminal, but apparently this little .c program doesn't create a pid, even when I open it and let it wait for input.
Some (failed/laughable) examples of what I've tried that hopefully show the logic of what I'd like to do:
For what it's worth, I've already stepped through gdb and entered/replaced the strings manually in memory at the appropriate input points, but there's some extra behaviour that I'd like to investigate which only seems to happen when I pipe the text from the command line. So I'm hoping to catch a "snapshot" of the program in that state before it starts executing.
Happy to provide more details if that helps. Left off for brevity's sake.
Basically I'm asking this in r/bash because I'm wondering if this sequence is even possible, or if it's like trying to put on your socks after you've already laced up your shoes.
This is running in GNU bash, v5.1.16.
https://redd.it/1cbqif7
@r_bash
Hello. I have a small
program.c that takes one line of text, evaluates the input, and then exits. To get the program to run successfully (return 0 and exit), I pipe some hex (non-printable ascii) characters to it. This causes the program to run and exit fine. What I'd like to do is step through this program.c once it's been fed the hex values, but before executing, using gdb.So far I've tried every combination of piping, redirection and command substitution that I can think of, but it either hangs or the program finishes executing before gdb can open it.
I've also read in gdb's pages that it can open a program based on a pid, so I tried that with a split screen terminal, but apparently this little .c program doesn't create a pid, even when I open it and let it wait for input.
Some (failed/laughable) examples of what I've tried that hopefully show the logic of what I'd like to do:
gdb "$( (printf "some text"; printf "\xsomehex") | ./program.c )"(printf "some text"; printf "\xsomehex") >>> ./program.c | gdb(printf "some text"; printf "\xsomehex") | gdb ./program.cx="$( (printf "some text"; printf "\xsomehex") )"; gdb program.c < $xFor what it's worth, I've already stepped through gdb and entered/replaced the strings manually in memory at the appropriate input points, but there's some extra behaviour that I'd like to investigate which only seems to happen when I pipe the text from the command line. So I'm hoping to catch a "snapshot" of the program in that state before it starts executing.
Happy to provide more details if that helps. Left off for brevity's sake.
Basically I'm asking this in r/bash because I'm wondering if this sequence is even possible, or if it's like trying to put on your socks after you've already laced up your shoes.
This is running in GNU bash, v5.1.16.
https://redd.it/1cbqif7
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
SoftView Script
Greetings to all,
I have crafted this modest noscript for everyone who spends considerable time working on computers and experiences eye fatigue. I hope you find it to your liking. Please feel free to modify or enhance it as you see fit.
#!/bin/bash
# Check dependencies
type xrandr &>/dev/null || { echo "xrandr is not installed"; exit 1; }
type rofi &>/dev/null || { echo "rofi is not installed"; exit 1; }
type redshift &>/dev/null || { echo "redshift is not installed"; exit 1; }
# Lists monitors and allows the user to choose one if there is more than one
monitors=$(xrandr --query | grep " connected" | cut -d" " -f1)
if [ "$(echo "$monitors" | wc -l)" -gt 1 ]; then
monitor=$(echo "$monitors" | rofi -dmenu -p "Select Monitor:" -config /usr/share/rofi/themes/Arc-Dark.rasi)
else
monitor=$monitors
fi
# Ensures that a monitor has been selected
test -n "$monitor" || { echo "No monitor selected, exiting."; exit 0; }
# Sets the monitor configuration options
list_options() {
echo "Reset : xrandr --output $monitor --set CTM '0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1' ; redshift -x"
echo "GrayScale : xrandr --output $monitor --set CTM '1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0'"
echo "Brightness 0.5 : xrandr --output $monitor --brightness 0.5"
echo "RedShift 1 : redshift -oP -O 4500 -b 0.5"
echo "RedShift 2 : redshift -oP -O 3300 -b 0.7"
echo "RedShift 3 : redshift -oP -O 10000 -g .1:1:.1"
echo "RedShift 4 : redshift -oP -O 1000 -g 1:1.1:1"
}
# Show the list of options with rofi and execute the selection directly
selected_option=$(list_options | rofi -dmenu -p "Select configuration:" -config /usr/share/rofi/themes/Arc-Dark.rasi)
# Checks if an option has been selected
test -n "$selected_option" || { echo "No option selected, exiting."; exit 0; }
# Extracts only the command from the selected result
command=$(echo "$selected_option" | cut -d':' -f2- | xargs)
# Execute the selected command
if [ -n "$command" ]; then
bash -c "$command"
else
echo "Invalid command, exiting."
exit 1
fi
https://redd.it/1cbv3c5
@r_bash
Greetings to all,
I have crafted this modest noscript for everyone who spends considerable time working on computers and experiences eye fatigue. I hope you find it to your liking. Please feel free to modify or enhance it as you see fit.
#!/bin/bash
# Check dependencies
type xrandr &>/dev/null || { echo "xrandr is not installed"; exit 1; }
type rofi &>/dev/null || { echo "rofi is not installed"; exit 1; }
type redshift &>/dev/null || { echo "redshift is not installed"; exit 1; }
# Lists monitors and allows the user to choose one if there is more than one
monitors=$(xrandr --query | grep " connected" | cut -d" " -f1)
if [ "$(echo "$monitors" | wc -l)" -gt 1 ]; then
monitor=$(echo "$monitors" | rofi -dmenu -p "Select Monitor:" -config /usr/share/rofi/themes/Arc-Dark.rasi)
else
monitor=$monitors
fi
# Ensures that a monitor has been selected
test -n "$monitor" || { echo "No monitor selected, exiting."; exit 0; }
# Sets the monitor configuration options
list_options() {
echo "Reset : xrandr --output $monitor --set CTM '0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1' ; redshift -x"
echo "GrayScale : xrandr --output $monitor --set CTM '1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0'"
echo "Brightness 0.5 : xrandr --output $monitor --brightness 0.5"
echo "RedShift 1 : redshift -oP -O 4500 -b 0.5"
echo "RedShift 2 : redshift -oP -O 3300 -b 0.7"
echo "RedShift 3 : redshift -oP -O 10000 -g .1:1:.1"
echo "RedShift 4 : redshift -oP -O 1000 -g 1:1.1:1"
}
# Show the list of options with rofi and execute the selection directly
selected_option=$(list_options | rofi -dmenu -p "Select configuration:" -config /usr/share/rofi/themes/Arc-Dark.rasi)
# Checks if an option has been selected
test -n "$selected_option" || { echo "No option selected, exiting."; exit 0; }
# Extracts only the command from the selected result
command=$(echo "$selected_option" | cut -d':' -f2- | xargs)
# Execute the selected command
if [ -n "$command" ]; then
bash -c "$command"
else
echo "Invalid command, exiting."
exit 1
fi
https://redd.it/1cbv3c5
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to bypass "exec &> logfile" and show echo messages on the screen
I do have a very old and long noscript that is spitting everything to the log file, but gives no output on the screen. This make a problem as noscript is running in the background and user think it hanged or crashed.
I would like to add some "milestone messages" when part of noscript is done and these messages would be shown on the screen for the user, but can't figure out how to make it.
recent example noscript:
#!/bin/bash
set -xeo pipefail
exec &> setup_noscript.log
echo "test message"
recent output on the screen:
`+ exec`
https://redd.it/1cbvxmx
@r_bash
I do have a very old and long noscript that is spitting everything to the log file, but gives no output on the screen. This make a problem as noscript is running in the background and user think it hanged or crashed.
I would like to add some "milestone messages" when part of noscript is done and these messages would be shown on the screen for the user, but can't figure out how to make it.
recent example noscript:
#!/bin/bash
set -xeo pipefail
exec &> setup_noscript.log
echo "test message"
recent output on the screen:
`+ exec`
https://redd.it/1cbvxmx
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Build my first project in bash. Test it out please
​
https://preview.redd.it/gjvu2vyiefwc1.png?width=2204&format=png&auto=webp&s=b85764d55d247c8f8533939a9ba55aa992e5ac57
github: https://github.com/suvanbanerjee/Keyboard-LED-Remapper
https://redd.it/1cbxptu
@r_bash
​
https://preview.redd.it/gjvu2vyiefwc1.png?width=2204&format=png&auto=webp&s=b85764d55d247c8f8533939a9ba55aa992e5ac57
github: https://github.com/suvanbanerjee/Keyboard-LED-Remapper
https://redd.it/1cbxptu
@r_bash
Question about basic telent session noscript.
Hello guys.
I want to gather the output from the cisco device by using 'show ip interface' every 30 seconds.
and I haven't finished yet but I faced unexpected behavior.
This is my noscript.
#!/bin/bash
# device
ip="192.168.192.138"
port="23"
pass="cisco"
duration=$((60 * 60)) # 1 hour
interval=30 # Check every 30 seconds
# Main
echo "Starting to gather 'show ip ali'"
start_time=$(date +%s)
end_time=$((start_time + duration))
while [ $(date +%s) -lt $end_time ]; do
echo "Gathering 'show version'..."
(
sleep 1
echo "$pass"
sleep 5
echo "show ip ali"
sleep 5
echo "exit"
) | telnet $ip $port
echo "Waiting for 30 seconds"
sleep $interval
done
Is there a way to maintain the telnet session without disconnecting and gather 'show ip ali' every 30 seconds?
With my noscript, every time telnet sessions disconnected after executing 'show ip ali' and then re-connect telnet session again.
Thank you!
https://redd.it/1ccypil
@r_bash
Hello guys.
I want to gather the output from the cisco device by using 'show ip interface' every 30 seconds.
and I haven't finished yet but I faced unexpected behavior.
This is my noscript.
#!/bin/bash
# device
ip="192.168.192.138"
port="23"
pass="cisco"
duration=$((60 * 60)) # 1 hour
interval=30 # Check every 30 seconds
# Main
echo "Starting to gather 'show ip ali'"
start_time=$(date +%s)
end_time=$((start_time + duration))
while [ $(date +%s) -lt $end_time ]; do
echo "Gathering 'show version'..."
(
sleep 1
echo "$pass"
sleep 5
echo "show ip ali"
sleep 5
echo "exit"
) | telnet $ip $port
echo "Waiting for 30 seconds"
sleep $interval
done
Is there a way to maintain the telnet session without disconnecting and gather 'show ip ali' every 30 seconds?
With my noscript, every time telnet sessions disconnected after executing 'show ip ali' and then re-connect telnet session again.
Thank you!
https://redd.it/1ccypil
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Doubt
Hi guys i am learning linux command line from the book "The Linux Command Line
Second Internet Edition
William E. Shotts, Jr".
I completed part1 in this book.
Part 1 – Learning The Shell starts our exploration of the basics of the
command line including such things as the structure of commands, file system
navigation, command line editing, and finding help and documentation for com-
mands.
I need to know what is bash programming and bash programming language?.
What's the difference between bash and other programming language.
As mentioned in part 1, the things I learned are actually bash programming or not?
Whether i learning bash programming without knowing it?
https://redd.it/1cdfglj
@r_bash
Hi guys i am learning linux command line from the book "The Linux Command Line
Second Internet Edition
William E. Shotts, Jr".
I completed part1 in this book.
Part 1 – Learning The Shell starts our exploration of the basics of the
command line including such things as the structure of commands, file system
navigation, command line editing, and finding help and documentation for com-
mands.
I need to know what is bash programming and bash programming language?.
What's the difference between bash and other programming language.
As mentioned in part 1, the things I learned are actually bash programming or not?
Whether i learning bash programming without knowing it?
https://redd.it/1cdfglj
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community