PS1
I have recently started to use oh my bash and now I want to change the color of my PS1 (custome prompt) how should I do it.
I do not seem to have anything regarding PS1 in my .bashrc .
Please help
https://redd.it/17sqrm5
@r_bash
I have recently started to use oh my bash and now I want to change the color of my PS1 (custome prompt) how should I do it.
I do not seem to have anything regarding PS1 in my .bashrc .
Please help
https://redd.it/17sqrm5
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Glassfish/payara domain restart project, any improvements you would say?
function domain_action() {
case $1 in
1)
echo "instruction received to start domain $2"
/home/techyman/glassfish4/bin/asadmin start-domain "$2"
;;
2)
echo "instruction received to stop domain $2"
/home/techyman/glassfish4/bin/asadmin stop-domain "$2"
;;
3)
echo "instruction received to restart domain $2"
/home/techyman/glassfish4/bin/asadmin stop-domain "$2" && /home/techyman/glassfish4/bin/asadmin start-domain "$2"
;;
esac
}
echo "What action do you want to perform? (1 for Start, 2 for Stop, 3 for Restart)"
read actionToPerform
echo "On which domains do you want to perform these actions?"
read -a arrayOfDomains
# https://stackoverflow.com/a/56146307/21719190
for domain in "${arrayOfDomains[@]}"; do
domain_action "$actionToPerform" "$domain"
#echo "$domain"
#https://ryanstutorials.net/bash-noscripting-tutorial/bash-if-statements.php
#if [ "$actionToPerform" = "1" ]; then
# echo "Starting $domain"
# domain_action "$actionToPerform" "$domain"
#elif [ "$actionToPerform" = "2" ]; then
# echo "Stopping $domain"
# domain_action "$actionToPerform" "$domain"
#else
# [ "$actionToPerform" = "3" ]
# echo "Restarting $domain"
# domain_action "$actionToPerform" "$domain"
#fi
done
https://redd.it/17tinew
@r_bash
function domain_action() {
case $1 in
1)
echo "instruction received to start domain $2"
/home/techyman/glassfish4/bin/asadmin start-domain "$2"
;;
2)
echo "instruction received to stop domain $2"
/home/techyman/glassfish4/bin/asadmin stop-domain "$2"
;;
3)
echo "instruction received to restart domain $2"
/home/techyman/glassfish4/bin/asadmin stop-domain "$2" && /home/techyman/glassfish4/bin/asadmin start-domain "$2"
;;
esac
}
echo "What action do you want to perform? (1 for Start, 2 for Stop, 3 for Restart)"
read actionToPerform
echo "On which domains do you want to perform these actions?"
read -a arrayOfDomains
# https://stackoverflow.com/a/56146307/21719190
for domain in "${arrayOfDomains[@]}"; do
domain_action "$actionToPerform" "$domain"
#echo "$domain"
#https://ryanstutorials.net/bash-noscripting-tutorial/bash-if-statements.php
#if [ "$actionToPerform" = "1" ]; then
# echo "Starting $domain"
# domain_action "$actionToPerform" "$domain"
#elif [ "$actionToPerform" = "2" ]; then
# echo "Stopping $domain"
# domain_action "$actionToPerform" "$domain"
#else
# [ "$actionToPerform" = "3" ]
# echo "Restarting $domain"
# domain_action "$actionToPerform" "$domain"
#fi
done
https://redd.it/17tinew
@r_bash
Stack Overflow
Shell noscript read multiple inputs from user
How to read any number of inputs from user at once and store it into an array.
For example this will read only a single input at a time
read -p "Please enter username: " username
echo "Dear $
For example this will read only a single input at a time
read -p "Please enter username: " username
echo "Dear $
man tool | cat | grep "string"
Out of curiosity, why doesn't grep work after cat? Isn't the stdout just a "textfile"? Ok, now thinking about this, I actually didn't try to run it with root privileges. But would it matter though?
https://redd.it/17tntom
@r_bash
Out of curiosity, why doesn't grep work after cat? Isn't the stdout just a "textfile"? Ok, now thinking about this, I actually didn't try to run it with root privileges. But would it matter though?
https://redd.it/17tntom
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to remove single new lines from the end of a line in a text file, but ignore double new lines
I have been tearing my hair out trying to process some text files that have too many new lines.
I have a text file that look s something like this:
The quick brown fox jumps Over the
lazy dog. The quick brown fox.
The quick brown fox
jumps over the lazy dog.
I want to remove the single newlines but ignore the doubles.
In a text editor I can find and place using regex like this:
Find: \n(?!\n) Replace with: <space>
But I have a bunch of files, so I’m looking for a way I can create a noscript to do it.
I’ve tried see/gsed, but it is ignoring my regular expressions, even with the -E option. Even a simple search for a newline fails:
sed -i -E 's/\n/ /g' test.txt
Does anyone have a solution?
Many thanks.
https://redd.it/17twwyv
@r_bash
I have been tearing my hair out trying to process some text files that have too many new lines.
I have a text file that look s something like this:
The quick brown fox jumps Over the
lazy dog. The quick brown fox.
The quick brown fox
jumps over the lazy dog.
I want to remove the single newlines but ignore the doubles.
In a text editor I can find and place using regex like this:
Find: \n(?!\n) Replace with: <space>
But I have a bunch of files, so I’m looking for a way I can create a noscript to do it.
I’ve tried see/gsed, but it is ignoring my regular expressions, even with the -E option. Even a simple search for a newline fails:
sed -i -E 's/\n/ /g' test.txt
Does anyone have a solution?
Many thanks.
https://redd.it/17twwyv
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
weird behaviors
curl -s https://english-e-reader.net/level/pre-intermediate | grep "/book/.*>" | sed 's/<a.*="//' | sed 's/">//' |sed 's|\^|https://english-e-reader.net|' | xargs -n 1 curl -s | grep -E "\^words: " >> out
I cannot write anything to the out file, but without redirecting to the file, everything went right.
https://redd.it/17v73mz
@r_bash
curl -s https://english-e-reader.net/level/pre-intermediate | grep "/book/.*>" | sed 's/<a.*="//' | sed 's/">//' |sed 's|\^|https://english-e-reader.net|' | xargs -n 1 curl -s | grep -E "\^words: " >> out
I cannot write anything to the out file, but without redirecting to the file, everything went right.
https://redd.it/17v73mz
@r_bash
English e-reader
graded readers ebooks - best choice to learn English. Download or read online for free!
Is the -f in rm -rf a bit useless?
There's a lot of jokes about
But if it does exist and we run
https://redd.it/17vgh0i
@r_bash
There's a lot of jokes about
rm -rf but if the directory doesn't exist and you run rm -r, it would throw an error, no big deal.But if it does exist and we run
rm -r then it deletes the directory recursively. As a standalone command rm -rfdoesn't seem that much different from rm -r. So maybe I don't understand the joke about rm -rf but rm -r should be good enough? I mean we obviously can't delete something that doesn't exist and -f just suppresses that error message. The importance of -f seems to be overstated?https://redd.it/17vgh0i
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Bash Script YouTube Downloader
https://medium.com/@mwikyo/download-youtube-videos-through-the-terminal-using-a-bash-noscript-205b21161339
https://redd.it/17vfvsa
@r_bash
https://medium.com/@mwikyo/download-youtube-videos-through-the-terminal-using-a-bash-noscript-205b21161339
https://redd.it/17vfvsa
@r_bash
Medium
Download YouTube videos through the terminal using a bash noscript.
If you have always wanted to download youtube videos with your own piece of software, no ads-filled and limiting online tools, even those…
"if grep" is a bomb that we ignore
https://blog.ngs-lang.org/2023/11/07/if-grep-the-bomb/
https://redd.it/17vncx8
@r_bash
https://blog.ngs-lang.org/2023/11/07/if-grep-the-bomb/
https://redd.it/17vncx8
@r_bash
Next Generation Shell
“if grep”, the bomb
Take 2 This is version two of the post, based on the feedback in this Reddit discussion. Some things need clarification. That includes the noscript which should be something like Why NGS has more ergo…
Monitor text file and run command on change?
I'm writing a now-playing Spotify noscript with semi cool formating...
When I ask playerctl for metadata I get a mpris:length (with a number) line, among the others.
I am currently giving that (number) to a Var and checking it every second and then re-running the noscript on change.
I read about a tool that can watch a file and run a command on change of file. I just can't remember what it was. I was thinking I could put the length into a txt file and watch it.
Is it worth using this other tool (that some great haxor will name) to watch the file?
I'm trying to lower system resource use of course.
https://redd.it/17vu88w
@r_bash
I'm writing a now-playing Spotify noscript with semi cool formating...
When I ask playerctl for metadata I get a mpris:length (with a number) line, among the others.
I am currently giving that (number) to a Var and checking it every second and then re-running the noscript on change.
I read about a tool that can watch a file and run a command on change of file. I just can't remember what it was. I was thinking I could put the length into a txt file and watch it.
Is it worth using this other tool (that some great haxor will name) to watch the file?
I'm trying to lower system resource use of course.
https://redd.it/17vu88w
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
jazz : through a marriage of jq and fzf, fuzzy select json input in terminal [homemade gist]
https://gist.github.com/grdscrc/2d0b0549f48950e12d0386bb0fbd8b4f
https://redd.it/17w065j
@r_bash
https://gist.github.com/grdscrc/2d0b0549f48950e12d0386bb0fbd8b4f
https://redd.it/17w065j
@r_bash
Gist
jazz : list paths from a json input, fuzzy search a node, get its content ; useful with large payloads
jazz : list paths from a json input, fuzzy search a node, get its content ; useful with large payloads - jazz.sh
Trying to set a noscript that will move files to different directories based off size
I can’t figure out how to set a shell noscript that when I run it will allow me to move a files above or below a certain size into two different directories and was wondering if anyone knew how.
https://redd.it/17w47wx
@r_bash
I can’t figure out how to set a shell noscript that when I run it will allow me to move a files above or below a certain size into two different directories and was wondering if anyone knew how.
https://redd.it/17w47wx
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Getting Currently playing from Spotify_Player
Trying to use inotifywait to watch the album art file to see when spotify\_player changes tracks then adding now playing data to a txt file for other use.
My issue is that I am getting the LAST song that was played.... what am I doing wrong?
If I cat I get last song played... if I run the playerctl in a terminal it is currently playing.
(sleeping before the echo did not work)
album_art="$HOME/.cache/spotify_player/image"
metadata_file="$HOME/.local/tmp/spotify.txt"
inotifywait -m -e access "$album_art" | while read changed_file; do
echo "$(playerctl -p spotify_player metadata noscript)" > $metadata_file
done
​
https://redd.it/17w8iaz
@r_bash
Trying to use inotifywait to watch the album art file to see when spotify\_player changes tracks then adding now playing data to a txt file for other use.
My issue is that I am getting the LAST song that was played.... what am I doing wrong?
If I cat I get last song played... if I run the playerctl in a terminal it is currently playing.
(sleeping before the echo did not work)
album_art="$HOME/.cache/spotify_player/image"
metadata_file="$HOME/.local/tmp/spotify.txt"
inotifywait -m -e access "$album_art" | while read changed_file; do
echo "$(playerctl -p spotify_player metadata noscript)" > $metadata_file
done
​
https://redd.it/17w8iaz
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Just in case this is useful to anyone else
I recently finished a function to validate the file extension of say, a list file or what have you, if you want to limit the filetype that can be passed to your noscript, and thought I'd share what I came up with:
#==========================================================================
# Check the validity of a file's file extension
# Invoked with: check_ext "<filepath>" <extension length> "<valid file format>"
# Globals: none
# Arguments: file path, length of file extension, accepted file extension
# Outputs: nothing
# Returns: 0 if extension is valid, 1 otherwise
#
# Notes: extension length should be the character length of the extension
# itself (e.g.: 2 for sh) plus the dot preceding the extension (e.g.:
# 3 for '.sh')
check_ext() {
local filePath="$1"
local extensionLength="$2"
local validFormat="$3"
fileName="${filePath##*/}"
fileExtension="${fileName: -${extensionLength}}"
if [[ "$fileExtension" == "$validFormat" ]]; then
return 0
else
return 1
fi
} # End of function 'check_ext'
I'm sure there's probably a better way to go about this, but this is the best I can come up with at this stage.
https://redd.it/17weust
@r_bash
I recently finished a function to validate the file extension of say, a list file or what have you, if you want to limit the filetype that can be passed to your noscript, and thought I'd share what I came up with:
#==========================================================================
# Check the validity of a file's file extension
# Invoked with: check_ext "<filepath>" <extension length> "<valid file format>"
# Globals: none
# Arguments: file path, length of file extension, accepted file extension
# Outputs: nothing
# Returns: 0 if extension is valid, 1 otherwise
#
# Notes: extension length should be the character length of the extension
# itself (e.g.: 2 for sh) plus the dot preceding the extension (e.g.:
# 3 for '.sh')
check_ext() {
local filePath="$1"
local extensionLength="$2"
local validFormat="$3"
fileName="${filePath##*/}"
fileExtension="${fileName: -${extensionLength}}"
if [[ "$fileExtension" == "$validFormat" ]]; then
return 0
else
return 1
fi
} # End of function 'check_ext'
I'm sure there's probably a better way to go about this, but this is the best I can come up with at this stage.
https://redd.it/17weust
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Making a matrix
Hey, everyone! I'm still fairly new to bash and don't exactly know how to solve this exercise we received for studying. If anyone could help me, I would really appreciate that. Here's the text:
You are tasked to create a simple program that emulates a cinema ticket reservation system for a cinema with a single screen and 100 seats organised in a 10x10 grid.
The seating arrangement should be presented to the user as a 10x10 grid. Each seat is identified by its position in the grid (e.g. the first seat is at position 0,0 and the last seat is position 9,9). For visual representation, the program should use 'A' for available seats and '_' for reserved seats.
The program should begin by displaying a greeting message to the user and the current seating map, where all seats are initially available. It should then prompt the user to enter a seat number to reserve. After the user provides a valid seat number, the program should reserve that seat and display the updated seating map. If the seat is already reserved, the program should inform the user and prompt them to choose another seat.
After reserving a seat and showing the updated seating map, the program should ask the user whether they want to reserve another seat. If the user decides to continue, the program should repeat the reservation process. Otherwise, it should end with a closing message.
Thanks in advance to anyone who's willing to help me with this exercise.
https://redd.it/17wj6s0
@r_bash
Hey, everyone! I'm still fairly new to bash and don't exactly know how to solve this exercise we received for studying. If anyone could help me, I would really appreciate that. Here's the text:
You are tasked to create a simple program that emulates a cinema ticket reservation system for a cinema with a single screen and 100 seats organised in a 10x10 grid.
The seating arrangement should be presented to the user as a 10x10 grid. Each seat is identified by its position in the grid (e.g. the first seat is at position 0,0 and the last seat is position 9,9). For visual representation, the program should use 'A' for available seats and '_' for reserved seats.
The program should begin by displaying a greeting message to the user and the current seating map, where all seats are initially available. It should then prompt the user to enter a seat number to reserve. After the user provides a valid seat number, the program should reserve that seat and display the updated seating map. If the seat is already reserved, the program should inform the user and prompt them to choose another seat.
After reserving a seat and showing the updated seating map, the program should ask the user whether they want to reserve another seat. If the user decides to continue, the program should repeat the reservation process. Otherwise, it should end with a closing message.
Thanks in advance to anyone who's willing to help me with this exercise.
https://redd.it/17wj6s0
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Using an INT trap to dynamically debug a running noscript
I came up with a way to using `trap ... INT` to help dynamically debug a noscript/function as it is running. I find it quite useful, and figured others on /r/bash might as well.
Set the following trap at the start of the functions/noscripts you want this functionality enabled on:
trap 'printf '"'"'%s\n'"'"' "" "press [a] to Abort (exit)" "press [u] to Unset INT trap (makes <ctrl> + <c> work normally again)" "press [x] to eXecute a command" "press [p] to print the Present working directory" "press [i] to print Information about what caller/function/line/command is currently running" "press [d] / [D] to [start] (set -xv) / to [stop] (set +xv) printing Debug output to stderr" "press [v] / [V] to write Vars (declare -p) to [stderr] / to [file (${PWD}/.vars)]" "press [e] / [E] to write Environment (env) to [stderr] / to [file (${PWD}/.env)]" "press anything else to continue" >&2;
read -r -n 1;
case "$REPLY" in
a) exit ;;
u) trap - INT ;;
x) if [[ $USER == root ]] && [[ ${SUDO_USER} ]] && ! [[ ${SUDO_USER} == root ]] && type -a su &>/dev/null; then su -p "${SUDO_USER}" < <(read -r && echo "$REPLY"); elif ! [[ $USER == root ]]; then source <(read -r && echo "$REPLY"); else echo "for security running generic commands as root is not allowed" >&2; fi ;;
p) echo "$PWD" ;;
i) echo; [[ $FUNCNAME ]] && printf '"'"'function: %s\n'"'"' "$FUNCNAME" >&2; printf '"'"'caller : %s\n'"'"' "$0" >&2; [[ $BASH_LINENO ]] && printf '"'"'line : %s\n'"'"' "${BASH_LINENO}" >&2; printf '"'"'command : %s\n'"'"' "${BASH_COMMAND}" >&2 ;;
d) set -xv ;;
D) set +xv ;;
v) declare -p >&2 ;;
V) declare -p >"${PWD}"/.vars ;;
e) env >&2 ;;
E) env >"${PWD}"/.env ;;
esac' INT
This will make it so that when you press `<ctrl>` + `<c>` the following menu appears:
press [a] to Abort (exit)
press [u] to Unset INT trap (makes <ctrl> + <c> work normally again)
press [x] to eXecute a command
press [p] to print the Present working directory
press [i] to print Information about what caller/function/line/command is currently running
press [d] / [D] to [start] (set -xv) / to [stop] (set +xv) printing Debug output to stderr
press [v] / [V] to write Vars (declare -p) to [stderr] / to [file ($PWD}/.vars)]
press [e] / [E] to write Environment (env) to [stderr] / to [file ($PWD}/.env)]
press anything else to continue
The shell will then read 1 character and if it is one of the ones listed above it will run the corresponding action in the `case` statement from the `trap ... INT` definition. I chose these actions feeling that they might be of use when debugging a noscript, though of course you can modify/add/remove possible actions by redefining the trap.
***
One note regarding the "press [x] to eXecute a command" action:
As it is implemented above, it will not execute commands as root. If allowed to run commands as root, it would allow someone to hit `<ctrl>` + `<c>` on a noscript run with `sudo` and then execute generic commands (outside the scope of what the noscript was intended to do) as root. Which is dangerous.
If run as root and you press `x` at the INT trap menu it will try and run your command as the (non-root) `$SUDO_USER` (the user you ran `sudo` from) using `su`. Unfortunately, this runs the command in a subshell, meaning you cannot use it to modify any parameters of the running noscript, which limits its usefulness.
If anyone knows how to run a command in the current (root) shell as a non-root user let me know and ill incorporate it. If you are OK with the security risks of running generic commands as root from the trap menu you can replace the `case` statement's definition for `x` with
x) source <(read -r && echo "$REPLY") ;;
https://redd.it/17wqep9
@r_bash
I came up with a way to using `trap ... INT` to help dynamically debug a noscript/function as it is running. I find it quite useful, and figured others on /r/bash might as well.
Set the following trap at the start of the functions/noscripts you want this functionality enabled on:
trap 'printf '"'"'%s\n'"'"' "" "press [a] to Abort (exit)" "press [u] to Unset INT trap (makes <ctrl> + <c> work normally again)" "press [x] to eXecute a command" "press [p] to print the Present working directory" "press [i] to print Information about what caller/function/line/command is currently running" "press [d] / [D] to [start] (set -xv) / to [stop] (set +xv) printing Debug output to stderr" "press [v] / [V] to write Vars (declare -p) to [stderr] / to [file (${PWD}/.vars)]" "press [e] / [E] to write Environment (env) to [stderr] / to [file (${PWD}/.env)]" "press anything else to continue" >&2;
read -r -n 1;
case "$REPLY" in
a) exit ;;
u) trap - INT ;;
x) if [[ $USER == root ]] && [[ ${SUDO_USER} ]] && ! [[ ${SUDO_USER} == root ]] && type -a su &>/dev/null; then su -p "${SUDO_USER}" < <(read -r && echo "$REPLY"); elif ! [[ $USER == root ]]; then source <(read -r && echo "$REPLY"); else echo "for security running generic commands as root is not allowed" >&2; fi ;;
p) echo "$PWD" ;;
i) echo; [[ $FUNCNAME ]] && printf '"'"'function: %s\n'"'"' "$FUNCNAME" >&2; printf '"'"'caller : %s\n'"'"' "$0" >&2; [[ $BASH_LINENO ]] && printf '"'"'line : %s\n'"'"' "${BASH_LINENO}" >&2; printf '"'"'command : %s\n'"'"' "${BASH_COMMAND}" >&2 ;;
d) set -xv ;;
D) set +xv ;;
v) declare -p >&2 ;;
V) declare -p >"${PWD}"/.vars ;;
e) env >&2 ;;
E) env >"${PWD}"/.env ;;
esac' INT
This will make it so that when you press `<ctrl>` + `<c>` the following menu appears:
press [a] to Abort (exit)
press [u] to Unset INT trap (makes <ctrl> + <c> work normally again)
press [x] to eXecute a command
press [p] to print the Present working directory
press [i] to print Information about what caller/function/line/command is currently running
press [d] / [D] to [start] (set -xv) / to [stop] (set +xv) printing Debug output to stderr
press [v] / [V] to write Vars (declare -p) to [stderr] / to [file ($PWD}/.vars)]
press [e] / [E] to write Environment (env) to [stderr] / to [file ($PWD}/.env)]
press anything else to continue
The shell will then read 1 character and if it is one of the ones listed above it will run the corresponding action in the `case` statement from the `trap ... INT` definition. I chose these actions feeling that they might be of use when debugging a noscript, though of course you can modify/add/remove possible actions by redefining the trap.
***
One note regarding the "press [x] to eXecute a command" action:
As it is implemented above, it will not execute commands as root. If allowed to run commands as root, it would allow someone to hit `<ctrl>` + `<c>` on a noscript run with `sudo` and then execute generic commands (outside the scope of what the noscript was intended to do) as root. Which is dangerous.
If run as root and you press `x` at the INT trap menu it will try and run your command as the (non-root) `$SUDO_USER` (the user you ran `sudo` from) using `su`. Unfortunately, this runs the command in a subshell, meaning you cannot use it to modify any parameters of the running noscript, which limits its usefulness.
If anyone knows how to run a command in the current (root) shell as a non-root user let me know and ill incorporate it. If you are OK with the security risks of running generic commands as root from the trap menu you can replace the `case` statement's definition for `x` with
x) source <(read -r && echo "$REPLY") ;;
https://redd.it/17wqep9
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
any tips why its not working?
if [[ $current_url != "${NGROK_REMOTE_URL}" \]\];
then
curl -s -X POST "https://api.telegram.org/botapi/sendMessage" -d "chat_id=secret" -d text=${NGROK_REMOTE_URL}
current_url=${NGROK_REMOTE_URL}
fi
https://redd.it/17wtqme
@r_bash
if [[ $current_url != "${NGROK_REMOTE_URL}" \]\];
then
curl -s -X POST "https://api.telegram.org/botapi/sendMessage" -d "chat_id=secret" -d text=${NGROK_REMOTE_URL}
current_url=${NGROK_REMOTE_URL}
fi
https://redd.it/17wtqme
@r_bash
Does anyone have a clue how to do this
Script 4: The server that hosts the images that you process with your previous shell noscript has been having connectivity problems. You want to write a shell noscript named checkserver.sh that you can schedule to run at night to ping the server and capture the results in a file. ping is a command to send packets to another computer to verify you can connect to it. Your noscript should take the IP address of the server as a parameter. For testing purposes, you may use 173.255.195.185. Your noscript should ping the server 10 times, save the output in a file and quit. The output file should include the date and time the ping was executed.
https://redd.it/17wxyau
@r_bash
Script 4: The server that hosts the images that you process with your previous shell noscript has been having connectivity problems. You want to write a shell noscript named checkserver.sh that you can schedule to run at night to ping the server and capture the results in a file. ping is a command to send packets to another computer to verify you can connect to it. Your noscript should take the IP address of the server as a parameter. For testing purposes, you may use 173.255.195.185. Your noscript should ping the server 10 times, save the output in a file and quit. The output file should include the date and time the ping was executed.
https://redd.it/17wxyau
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
New to bash and can't figure out array items
I have been beating my head against a wall about this for longer than I care to admit and am looking for a clue.
I am pulling all my budget names from AWS and storing them into a variable:
`budgets=$(aws budgets describe-budgets --account-id "$ACCOUNT_ID" | jq '.Budgets[].BudgetName')`
One big string that looks like this:
`"Market Accounts" "Scratch account" "DataScience Accounts" "Infrastructure Accounts" "Networking Accounts"` etc..
so I convert it to an array so I can use the items individually:
`budgets=($budgets)`
but when I run it through a for loop:
`for budget in "${budgets[@]}"; do echo $budget; done`
It doesn't treat the quoted groups as items and treats every space as a delimiter.
So I get this output for `echo "${budgets[0]}"`
`"Market`
but my desired output is:
`"Market Accounts"`
Full snippet:
budgets=$(aws budgets describe-budgets --account-id "$ACCOUNT_ID" | jq '.Budgets[].BudgetName')
budgets=($budgets)
for budget in "${budgets[@]}"; do echo $budget; done
It has to be simpler that all the things I have tried. Any help is greatly appreciated.
https://redd.it/17x4fsh
@r_bash
I have been beating my head against a wall about this for longer than I care to admit and am looking for a clue.
I am pulling all my budget names from AWS and storing them into a variable:
`budgets=$(aws budgets describe-budgets --account-id "$ACCOUNT_ID" | jq '.Budgets[].BudgetName')`
One big string that looks like this:
`"Market Accounts" "Scratch account" "DataScience Accounts" "Infrastructure Accounts" "Networking Accounts"` etc..
so I convert it to an array so I can use the items individually:
`budgets=($budgets)`
but when I run it through a for loop:
`for budget in "${budgets[@]}"; do echo $budget; done`
It doesn't treat the quoted groups as items and treats every space as a delimiter.
So I get this output for `echo "${budgets[0]}"`
`"Market`
but my desired output is:
`"Market Accounts"`
Full snippet:
budgets=$(aws budgets describe-budgets --account-id "$ACCOUNT_ID" | jq '.Budgets[].BudgetName')
budgets=($budgets)
for budget in "${budgets[@]}"; do echo $budget; done
It has to be simpler that all the things I have tried. Any help is greatly appreciated.
https://redd.it/17x4fsh
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Many of my functions are not recognised by GitHub as functions
I'm wondering if there's something wrong with the way I format my functions in bash. They work just fine in bash. But GitHub doesn't recognise many of them as functions.
GitHub's Symbols panel only lists 7 of the noscript's 21 functions. https://i.imgur.com/njBUl8J.png
Notepad++ shows all 21 functions in it's Function List. https://i.imgur.com/OxUxXWw.png
I had a similar issue with Notepad++ when the first line in the function was a comment. I fixed that by adding a space after the
The bash noscript is here: https://github.com/007revad/Synology\_HDD\_db/blob/develop/syno\_hdd\_db.sh
Is there anything I can change in my bash noscript that will make GitHub recognise all of my functions as functions?
​
https://redd.it/17x7fp8
@r_bash
I'm wondering if there's something wrong with the way I format my functions in bash. They work just fine in bash. But GitHub doesn't recognise many of them as functions.
GitHub's Symbols panel only lists 7 of the noscript's 21 functions. https://i.imgur.com/njBUl8J.png
Notepad++ shows all 21 functions in it's Function List. https://i.imgur.com/OxUxXWw.png
I had a similar issue with Notepad++ when the first line in the function was a comment. I fixed that by adding a space after the
{The bash noscript is here: https://github.com/007revad/Synology\_HDD\_db/blob/develop/syno\_hdd\_db.sh
Is there anything I can change in my bash noscript that will make GitHub recognise all of my functions as functions?
​
https://redd.it/17x7fp8
@r_bash
Wayland noscript that is equivalent to x11
Hi, I wrote a noscript for browser functionality. Is it possible to rewrite it to wayland? Thanks in advance!
Basically, what this noscript does:
If browser isn't open, it opens it
If browser is open, but not active, it activates it
If more than one browser window is open, it cycles between them
​
\#!/bin/bash
\#Needs wmctrl ,libnotify-bin, noscript x11 only
​
defaultBrowser=$(xdg-settings get default-web-browser -eq)
if [ "$defaultBrowser" = "brave-browser.desktop" \]; then
findName="Brave"
launchName="brave-browser"
fi
​
if [ "$defaultBrowser" = "firefox_firefox.desktop" \]; then
findName="Firefox"
launchName="firefox"
fi
OUTPUT=$(wmctrl -l | awk '{print $1, $NF}' | grep $findName | awk '{print $1}')
​
a=($(echo "$OUTPUT" | tr ' ' '\\n'))
aSize=${#a[@\]}
​
\# Check if array size is 0
if [ "$aSize" -eq 0 \]; then
$launchName &
notify-send -t 800 "Launching: $findName"
exit
elif [ "$aSize" -eq 1 \]; then
wmctrl -ia "${a[0\]}"
exit
elif [[ -z $(wmctrl -lp | grep "$(xprop -root | grep _NET_ACTIVE_WINDOW | head -1 | awk '{print $5}' | sed 's/,//' | sed 's/\^0x/0x0/')" | grep $findName) \]\]; then
wmctrl -ia "${a[0\]}"
exit
else
activeWindowID=$(wmctrl -lp | grep "$(xprop -root | grep _NET_ACTIVE_WINDOW | head -1 | \\
awk '{print $5}' | sed 's/,//' | sed 's/\^0x/0x0/')" | awk '{print $1}')
​
for i in "${!a[@\]}"; do
if [ "${a[i\]}" == "$activeWindowID" \]; then
index="$i"
if [ "$index" -eq "$((aSize - 1))" \]; then
index="0"
else
((index++))
fi
wmctrl -ia "${a[$index\]}"
exit
fi
done
fi
https://redd.it/17xebi9
@r_bash
Hi, I wrote a noscript for browser functionality. Is it possible to rewrite it to wayland? Thanks in advance!
Basically, what this noscript does:
If browser isn't open, it opens it
If browser is open, but not active, it activates it
If more than one browser window is open, it cycles between them
​
\#!/bin/bash
\#Needs wmctrl ,libnotify-bin, noscript x11 only
​
defaultBrowser=$(xdg-settings get default-web-browser -eq)
if [ "$defaultBrowser" = "brave-browser.desktop" \]; then
findName="Brave"
launchName="brave-browser"
fi
​
if [ "$defaultBrowser" = "firefox_firefox.desktop" \]; then
findName="Firefox"
launchName="firefox"
fi
OUTPUT=$(wmctrl -l | awk '{print $1, $NF}' | grep $findName | awk '{print $1}')
​
a=($(echo "$OUTPUT" | tr ' ' '\\n'))
aSize=${#a[@\]}
​
\# Check if array size is 0
if [ "$aSize" -eq 0 \]; then
$launchName &
notify-send -t 800 "Launching: $findName"
exit
elif [ "$aSize" -eq 1 \]; then
wmctrl -ia "${a[0\]}"
exit
elif [[ -z $(wmctrl -lp | grep "$(xprop -root | grep _NET_ACTIVE_WINDOW | head -1 | awk '{print $5}' | sed 's/,//' | sed 's/\^0x/0x0/')" | grep $findName) \]\]; then
wmctrl -ia "${a[0\]}"
exit
else
activeWindowID=$(wmctrl -lp | grep "$(xprop -root | grep _NET_ACTIVE_WINDOW | head -1 | \\
awk '{print $5}' | sed 's/,//' | sed 's/\^0x/0x0/')" | awk '{print $1}')
​
for i in "${!a[@\]}"; do
if [ "${a[i\]}" == "$activeWindowID" \]; then
index="$i"
if [ "$index" -eq "$((aSize - 1))" \]; then
index="0"
else
((index++))
fi
wmctrl -ia "${a[$index\]}"
exit
fi
done
fi
https://redd.it/17xebi9
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
HELP! Bash noscript wilding. Even GPT is stumped.
Hi there,
I've been modifying this noscript so that it uses grim and slurp to work on wayland. Now I've hit the road block. The output of the program (After modification) is:
Selected geometry: 1118,285 528x656
Screenshot command: grim -g "1118,285 528x656" /home/baighack3rss/Pictures/Screenshots\/1700230454.png
invalid geometry
Command exit status: 1
Now here is the interesting part. If I just copy the screenshot command and run it in the terminal it works but in the noscript it's an invalid geometry.
I've attached the noscript to this hastebin.
Thanks in advance!!
https://redd.it/17xg4m2
@r_bash
Hi there,
I've been modifying this noscript so that it uses grim and slurp to work on wayland. Now I've hit the road block. The output of the program (After modification) is:
Selected geometry: 1118,285 528x656
Screenshot command: grim -g "1118,285 528x656" /home/baighack3rss/Pictures/Screenshots\/1700230454.png
invalid geometry
Command exit status: 1
Now here is the interesting part. If I just copy the screenshot command and run it in the terminal it works but in the noscript it's an invalid geometry.
I've attached the noscript to this hastebin.
Thanks in advance!!
https://redd.it/17xg4m2
@r_bash
GitHub
yoru/config/awesome/utilities/screensht at main · rxyhn/yoru
夜 - Yoru | Aesthetic and Beautiful Awesome Environment :first_quarter_moon: - rxyhn/yoru