How to start a process in the background from a bash noscript but then kill that process when I Ctrl+C see the noscript?
I have this noscript:
#!/bin/bash
sudo nginx -t
if ! ss -l | grep 10002 > /dev/null
then
sudo nginx
else
sudo nginx -s reload
fi
python loop.py > /dev/null &
python app.py
This noscript is supposed to test the nginx config file, then check if nginx is running, if its not running, start it, if it is running reload it, then run a python noscript which is an infinite loop, then load a flask app.
If i don't add the '&' on the loop the flask app will never load because the loop will never end. However, when I press Ctrl+C on this noscript I want both loop.py and app.py to end process.
But right now only app.py ends and loop.py keeps running (I assume because it spawned a child process). How can I make it so loop.py ends when I Ctrl+C?
https://redd.it/zm42ox
@r_bash
I have this noscript:
#!/bin/bash
sudo nginx -t
if ! ss -l | grep 10002 > /dev/null
then
sudo nginx
else
sudo nginx -s reload
fi
python loop.py > /dev/null &
python app.py
This noscript is supposed to test the nginx config file, then check if nginx is running, if its not running, start it, if it is running reload it, then run a python noscript which is an infinite loop, then load a flask app.
If i don't add the '&' on the loop the flask app will never load because the loop will never end. However, when I press Ctrl+C on this noscript I want both loop.py and app.py to end process.
But right now only app.py ends and loop.py keeps running (I assume because it spawned a child process). How can I make it so loop.py ends when I Ctrl+C?
https://redd.it/zm42ox
@r_bash
found a noscript in a file i was sent and I'm wondering what exactly it does.
edited to fix format.
#!/bin/bash
filename=$1
sed -n '1~4s/^@/>/p;2~4p' $filename | awk '{print $1}' > $filename.fasta
https://redd.it/zm6c6b
@r_bash
edited to fix format.
#!/bin/bash
filename=$1
sed -n '1~4s/^@/>/p;2~4p' $filename | awk '{print $1}' > $filename.fasta
https://redd.it/zm6c6b
@r_bash
reddit
found a noscript in a file i was sent and I'm wondering what exactly...
edited to fix format. #!/bin/bash filename=$1 sed -n '1~4s/^@/>/p;2~4p' $filename | awk '{print $1}' > $filename.fasta
"type -P" vs "type -p"
As per
-P force a PATH search for each NAME, even if it is an alias,
builtin, or function, and returns the name of the disk file
that would be executed
-p returns either the name of the disk file that would be executed,
or nothing if
Could someone please provide an example when there is a difference in
https://redd.it/zm7dke
@r_bash
As per
help type output-P force a PATH search for each NAME, even if it is an alias,
builtin, or function, and returns the name of the disk file
that would be executed
-p returns either the name of the disk file that would be executed,
or nothing if
type -t NAME' would not return file'Could someone please provide an example when there is a difference in
-P vs -p output?https://redd.it/zm7dke
@r_bash
reddit
"type -P" vs "type -p"
As per `help type` output -P force a PATH search for each NAME, even if it is an alias, builtin, or function, and returns the...
How can I append an output at the end of a line on a file?
I want to append the output of the following code at the end of every line in a file
echo "$(printf "%0d" "$x" 0)$exampleString" | perl -lape '$_=pack"(B8)",@F'
I think
https://redd.it/zmh5hs
@r_bash
I want to append the output of the following code at the end of every line in a file
echo "$(printf "%0d" "$x" 0)$exampleString" | perl -lape '$_=pack"(B8)",@F'
I think
sed is the right way to go, but I just don't know how to fit all that piece of codehttps://redd.it/zmh5hs
@r_bash
reddit
How can I append an output at the end of a line on a file?
I want to append the output of the following code at the end of every line in a file echo "$(printf "%0*d" "$x" 0)$exampleString" | perl...
grep output for a file not found - How can I redirect that message to a new variable?
I have the following as an example,
​
echo -e "-------------------\nJournalctl Log Results:\n-------------------"
GREPJOURNALCTL=$( journalctl | grep $input | tail -10 )
if [ -z "$GREPJOURNALCTL" ]
then
echo -e "\n${G}No Results Found${NC}\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo $GREPJOURNALCTL
echo ""
fi
sleep 1s
Then I would get "grep: /var/log/dmesg: No such file or directory"
Can I redirect that to a variable or is that already is redirected to a variable with GREP\JOURNALCTL? If impossible, can I redirect the stderr message to null? I've tried adding 2>&1 /dev/null but it didn't work for me :S
https://redd.it/zmjh4y
@r_bash
I have the following as an example,
​
echo -e "-------------------\nJournalctl Log Results:\n-------------------"
GREPJOURNALCTL=$( journalctl | grep $input | tail -10 )
if [ -z "$GREPJOURNALCTL" ]
then
echo -e "\n${G}No Results Found${NC}\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo $GREPJOURNALCTL
echo ""
fi
sleep 1s
Then I would get "grep: /var/log/dmesg: No such file or directory"
Can I redirect that to a variable or is that already is redirected to a variable with GREP\JOURNALCTL? If impossible, can I redirect the stderr message to null? I've tried adding 2>&1 /dev/null but it didn't work for me :S
https://redd.it/zmjh4y
@r_bash
reddit
grep output for a file not found - How can I redirect that message...
I have the following as an example, echo -e "-------------------\nJournalctl Log Results:\n-------------------" ...
Creating a bash noscript that uses a python package
I am running a python [package](https://hippmapp3r.readthedocs.io/en/latest/hipp_seg.html) in my linux terminal. I would like to create a loop noscript that says to use the python package to perform a function. Currently, my workflow is like this:
source activate hippmapper
hippmapper seg_hipp -t1 participantnumber.nii.gz -o participantnumber_transformed.nii.gz
conda deactivate
This is fine if I was doing one participant, but I have 671, and potentially MANY more.
I have a working shell noscript for another process, so I am using that as a template to adapt. However, altering it to what I need doesn't work, and I am unsure why. **I am activating my python environment (that I have called hippmapper) before running the shell noscript. Should it be inside the noscript?**
#!/bin/sh
parent_folder="path/here"
for i in folder1 folder2 folder3; do hippmapper seg_hipp -t1 ${parent_folder}/${i}/${i}_1_T1W.nii.gz -o ${parent_folder}/${i}/${i}_transformed.nii.gz; done
This code above does not work.
https://redd.it/zmkt04
@r_bash
I am running a python [package](https://hippmapp3r.readthedocs.io/en/latest/hipp_seg.html) in my linux terminal. I would like to create a loop noscript that says to use the python package to perform a function. Currently, my workflow is like this:
source activate hippmapper
hippmapper seg_hipp -t1 participantnumber.nii.gz -o participantnumber_transformed.nii.gz
conda deactivate
This is fine if I was doing one participant, but I have 671, and potentially MANY more.
I have a working shell noscript for another process, so I am using that as a template to adapt. However, altering it to what I need doesn't work, and I am unsure why. **I am activating my python environment (that I have called hippmapper) before running the shell noscript. Should it be inside the noscript?**
#!/bin/sh
parent_folder="path/here"
for i in folder1 folder2 folder3; do hippmapper seg_hipp -t1 ${parent_folder}/${i}/${i}_1_T1W.nii.gz -o ${parent_folder}/${i}/${i}_transformed.nii.gz; done
This code above does not work.
https://redd.it/zmkt04
@r_bash
Grep lines from a file, that have special chars in them.
I’m trying to check existing crontab entries against a file, to ensure everything in the file is loaded in to cron.
So my function is basically:
func(){
while IFS= read -r line
do
if ! crontab -l | grep -fq “${line}”. > /dev/null 2>&1
then
return 1
fi
done < crons.file
return 0
}
The issue is that, grep reads $line as a regex pattern. I can’t put single quotes around $line to make it not read it as a regex, because then $line won’t expand.
How do I navigate this? Thanks in advance!!!
https://redd.it/zmrdgn
@r_bash
I’m trying to check existing crontab entries against a file, to ensure everything in the file is loaded in to cron.
So my function is basically:
func(){
while IFS= read -r line
do
if ! crontab -l | grep -fq “${line}”. > /dev/null 2>&1
then
return 1
fi
done < crons.file
return 0
}
The issue is that, grep reads $line as a regex pattern. I can’t put single quotes around $line to make it not read it as a regex, because then $line won’t expand.
How do I navigate this? Thanks in advance!!!
https://redd.it/zmrdgn
@r_bash
reddit
Grep lines from a file, that have special chars in them.
I’m trying to check existing crontab entries against a file, to ensure everything in the file is loaded in to cron. So my function is basically: ...
Needed some dummy files and directories with unique md5sums, random file sizes. This is the final result.
This will create 3 functions:
1. randint() that takes a min and max values
2. genextension() which uses randint to pick a number from 1 to 10 and print that corresponing extension
3. genfiles() will use all defined functions and use the dd util and gather input from urandom to make the files.
​
​
A total of 1 to 15 dummy files and a total of 5 to 10 dummy directories will be created on the current working directory. I know its not pretty, but still bash? 😁
https://redd.it/zmtk8e
@r_bash
This will create 3 functions:
1. randint() that takes a min and max values
2. genextension() which uses randint to pick a number from 1 to 10 and print that corresponing extension
3. genfiles() will use all defined functions and use the dd util and gather input from urandom to make the files.
​
randint() { expr $(expr ${RANDOM} % $(expr $(expr ${2} - ${1}) + ${1})) + ${1} ; }; genextension() { randext=$(randint 1 10); echo ".txt .jpg .png .exe .json .wav .mp3 .doc .docx" | awk -F " " -v i=${randext} '{ print$i }'; };genfiles() { totalfiles=$(randint ${1} ${2});totaldirs=$(randint 5 10); for (( i=0;i<totalfiles;i++ ));do filename="${3}/file_${i}$(genextension)"; dd if=/dev/urandom of=${filename} bs=100b count=$(randint 1 10) &> /dev/null; du -h ${filename};done; for (( i=0;i<totaldirs;i++ ));do mkdir -p dir_${i};done; }; genfiles 1 15 .; for d in $(ls); do if [ -d ${d} ]; then genfiles 1 15 ${d};fi;done;​
A total of 1 to 15 dummy files and a total of 5 to 10 dummy directories will be created on the current working directory. I know its not pretty, but still bash? 😁
https://redd.it/zmtk8e
@r_bash
reddit
Needed some dummy files and directories with unique md5sums,...
This will create 3 functions: 1. randint() that takes a min and max values 2. genextension() which uses randint to pick a number from 1 to 10 and...
The simplest of bash noscripts only runs in terminal so many lines before closing prematurely, Despite there being more perfectly fine code to run.
OK, so my noscript is a simple story for a friend as part of her CBT trauma therapy I'm trying to help her with. The noscript is just a bunch of echos with some shuf thrown in to make the story a little different every time it is read. (obviously when im more skilled i plan to use case statements and else if type stuff as well but im not there yet so im working with what ive got.)
My problem is It closes prematurely. Its closing despite shellcheck.net saying there are no errors! (My first one btw, YAY!) is there an answer to why it closes prematurely without a good reason? or a way to link multiple short noscripts to run one after the other if they can only be so long for some reason. Is there a way to extend the length of the noscript the terminal will run? ive kinda hit a wall, and it needs to it be a much more detailed and personalized narrative for it to be an effective CBT therapy tool for my friend who truly deserves it. And this community has been so kind in helping me on my learning noscripting journey, so a big thanks in advance to anyone who can help me figure this one out.
https://redd.it/zmvjc4
@r_bash
OK, so my noscript is a simple story for a friend as part of her CBT trauma therapy I'm trying to help her with. The noscript is just a bunch of echos with some shuf thrown in to make the story a little different every time it is read. (obviously when im more skilled i plan to use case statements and else if type stuff as well but im not there yet so im working with what ive got.)
My problem is It closes prematurely. Its closing despite shellcheck.net saying there are no errors! (My first one btw, YAY!) is there an answer to why it closes prematurely without a good reason? or a way to link multiple short noscripts to run one after the other if they can only be so long for some reason. Is there a way to extend the length of the noscript the terminal will run? ive kinda hit a wall, and it needs to it be a much more detailed and personalized narrative for it to be an effective CBT therapy tool for my friend who truly deserves it. And this community has been so kind in helping me on my learning noscripting journey, so a big thanks in advance to anyone who can help me figure this one out.
https://redd.it/zmvjc4
@r_bash
www.shellcheck.net
ShellCheck – shell noscript analysis tool
ShellCheck finds bugs in your shell noscripts
new to bash please help
hi so im new to bash and want to create a box with '-+' around words i have this but not sure why it isnt working. could someone help me please:
function generateBanner {
length=${#1}
echo -n '+'
for i in {0..$($length-3)}
do
echo -n '-'
done
echo '+'
}
https://redd.it/zmx7w9
@r_bash
hi so im new to bash and want to create a box with '-+' around words i have this but not sure why it isnt working. could someone help me please:
function generateBanner {
length=${#1}
echo -n '+'
for i in {0..$($length-3)}
do
echo -n '-'
done
echo '+'
}
https://redd.it/zmx7w9
@r_bash
reddit
new to bash please help
hi so im new to bash and want to create a box with '-+' around words i have this but not sure why it isnt working. could someone help me...
new to bash please help
hi so im trying to create a box with - and + in the corners but the box doesnt go all the way around this is my code and the output is bellow it. any help would be greatly appreciated.
\#!/bin/bash
function generateBanner {
length=${#1}
echo -n '+'
for i in {0..$length-3}
do
echo -n '-'
done
echo '+'
}
clear
​
welcomeMsg = '| hi how are you |'
generateBanner $welcomeMsg
echo $welcomeMsg
generateBanner $welcomeMsg
​
​
​
\+-+
|hi how are you |
\+-+
https://redd.it/zmzlch
@r_bash
hi so im trying to create a box with - and + in the corners but the box doesnt go all the way around this is my code and the output is bellow it. any help would be greatly appreciated.
\#!/bin/bash
function generateBanner {
length=${#1}
echo -n '+'
for i in {0..$length-3}
do
echo -n '-'
done
echo '+'
}
clear
​
welcomeMsg = '| hi how are you |'
generateBanner $welcomeMsg
echo $welcomeMsg
generateBanner $welcomeMsg
​
​
​
\+-+
|hi how are you |
\+-+
https://redd.it/zmzlch
@r_bash
reddit
new to bash please help
hi so im trying to create a box with - and + in the corners but the box doesnt go all the way around this is my code and the output is bellow it....
xargs string concatination
I'm builing a litte wrapper for diskus. I want find files or folders using find and then calculate their size; sort it by size and pass it to fzf. I was trying to do that using xargs. The problem is: diskus only prints the file size. What I want is the file size next to the file name. xargs is not mandatory, but I'm looking for the fastest possible solution for this kind of task. This is what I have:
find $PWD -maxdepth 1 -print0 | xargs -0 -I % diskus % | sort -r -h | fzf
But I could not figure out how to concatinate the output of diskus with the output of find (the file name).
Can somone help? If you think another approach would be faster/better I'm happy to hear that.
Thanks in advance!
EDIT:
To concatinate I tried something like this:
$ find $PWD -maxdepth 1 -print0 | xargs -0 -I {} printf "%s %s" $(diskus --size-format decimal {}) {}
diskus warning the results may be tainted. Re-run with -v/--verbose to print all errors.
If you don't have diskus you can use something like this for testing:
find $PWD -maxdepth 1 -print0 | xargs -0 -I {} printf "%s %s \n" $(file -b {}) {} | fzf
Edit 2:find $PWD -maxdepth 1 -print0 | xargs -0 -I {} printf "%s %s \\n" $(file -b {}) {} | fzf
to test you could use e.g /tmp or any other folder with files :)
https://redd.it/znakux
@r_bash
I'm builing a litte wrapper for diskus. I want find files or folders using find and then calculate their size; sort it by size and pass it to fzf. I was trying to do that using xargs. The problem is: diskus only prints the file size. What I want is the file size next to the file name. xargs is not mandatory, but I'm looking for the fastest possible solution for this kind of task. This is what I have:
find $PWD -maxdepth 1 -print0 | xargs -0 -I % diskus % | sort -r -h | fzf
But I could not figure out how to concatinate the output of diskus with the output of find (the file name).
Can somone help? If you think another approach would be faster/better I'm happy to hear that.
Thanks in advance!
EDIT:
To concatinate I tried something like this:
$ find $PWD -maxdepth 1 -print0 | xargs -0 -I {} printf "%s %s" $(diskus --size-format decimal {}) {}
diskus warning the results may be tainted. Re-run with -v/--verbose to print all errors.
If you don't have diskus you can use something like this for testing:
find $PWD -maxdepth 1 -print0 | xargs -0 -I {} printf "%s %s \n" $(file -b {}) {} | fzf
Edit 2:find $PWD -maxdepth 1 -print0 | xargs -0 -I {} printf "%s %s \\n" $(file -b {}) {} | fzf
to test you could use e.g /tmp or any other folder with files :)
https://redd.it/znakux
@r_bash
GitHub
GitHub - sharkdp/diskus: A minimal, fast alternative to 'du -sh'
A minimal, fast alternative to 'du -sh'. Contribute to sharkdp/diskus development by creating an account on GitHub.
Automatically Sourcing ~.config/bash/bashrc Doesn't Work
I want to move my ~/.bashrc to ~/.config/bash/bashrc.
This is my ~/.bashprofile:
```
[[ -f ~/.config/bash/bashrc ]] && source ~/.config/bash/bashrc
```
However, that file is not sourced automatically when I start a login shell.
The same syntax works in a ~/.bashprofile with these contents:
I've been unsuccessful googling this behaviour. Any of you wizards know what's up?
ETA: Can't edit the noscript. No, it's not because I forgot the slash. :-)
https://redd.it/zndgij
@r_bash
I want to move my ~/.bashrc to ~/.config/bash/bashrc.
This is my ~/.bashprofile:
```
[[ -f ~/.config/bash/bashrc ]] && source ~/.config/bash/bashrc
```
However, that file is not sourced automatically when I start a login shell.
The same syntax works in a ~/.bashprofile with these contents:
[[ -f ~/.bashrc ]] && source ~/.bashrc
I've been unsuccessful googling this behaviour. Any of you wizards know what's up?
ETA: Can't edit the noscript. No, it's not because I forgot the slash. :-)
https://redd.it/zndgij
@r_bash
reddit
Automatically Sourcing ~.config/bash/bashrc Doesn't Work
I want to move my ~/.bashrc to ~/.config/bash/bashrc. This is my ~/.bash_profile: ``` [[ -f ~/.config/bash/bashrc ]] && source...
User input
Hi how would I create something that asks a user for their name and store this as a variable. But if it contains numbers or blank space it will keep asking the user for their name.
Any help would be appreciated thanks
https://redd.it/zngtbm
@r_bash
Hi how would I create something that asks a user for their name and store this as a variable. But if it contains numbers or blank space it will keep asking the user for their name.
Any help would be appreciated thanks
https://redd.it/zngtbm
@r_bash
reddit
User input
Hi how would I create something that asks a user for their name and store this as a variable. But if it contains numbers or blank space it will...
Finished my first noscript, looking for feedback and advice
ASCII in the noscript here is a little borked but that's due to the size here. Any recommendations for improvements?
​
I was wondering whether my use of echo "$VAR" and if [[ -z file \]\]; then is correct here etc etc
​
Thank you!
​
#!/bin/bash
#------------Start Comments------------
#The noscript will scan system logs and various service logs.
#echo -e is intended to allow \n and to provide the function to drop lines, add text, all in one echo.
#If you are interested to evaluate whether a command resulted in no output, use -z "$variable" , it is the same as
#using "$variable" -eq "" .
#grep -a is intended to retrieve actual results and not "binary found" which ocaccionaly will come up.
#tail -10 piped to the grep command is used to retrieve the last 10 hits of that file from our results.
#Make sure to use spaces around your tests and within your variables, don't hug them too tight.
# if [ -f $0 ] means if the noscript file exists and tests for it.
#rm -- $0 will remove it.
#------------End Comments------------
echo -e "\n\n"
echo "████████╗██╗ ██╗███████╗ ██╗ ██╗██╗ ████████╗██╗███╗ ███╗ █████╗ ████████╗███████╗";
echo "╚══██╔══╝██║ ██║██╔════╝ ██║ ██║██║ ╚══██╔══╝██║████╗ ████║██╔══██╗╚══██╔══╝██╔════╝";
echo " ██║ ███████║█████╗ ██║ ██║██║ ██║ ██║██╔████╔██║███████║ ██║ █████╗ ";
echo " ██║ ██╔══██║██╔══╝ ██║ ██║██║ ██║ ██║██║╚██╔╝██║██╔══██║ ██║ ██╔══╝ ";
echo " ██║ ██║ ██║███████╗ ╚██████╔╝███████╗██║ ██║██║ ╚═╝ ██║██║ ██║ ██║ ███████╗";
echo " ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚══════╝";
echo " ";
echo "██╗ ██████╗ ██████╗ ███████╗ ██████╗ █████╗ ███╗ ██╗███╗ ██╗███████╗██████╗ ";
echo "██║ ██╔═══██╗██╔════╝ ██╔════╝██╔════╝██╔══██╗████╗ ██║████╗ ██║██╔════╝██╔══██╗ ";
echo "██║ ██║ ██║██║ ███╗ ███████╗██║ ███████║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝ ";
echo "██║ ██║ ██║██║ ██║ ╚════██║██║ ██╔══██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗ ";
echo "███████╗╚██████╔╝╚██████╔╝ ███████║╚██████╗██║ ██║██║ ╚████║██║ ╚████║███████╗██║ ██║ ";
echo "╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ";
echo -e "\n\n"
sleep 1s
echo -e "------------------------------------------\nPlease provide required IP or Search Term:\n------------------------------------------\n"
read input
echo -e "\n--------------------------------------\nData Received: "$input" - Searching...\n--------------------------------------\n"
sleep 1s
#Color Variables
NC="\0330m"
G="\033[0;32m"
R="\033[1;31m"
#journalctl can be used to query the contents of the systemd(1)
#journal as written by systemd-journald.service(8).
#This also shows the dmesg messages [kernel messages.
echo -e "-------------------\nJournalctl Log Results:\n-------------------"
GREPJOURNALCTL=$( journalctl | grep "$input" | tail -10 )
if [[ -z "$GREPJOURNALCTL" ]]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPJOURNALCTL"
echo ""
fi
sleep 1s
#Displays kernel messages from the kernel buffer during system boot.
#The one above using journalctl covers this but this is here just in case.
echo -e "-------------------\nDMESG\Kernel Buffer Log Results:\n-------------------"
GREPDMESG=$( grep --color='always' -a "$input" /var/log/dmesg 2> /dev/null | tail -10 )
if [ -f /var/log/dmesg ]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_DMESG" ]; then
echo -e
ASCII in the noscript here is a little borked but that's due to the size here. Any recommendations for improvements?
​
I was wondering whether my use of echo "$VAR" and if [[ -z file \]\]; then is correct here etc etc
​
Thank you!
​
#!/bin/bash
#------------Start Comments------------
#The noscript will scan system logs and various service logs.
#echo -e is intended to allow \n and to provide the function to drop lines, add text, all in one echo.
#If you are interested to evaluate whether a command resulted in no output, use -z "$variable" , it is the same as
#using "$variable" -eq "" .
#grep -a is intended to retrieve actual results and not "binary found" which ocaccionaly will come up.
#tail -10 piped to the grep command is used to retrieve the last 10 hits of that file from our results.
#Make sure to use spaces around your tests and within your variables, don't hug them too tight.
# if [ -f $0 ] means if the noscript file exists and tests for it.
#rm -- $0 will remove it.
#------------End Comments------------
echo -e "\n\n"
echo "████████╗██╗ ██╗███████╗ ██╗ ██╗██╗ ████████╗██╗███╗ ███╗ █████╗ ████████╗███████╗";
echo "╚══██╔══╝██║ ██║██╔════╝ ██║ ██║██║ ╚══██╔══╝██║████╗ ████║██╔══██╗╚══██╔══╝██╔════╝";
echo " ██║ ███████║█████╗ ██║ ██║██║ ██║ ██║██╔████╔██║███████║ ██║ █████╗ ";
echo " ██║ ██╔══██║██╔══╝ ██║ ██║██║ ██║ ██║██║╚██╔╝██║██╔══██║ ██║ ██╔══╝ ";
echo " ██║ ██║ ██║███████╗ ╚██████╔╝███████╗██║ ██║██║ ╚═╝ ██║██║ ██║ ██║ ███████╗";
echo " ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚══════╝";
echo " ";
echo "██╗ ██████╗ ██████╗ ███████╗ ██████╗ █████╗ ███╗ ██╗███╗ ██╗███████╗██████╗ ";
echo "██║ ██╔═══██╗██╔════╝ ██╔════╝██╔════╝██╔══██╗████╗ ██║████╗ ██║██╔════╝██╔══██╗ ";
echo "██║ ██║ ██║██║ ███╗ ███████╗██║ ███████║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝ ";
echo "██║ ██║ ██║██║ ██║ ╚════██║██║ ██╔══██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗ ";
echo "███████╗╚██████╔╝╚██████╔╝ ███████║╚██████╗██║ ██║██║ ╚████║██║ ╚████║███████╗██║ ██║ ";
echo "╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ";
echo -e "\n\n"
sleep 1s
echo -e "------------------------------------------\nPlease provide required IP or Search Term:\n------------------------------------------\n"
read input
echo -e "\n--------------------------------------\nData Received: "$input" - Searching...\n--------------------------------------\n"
sleep 1s
#Color Variables
NC="\0330m"
G="\033[0;32m"
R="\033[1;31m"
#journalctl can be used to query the contents of the systemd(1)
#journal as written by systemd-journald.service(8).
#This also shows the dmesg messages [kernel messages.
echo -e "-------------------\nJournalctl Log Results:\n-------------------"
GREPJOURNALCTL=$( journalctl | grep "$input" | tail -10 )
if [[ -z "$GREPJOURNALCTL" ]]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPJOURNALCTL"
echo ""
fi
sleep 1s
#Displays kernel messages from the kernel buffer during system boot.
#The one above using journalctl covers this but this is here just in case.
echo -e "-------------------\nDMESG\Kernel Buffer Log Results:\n-------------------"
GREPDMESG=$( grep --color='always' -a "$input" /var/log/dmesg 2> /dev/null | tail -10 )
if [ -f /var/log/dmesg ]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_DMESG" ]; then
echo -e
"\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPDMESG"
echo ""
fi
sleep 1s
echo -e "-------------------\nUbuntu Servers syslog Results:\n-------------------"
GREPSYSLOG=$( grep --color='always' -a "$input" /var/log/syslog 2> /dev/null | tail -10 )
if [ -f /var/log/syslog ]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
sleep 1s
fi
if [ -z "$GREP_SYSLOG" ]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPSYSLOG"
echo ""
fi
sleep 1s
echo -e "-------------------\nRed Hat Based Servers System Messages Log Results:\n-------------------"
GREPMESSAGES=$( grep --color='always' -a "$input" /var/log/messages 2> /dev/null | tail -10 )
if [ -f /var/log/messages ]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_MESSAGES" ]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPMESSAGES"
echo ""
fi
sleep 1s
echo -e "-------------------\nApache Error Log Results:\n-------------------"
GREPAPACHE=$( grep --color='always' -a "$input" /usr/local/apache/logs/errorlog 2> /dev/null | tail -10 )
if [[ -f /usr/local/apache/logs/errorlog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_APACHE" ]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPAPACHE"
echo ""
fi
sleep 1s
echo -e "--------------------\nModSec Log Results:\n--------------------"
GREPMODSEC=$( grep -a --color='always' "$input" /usr/local/apache/logs/modsecaudit.log 2> /dev/null | tail -10 )
if [[ -f /usr/local/apache/logs/modsecaudit.log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_MODSEC" ]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPMODSEC"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Access Log Results:\n--------------------"
GREPCPANELACCESS=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/accesslog 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/accesslog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_CPANELACCESS" ]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPCPANELACCESS"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Error Log Results:\n--------------------"
GREPCPANELERROR=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/errorlog 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/errorlog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_CPANELERROR" ]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPCPANELERROR"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Stats Log Results:\n--------------------"
GREPCPANELSTATS=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/statslog 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/statslog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_CPANELSTATS" ]; then
echo -e "\nNo Results Found\n"
else
echo -e
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPDMESG"
echo ""
fi
sleep 1s
echo -e "-------------------\nUbuntu Servers syslog Results:\n-------------------"
GREPSYSLOG=$( grep --color='always' -a "$input" /var/log/syslog 2> /dev/null | tail -10 )
if [ -f /var/log/syslog ]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
sleep 1s
fi
if [ -z "$GREP_SYSLOG" ]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPSYSLOG"
echo ""
fi
sleep 1s
echo -e "-------------------\nRed Hat Based Servers System Messages Log Results:\n-------------------"
GREPMESSAGES=$( grep --color='always' -a "$input" /var/log/messages 2> /dev/null | tail -10 )
if [ -f /var/log/messages ]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_MESSAGES" ]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPMESSAGES"
echo ""
fi
sleep 1s
echo -e "-------------------\nApache Error Log Results:\n-------------------"
GREPAPACHE=$( grep --color='always' -a "$input" /usr/local/apache/logs/errorlog 2> /dev/null | tail -10 )
if [[ -f /usr/local/apache/logs/errorlog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_APACHE" ]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPAPACHE"
echo ""
fi
sleep 1s
echo -e "--------------------\nModSec Log Results:\n--------------------"
GREPMODSEC=$( grep -a --color='always' "$input" /usr/local/apache/logs/modsecaudit.log 2> /dev/null | tail -10 )
if [[ -f /usr/local/apache/logs/modsecaudit.log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_MODSEC" ]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPMODSEC"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Access Log Results:\n--------------------"
GREPCPANELACCESS=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/accesslog 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/accesslog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_CPANELACCESS" ]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPCPANELACCESS"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Error Log Results:\n--------------------"
GREPCPANELERROR=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/errorlog 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/errorlog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_CPANELERROR" ]; then
echo -e "\nNo Results Found\n"
else
echo -e "\n${R}Results Found${NC}\n"
sleep 1s
echo "$GREPCPANELERROR"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Stats Log Results:\n--------------------"
GREPCPANELSTATS=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/statslog 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/statslog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_CPANELSTATS" ]; then
echo -e "\nNo Results Found\n"
else
echo -e
Finished my first noscript, looking for feedback and advice
ASCII in the noscript here is a little borked but that's due to the size here. Any recommendations for improvements?
​
I was wondering whether my use of echo "$VAR" and if \[\[ -z file \]\]; then is correct here etc etc
​
Thank you!
​
#!/bin/bash
#------------Start Comments------------
#The noscript will scan system logs and various service logs.
#echo -e is intended to allow \n and to provide the function to drop lines, add text, all in one echo.
#If you are interested to evaluate whether a command resulted in no output, use [ -z "$variable" ], it is the same as
#using [ "$variable" -eq "" ].
#grep -a is intended to retrieve actual results and not "binary found" which ocaccionaly will come up.
#tail -10 piped to the grep command is used to retrieve the last 10 hits of that file from our results.
#Make sure to use spaces around your tests and within your variables, don't hug them too tight.
# if [[ -f $0 ]] means if the noscript file exists and tests for it.
#rm -- $0 will remove it.
#------------End Comments------------
echo -e "\n\n"
echo "████████╗██╗ ██╗███████╗ ██╗ ██╗██╗ ████████╗██╗███╗ ███╗ █████╗ ████████╗███████╗";
echo "╚══██╔══╝██║ ██║██╔════╝ ██║ ██║██║ ╚══██╔══╝██║████╗ ████║██╔══██╗╚══██╔══╝██╔════╝";
echo " ██║ ███████║█████╗ ██║ ██║██║ ██║ ██║██╔████╔██║███████║ ██║ █████╗ ";
echo " ██║ ██╔══██║██╔══╝ ██║ ██║██║ ██║ ██║██║╚██╔╝██║██╔══██║ ██║ ██╔══╝ ";
echo " ██║ ██║ ██║███████╗ ╚██████╔╝███████╗██║ ██║██║ ╚═╝ ██║██║ ██║ ██║ ███████╗";
echo " ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚══════╝";
echo " ";
echo "██╗ ██████╗ ██████╗ ███████╗ ██████╗ █████╗ ███╗ ██╗███╗ ██╗███████╗██████╗ ";
echo "██║ ██╔═══██╗██╔════╝ ██╔════╝██╔════╝██╔══██╗████╗ ██║████╗ ██║██╔════╝██╔══██╗ ";
echo "██║ ██║ ██║██║ ███╗ ███████╗██║ ███████║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝ ";
echo "██║ ██║ ██║██║ ██║ ╚════██║██║ ██╔══██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗ ";
echo "███████╗╚██████╔╝╚██████╔╝ ███████║╚██████╗██║ ██║██║ ╚████║██║ ╚████║███████╗██║ ██║ ";
echo "╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ";
echo -e "\n\n"
sleep 1s
echo -e "------------------------------------------\nPlease provide required IP or Search Term:\n------------------------------------------\n"
read input
echo -e "\n--------------------------------------\nData Received: "$input" - Searching...\n--------------------------------------\n"
sleep 1s
#Color Variables
NC="\033[0m"
G="\033[0;32m"
R="\033[1;31m"
#journalctl can be used to query the contents of the systemd(1)
#journal as written by systemd-journald.service(8).
#This also shows the dmesg messages [kernel messages].
echo -e "-------------------\nJournalctl Log Results:\n-------------------"
GREP_JOURNALCTL=$( journalctl | grep "$input" | tail -10 )
if [[ -z "$GREP_JOURNALCTL" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_JOURNALCTL"
echo ""
fi
sleep 1s
#Displays kernel messages from the kernel buffer during system boot.
#The one above using journalctl covers this but this is here just in case.
echo -e "-------------------\nDMESG\Kernel Buffer Log Results:\n-------------------"
GREP_DMESG=$( grep --color='always' -a "$input" /var/log/dmesg 2> /dev/null | tail -10 )
if [[ -f /var/log/dmesg ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_DMESG" ]]; then
echo -e
ASCII in the noscript here is a little borked but that's due to the size here. Any recommendations for improvements?
​
I was wondering whether my use of echo "$VAR" and if \[\[ -z file \]\]; then is correct here etc etc
​
Thank you!
​
#!/bin/bash
#------------Start Comments------------
#The noscript will scan system logs and various service logs.
#echo -e is intended to allow \n and to provide the function to drop lines, add text, all in one echo.
#If you are interested to evaluate whether a command resulted in no output, use [ -z "$variable" ], it is the same as
#using [ "$variable" -eq "" ].
#grep -a is intended to retrieve actual results and not "binary found" which ocaccionaly will come up.
#tail -10 piped to the grep command is used to retrieve the last 10 hits of that file from our results.
#Make sure to use spaces around your tests and within your variables, don't hug them too tight.
# if [[ -f $0 ]] means if the noscript file exists and tests for it.
#rm -- $0 will remove it.
#------------End Comments------------
echo -e "\n\n"
echo "████████╗██╗ ██╗███████╗ ██╗ ██╗██╗ ████████╗██╗███╗ ███╗ █████╗ ████████╗███████╗";
echo "╚══██╔══╝██║ ██║██╔════╝ ██║ ██║██║ ╚══██╔══╝██║████╗ ████║██╔══██╗╚══██╔══╝██╔════╝";
echo " ██║ ███████║█████╗ ██║ ██║██║ ██║ ██║██╔████╔██║███████║ ██║ █████╗ ";
echo " ██║ ██╔══██║██╔══╝ ██║ ██║██║ ██║ ██║██║╚██╔╝██║██╔══██║ ██║ ██╔══╝ ";
echo " ██║ ██║ ██║███████╗ ╚██████╔╝███████╗██║ ██║██║ ╚═╝ ██║██║ ██║ ██║ ███████╗";
echo " ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚══════╝";
echo " ";
echo "██╗ ██████╗ ██████╗ ███████╗ ██████╗ █████╗ ███╗ ██╗███╗ ██╗███████╗██████╗ ";
echo "██║ ██╔═══██╗██╔════╝ ██╔════╝██╔════╝██╔══██╗████╗ ██║████╗ ██║██╔════╝██╔══██╗ ";
echo "██║ ██║ ██║██║ ███╗ ███████╗██║ ███████║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝ ";
echo "██║ ██║ ██║██║ ██║ ╚════██║██║ ██╔══██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗ ";
echo "███████╗╚██████╔╝╚██████╔╝ ███████║╚██████╗██║ ██║██║ ╚████║██║ ╚████║███████╗██║ ██║ ";
echo "╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ";
echo -e "\n\n"
sleep 1s
echo -e "------------------------------------------\nPlease provide required IP or Search Term:\n------------------------------------------\n"
read input
echo -e "\n--------------------------------------\nData Received: "$input" - Searching...\n--------------------------------------\n"
sleep 1s
#Color Variables
NC="\033[0m"
G="\033[0;32m"
R="\033[1;31m"
#journalctl can be used to query the contents of the systemd(1)
#journal as written by systemd-journald.service(8).
#This also shows the dmesg messages [kernel messages].
echo -e "-------------------\nJournalctl Log Results:\n-------------------"
GREP_JOURNALCTL=$( journalctl | grep "$input" | tail -10 )
if [[ -z "$GREP_JOURNALCTL" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_JOURNALCTL"
echo ""
fi
sleep 1s
#Displays kernel messages from the kernel buffer during system boot.
#The one above using journalctl covers this but this is here just in case.
echo -e "-------------------\nDMESG\Kernel Buffer Log Results:\n-------------------"
GREP_DMESG=$( grep --color='always' -a "$input" /var/log/dmesg 2> /dev/null | tail -10 )
if [[ -f /var/log/dmesg ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_DMESG" ]]; then
echo -e
"\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_DMESG"
echo ""
fi
sleep 1s
echo -e "-------------------\nUbuntu Servers syslog Results:\n-------------------"
GREP_SYSLOG=$( grep --color='always' -a "$input" /var/log/syslog 2> /dev/null | tail -10 )
if [[ -f /var/log/syslog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
sleep 1s
fi
if [[ -z "$GREP_SYSLOG" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_SYSLOG"
echo ""
fi
sleep 1s
echo -e "-------------------\nRed Hat Based Servers System Messages Log Results:\n-------------------"
GREP_MESSAGES=$( grep --color='always' -a "$input" /var/log/messages 2> /dev/null | tail -10 )
if [[ -f /var/log/messages ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_MESSAGES" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_MESSAGES"
echo ""
fi
sleep 1s
echo -e "-------------------\nApache Error Log Results:\n-------------------"
GREP_APACHE=$( grep --color='always' -a "$input" /usr/local/apache/logs/error_log 2> /dev/null | tail -10 )
if [[ -f /usr/local/apache/logs/error_log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_APACHE" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_APACHE"
echo ""
fi
sleep 1s
echo -e "--------------------\nModSec Log Results:\n--------------------"
GREP_MODSEC=$( grep -a --color='always' "$input" /usr/local/apache/logs/modsec_audit.log 2> /dev/null | tail -10 )
if [[ -f /usr/local/apache/logs/modsec_audit.log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_MODSEC" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_MODSEC"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Access Log Results:\n--------------------"
GREP_CPANELACCESS=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/access_log 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/access_log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_CPANELACCESS" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_CPANELACCESS"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Error Log Results:\n--------------------"
GREP_CPANELERROR=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/error_log 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/error_log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_CPANELERROR" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_CPANELERROR"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Stats Log Results:\n--------------------"
GREP_CPANELSTATS=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/stats_log 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/stats_log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_CPANELSTATS" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_DMESG"
echo ""
fi
sleep 1s
echo -e "-------------------\nUbuntu Servers syslog Results:\n-------------------"
GREP_SYSLOG=$( grep --color='always' -a "$input" /var/log/syslog 2> /dev/null | tail -10 )
if [[ -f /var/log/syslog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
sleep 1s
fi
if [[ -z "$GREP_SYSLOG" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_SYSLOG"
echo ""
fi
sleep 1s
echo -e "-------------------\nRed Hat Based Servers System Messages Log Results:\n-------------------"
GREP_MESSAGES=$( grep --color='always' -a "$input" /var/log/messages 2> /dev/null | tail -10 )
if [[ -f /var/log/messages ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_MESSAGES" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_MESSAGES"
echo ""
fi
sleep 1s
echo -e "-------------------\nApache Error Log Results:\n-------------------"
GREP_APACHE=$( grep --color='always' -a "$input" /usr/local/apache/logs/error_log 2> /dev/null | tail -10 )
if [[ -f /usr/local/apache/logs/error_log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_APACHE" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_APACHE"
echo ""
fi
sleep 1s
echo -e "--------------------\nModSec Log Results:\n--------------------"
GREP_MODSEC=$( grep -a --color='always' "$input" /usr/local/apache/logs/modsec_audit.log 2> /dev/null | tail -10 )
if [[ -f /usr/local/apache/logs/modsec_audit.log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_MODSEC" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_MODSEC"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Access Log Results:\n--------------------"
GREP_CPANELACCESS=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/access_log 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/access_log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_CPANELACCESS" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_CPANELACCESS"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Error Log Results:\n--------------------"
GREP_CPANELERROR=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/error_log 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/error_log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_CPANELERROR" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_CPANELERROR"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Stats Log Results:\n--------------------"
GREP_CPANELSTATS=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/stats_log 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/stats_log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_CPANELSTATS" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e
"\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_CPANELSTATS"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Check Service Log Results:\n--------------------"
GREP_CPANELCHECKSERVICE=$( grep -a --color='always' "$input" /var/log/chkservd.log 2> /dev/null| tail -10 )
if [[ -f /var/log/chkservd.log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_CPANELCHECKSERVICE" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_CPANELCHECKSERVICE"
echo ""
fi
sleep 1s
echo -e "--------------------\nExim Main Log Results:\n--------------------"
GREP_EXIMMAINLOG=$( grep -a --color='always' "$input" /var/log/exim_mainlog 2> /dev/null | tail -10 )
if [[ -f /var/log/exim_mainlog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_EXIMMAINLOG" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_EXIMMAINLOG"
echo ""
fi
sleep 1s
echo -e "--------------------\nExim Panic Log Results:\n--------------------"
GREP_EXIMPANICLOG=$( grep -a --color='always' "$input" /var/log/exim_paniclog 2> /dev/null | tail -10 )
if [[ -f /var/log/exim_paniclog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_EXIMPANICLOG" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_EXIMPANICLOG"
echo ""
fi
sleep 1s
echo -e "--------------------\nExim Reject Log Results:\n--------------------"
GREP_EXIMREJECT=$( grep -a --color='always' "$input" /var/log/exim_rejectlog 2> /dev/null | tail -10 )
if [[ -f /var/log/exim_rejectlog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_EXIMREJECT" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_EXIMREJECT"
echo ""
fi
sleep 1s
echo -e "-----------------\nCSF/LFD Log Results:\n-----------------"
GREP_LFD=$( grep -a --color='always' "$input" /var/log/lfd.log 2> /dev/null | tail -10 )
if [[ -f /var/log/lfd.log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_LFD" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_LFD"
echo ""
fi
sleep 1s
echo -e "-----------------\nCSF Allow/Deny Log Results:\n-----------------"
GREP_CSFDENY=$( grep -a --color='always' "$input" /etc/csf/csf.deny 2> /dev/null | tail -10 )
if [[ -f /etc/csf/csf.deny ]]; then
echo -e "\nCSF Deny Log Available - Scanning"
else
echo -e "\nCSF Deny Log Not Available"
fi
if [[ -z "$GREP_CSFDENY" ]]; then
echo -e "\n***No Results Found Within CSF Deny Log***\n"
else
echo -e "\n${R}***Results Found Within CSF Deny Log***${NC}\n"
sleep 1s
echo "$GREP_CSFDENY"
echo ""
fi
GREP_CSFALLOW=$( grep -a --color='always' "$input" /etc/csf/csf.allow 2> /dev/null | tail -10 )
if [[ -f /etc/csf/csf.allow ]]; then
echo -e "\nCSF Allow Log Available - Scanning"
else
echo -e "\nCSF Allow Log Not Available"
fi
if [[ -z "$GREP_CSFALLOW" ]]; then
echo -e "\n***No Results Found Within CSF Allow Log***\n"
else
echo -e "\n${R}***Results Found Within CSF Allow Log***${NC}\n"
sleep 1s
echo "$GREP_CSFALLOW"
echo ""
fi
sleep 1s
echo -e "-----------------\ncPHulk Brute
sleep 1s
echo "$GREP_CPANELSTATS"
echo ""
fi
sleep 1s
echo -e "--------------------\ncPanel Check Service Log Results:\n--------------------"
GREP_CPANELCHECKSERVICE=$( grep -a --color='always' "$input" /var/log/chkservd.log 2> /dev/null| tail -10 )
if [[ -f /var/log/chkservd.log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_CPANELCHECKSERVICE" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_CPANELCHECKSERVICE"
echo ""
fi
sleep 1s
echo -e "--------------------\nExim Main Log Results:\n--------------------"
GREP_EXIMMAINLOG=$( grep -a --color='always' "$input" /var/log/exim_mainlog 2> /dev/null | tail -10 )
if [[ -f /var/log/exim_mainlog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_EXIMMAINLOG" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_EXIMMAINLOG"
echo ""
fi
sleep 1s
echo -e "--------------------\nExim Panic Log Results:\n--------------------"
GREP_EXIMPANICLOG=$( grep -a --color='always' "$input" /var/log/exim_paniclog 2> /dev/null | tail -10 )
if [[ -f /var/log/exim_paniclog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_EXIMPANICLOG" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_EXIMPANICLOG"
echo ""
fi
sleep 1s
echo -e "--------------------\nExim Reject Log Results:\n--------------------"
GREP_EXIMREJECT=$( grep -a --color='always' "$input" /var/log/exim_rejectlog 2> /dev/null | tail -10 )
if [[ -f /var/log/exim_rejectlog ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_EXIMREJECT" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_EXIMREJECT"
echo ""
fi
sleep 1s
echo -e "-----------------\nCSF/LFD Log Results:\n-----------------"
GREP_LFD=$( grep -a --color='always' "$input" /var/log/lfd.log 2> /dev/null | tail -10 )
if [[ -f /var/log/lfd.log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_LFD" ]]; then
echo -e "\n***No Results Found***\n"
else
echo -e "\n${R}***Results Found***${NC}\n"
sleep 1s
echo "$GREP_LFD"
echo ""
fi
sleep 1s
echo -e "-----------------\nCSF Allow/Deny Log Results:\n-----------------"
GREP_CSFDENY=$( grep -a --color='always' "$input" /etc/csf/csf.deny 2> /dev/null | tail -10 )
if [[ -f /etc/csf/csf.deny ]]; then
echo -e "\nCSF Deny Log Available - Scanning"
else
echo -e "\nCSF Deny Log Not Available"
fi
if [[ -z "$GREP_CSFDENY" ]]; then
echo -e "\n***No Results Found Within CSF Deny Log***\n"
else
echo -e "\n${R}***Results Found Within CSF Deny Log***${NC}\n"
sleep 1s
echo "$GREP_CSFDENY"
echo ""
fi
GREP_CSFALLOW=$( grep -a --color='always' "$input" /etc/csf/csf.allow 2> /dev/null | tail -10 )
if [[ -f /etc/csf/csf.allow ]]; then
echo -e "\nCSF Allow Log Available - Scanning"
else
echo -e "\nCSF Allow Log Not Available"
fi
if [[ -z "$GREP_CSFALLOW" ]]; then
echo -e "\n***No Results Found Within CSF Allow Log***\n"
else
echo -e "\n${R}***Results Found Within CSF Allow Log***${NC}\n"
sleep 1s
echo "$GREP_CSFALLOW"
echo ""
fi
sleep 1s
echo -e "-----------------\ncPHulk Brute
Force Protection Log Results:\n-----------------"
GREP_CPHULK=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/cphulkd.log 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/cphulkd.log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_CPHULK" ]]; then
echo -e "\n***No Results Found Within cPHulk Log***\n"
else
echo -e "\n${R}***Results Found Within cPHulk Log***${NC}\n"
sleep 1s
echo "$GREP_CPHULK"
echo ""
fi
GREP_CPHULKERR=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/cphulkd_errors.log 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/cphulkd_errors.log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_CPHULKERR" ]
then
echo -e "\n***No Results Found Within cPHulk Error Log***\n"
else
echo -e "\n${R}***Results Found Within cPHulk Error Log***${NC}\n"
sleep 1s
echo "$GREP_CPHULKERR"
echo ""
fi
sleep 1s
echo -e "-------------------------------------------\nI Hope you found what you were looking for!\n-------------------------------------------"
sleep 3s
if [[ -f "$0" ]]
then
rm -- "$0"
fi
exit
https://redd.it/znxvrb
@r_bash
GREP_CPHULK=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/cphulkd.log 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/cphulkd.log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [[ -z "$GREP_CPHULK" ]]; then
echo -e "\n***No Results Found Within cPHulk Log***\n"
else
echo -e "\n${R}***Results Found Within cPHulk Log***${NC}\n"
sleep 1s
echo "$GREP_CPHULK"
echo ""
fi
GREP_CPHULKERR=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/cphulkd_errors.log 2> /dev/null | tail -10 )
if [[ -f /usr/local/cpanel/logs/cphulkd_errors.log ]]; then
echo -e "\nLog Available - Scanning"
else
echo -e "\nLog Not Available"
fi
if [ -z "$GREP_CPHULKERR" ]
then
echo -e "\n***No Results Found Within cPHulk Error Log***\n"
else
echo -e "\n${R}***Results Found Within cPHulk Error Log***${NC}\n"
sleep 1s
echo "$GREP_CPHULKERR"
echo ""
fi
sleep 1s
echo -e "-------------------------------------------\nI Hope you found what you were looking for!\n-------------------------------------------"
sleep 3s
if [[ -f "$0" ]]
then
rm -- "$0"
fi
exit
https://redd.it/znxvrb
@r_bash
reddit
Finished my first noscript, looking for feedback and advice
ASCII in the noscript here is a little borked but that's due to the size here. Any recommendations for improvements? I was wondering...
Optimize noscript with
I've created a simple one-liner to give me the last 10 commits and wrap them in a https call. However, I had to do some weird workarounds that I hope to get rid of.
What I have so far
This works, but there are a few issues:
1. I had to add | (any other special char would do) here
2. Instead of the entire commit hash I would like to have short form in the braces for the markdown display.
https://redd.it/zo4pyz
@r_bash
sedI've created a simple one-liner to give me the last 10 commits and wrap them in a https call. However, I had to do some weird workarounds that I hope to get rid of.
What I have so far
git log --pretty="%H| - %s" | grep -v Merge | grep -v chore | head -n 10 | sed 's/\(.*|\)/[&]\(https:\/\/github.com\/'$org'\/'$repo'\/&\)/g' | sed 's/|//g'This works, but there are a few issues:
1. I had to add | (any other special char would do) here
"%H| - %s", what I really want is "%H - %s" and in sed select the commit hash, this doesn't work. How to select the whole string up but excluding space?2. Instead of the entire commit hash I would like to have short form in the braces for the markdown display.
https://redd.it/zo4pyz
@r_bash
reddit
Optimize noscript with `sed`
I've created a simple one-liner to give me the last 10 commits and wrap them in a https call. However, I had to do some weird workarounds that I...