r_bash – Telegram
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 ~/.bash
profile 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
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
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 "$GREP
JOURNALCTL" ]]; 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-------------------"
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
"\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-------------------"
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 "\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-------------------"
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 "\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-------------------"
GREP
APACHE=$( grep --color='always' -a "$input" /usr/local/apache/logs/errorlog 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 "\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--------------------"
GREP
MODSEC=$( grep -a --color='always' "$input" /usr/local/apache/logs/modsecaudit.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 "\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--------------------"
GREP
CPANELACCESS=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/accesslog 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 "\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--------------------"
GREP
CPANELERROR=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/errorlog 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 "\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--------------------"
GREP
CPANELSTATS=$( grep -a --color='always' "$input" /usr/local/cpanel/logs/statslog 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 "\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
"\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
"\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
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
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 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
ffmpeg transcoding noscript

Hi wonderful Bashers.
I've created this basic noscript to detect new MKV files, transcode to MP4 for Roku, and if successful, delete the MKV file.


Every time I run this, I get a log entry that an output has to be specified, and I'm at a loss. Would anyone here see any of my glaring errors, I'm sure there's plenty as I'm a total diletant.


---


#!/bin/bash


# Set the folder to monitor
folder="/mnt/dietpiuserdata/downloads"


# Set the output folder
output="/mnt/dietpi
userdata/downloads/RokuTranscoded"


# Set the log file
log="/home/dietpi/transcode
logs"


# Set the transcoding options
options="-c:v libx264 -f mp4 -c:a aac -ab 192k -preset slow -profile:v high -level 4 -crf 20"


# Set the file extension to watch for
ext=".mkv"


# Infinite loop to continuously monitor the directory
while true; do
# Find all the files with the specified extension in the directory and its subdirectories
for file in $(find $dir -name $ext); do
# Check if a file was found
if [ -f "$file" ]; then
# Transcode the file and store the output in a variable
output=$(ffmpeg -i "$file" "$options" "$dst/${file%.
}.mp4")


# Check if the transcoding was successful
if $? -eq 0 ; then
# Transcoding was successful, delete the original file
rm "$file"
# Log the event
echo "$(date): Transcoded $file and deleted original" >> $log
else
# Transcoding failed, log the error
echo "$(date): Error transcoding $file: $output" >> $log
fi
fi
done
# Sleep for 1 hour before checking again
sleep 3600
done

https://redd.it/zobghb
@r_bash
Beginner looking for documentation or guides for whiptail...?

Hey everyone :-) I'm learning how to do bash noscripting, and I'm really loving it. It's oddly calming. Perhaps it brings out my inner Spock.

However, something that doesn't calm me so much is the lack of organisation and accessibility of my growing number of noscripts!

So I decided to assimilate them all into a super noscript with a menu built in, which I'm tentatively naming Scriptonomicon. I know. It's dumb. But what else am I gunna call it? 'Script Manager'? 'Script List'? Too vanilla.

Anyhow, I started out using dialog first, but have since decided that whiptail is probably the better option, but I'm struggling to find any good documentation for it. Can anyone point me to any guides, tutuorials or even a book? I'm mostly interested in getting a menu with sub-menus up and running at first, because I'm still a beginner. But eventually it would be great to be able to figure out how to do fancier stuff, like loading bars, disowning jobs and then returning to the menu, etc.

https://redd.it/zov3xg
@r_bash
noscript fails at first check

when using sudo -i before using ./ to execute the noscript, it fails saying that It could not find any keys despite them being there in /root/.ssh

​

\#!/bin/bash

​

LOCAL_DIR=/mnt/sda

​

\#check if user has elevated priveliges

​

ID=$(whoami)

IDCHECK=$(echo "root")

FIRSTTIMEUSER=$(ls \~/.ssh | grep id)

FIRSTTIMEUSERCHECK=$(ls \~/.ssh)

SSHFIRSTTIME=$(ssh $USER@$ADDRESS)

SSHFIRSTTIMECHECK=$(ssh $USER@$ADSDRESS | grep "Are you sure you want to continue connecting (yes/no)?")

PASSWORDAUTH=$(echo "yes")



touch \~/log.txt

​

\#check that user is superuser

​

if [[ $ID != $IDCHECK \]\]; then

echo "please execute this noscript as superuser to ensure root direcotry is backed up"

exit

elif [[ $FIRSTTIMEUSERCHECK != $FIRSTTIMEUSER \]\]; then

echo "no ssh keys detected, please ensure ssh is set up, noscript will remain inacitve for 1 hour to allow you to check ssh is set up before proceeding"

sleep 3600

fi

​

\#prompt for details

​

echo "ssh user"

read USER

​

echo "ssh password"

read -s PASSWORD

​

echo "ADDRESS"

read -s ADDRESS

​

echo "password authentication (yes/no)"

read PASSWORDAUTHENTICATION

​

\#zipping root directory excluding certain ones

cd $LOCAL_DIR

zip -9 -T -r --exclude=/proc/* --exclude=/sys/* --exclude=/boot/* --exclude=/tmp/* --exclude=/mnt/* --exclude=/media/* --exclude=/dev/* --exclude=/swapfile --exclude=/swap/* --exclude=/run/* --exclude=/Trash/* --exclude=/"lost+found"/* / backup.zip 2> \~/log.txt

​

\#check for password authentication

​

if [[ $PASSWORDAUTHENTICATION = $PASSWORDAUTH \]\]; then <<EOF

ssh $USER@$ADDRESS

$PASSWORD

\#following steps navigate to local directory and remote directory

lcd $LOCAL_DIR

cd adgow

cd "files to encrypt"

put backup.zip

elif [[$PASSWORDAUTHENTICATION != $PASSWORDAUTH \]\]; then

ssh $USER@$ADDRESS

lcd $LOCAL_DIR

cd adgow

cd "files to encrypt"

put backup.zip

fi

&#x200B;

\#check if first time connection message comes up and answer yes if so

&#x200B;

if [[ $SSHFIRSTTIME == $SSHFIRSTTIMECHECK \]\]

then

yes

fi

&#x200B;

EOF

https://redd.it/zoun9y
@r_bash
Could you guys share some smartctl output samples for my noscript?

Speaking about https://github.com/slowpeek/hddtemp. It is based on smartctl which uses three different output formats: ata, nvme and scsi. I've got enough SATA disks, but none of NVME nor SCSI to get real smartctl output samples.

I want to add some samples to the public repo. Could you share output of smartctl -i -A -q noserial for your NVME/SCSI disks?

https://redd.it/zpqmz1
@r_bash
How to create an alias for a "cat" file usable in a path

Hello everybody,

I have two hughe files (150G each) and I need to use a tool for which I should suuply them as a single file (since the tool only accepts one file). However, I do not really want to merge these files for several reasons, but I cannot pipe them using something like `<(cat file1 file2)` or `myfile=$(cat file1 file2)` because the noscript use the path of the input file for make use of another external tool on it.

So I would need something like:

alias myfile = "cat file1 file2"

such that, using:

tool_x --file /path/myfile

would work.

&#x200B;

I already tried the aforementioned commands but it didn't work.

Is it possible to achieve something like that?

&#x200B;

**NB** I asked the same question [here](https://askubuntu.com/questions/1446265/how-to-create-an-alias-for-a-cat-file-usable-in-a-path). I'll let you know if I get some external interesting answer.

https://redd.it/zpqcff
@r_bash
How to limit download speed of git clone?

How to limit download rate or download speed of git clone?

https://redd.it/zpsn33
@r_bash
How can I avoid this `-bash: /usr/bin/<functionName>: Argument list too long` error?

I have a file in my $PATH (at, say, `/usr/bin/functionName`) that looks like the following:

#!/bin/bash

functionName() {
#do stuff
}

(( $# > 0 )) && functionName "${@}"

When I pass it (admittedly large) inputs it throws an error:

functionName "$largeInput1" "$largeInput2"
-bash: /usr/bin/<functionName>: Argument list too long

Interestingly, if I source the function first it runs just fine

source "$(which functionName)"
functionName "$largeInput1" "$largeInput2"

<returns expected output>

I know that I could just source the noscript in my `.bashrc` file, but (if possible) Id rather not, since then I have to do that for all my custom functions that might recieve large inputs at some point (so, basically all of them). And, honestly, "putting them in my $PATH and having them just work" seems like a better solution.

Un-wrapping the code from a function *might* work too, but again im not crazy about this.

Best solution I have so far is to add something like this to my .bashrc:

trapfun() { which "${*%% *}" | grep -q -E '^.+$' && source "$(which "${*%% *}")" && "${@}"; }
trap 'trapfun "${BASH_COMMAND}"' ERR

Which works in some simple testing but seems fragile. Id feel a bit better about it with some additional checks before trying to source and re-run the command (e.g., if I could get the trap to fetch the error message text and make sure it contains `-bash: * Argument list too long`, perhaps a check with `file` to ensure that the file returned by `which <functionNAme>` is a sourceable shell noscript, etc.)

Any suggestions?

***

Heres an actual example with code and inputs

#/usr/bin/linecat

#!/bin/bash
linecat () {
(( ${#} < 2 )) && echo "${@}" && return;

local -a A;
local -a B;

mapfile -t B < <(echo "${2}");
mapfile -t A < <(echo "${1}");

(( ${#A[@]} < ${#B[@]} )) && { local -a Aadd; mapfile -t Aadd < <(printf '%0.0s\n' "${B[@]:${#A[@]}}"); A+=("${Aadd[@]}"); }

linecat "$(printf "$(printf '%s %%s\n' "${A[@]}")" "${B[@]}")" "${@:3}"
}
(( $# > 0 )) && linecat "${@}"
# commands

a="$(dd if=/dev/urandom bs=64k count=4|hexdump)"
b="$(dd if=/dev/urandom bs=64k count=5|hexdump)"

linecat "$a" "$b"

# THROWS ERROR

source "$(which linecat)"
linecat "$a" "$b"

# RETURNS CORRECT OUTPUT

https://redd.it/zptkru
@r_bash
What can I do if I constantly get memory garbage and all the datas are deleted?

Hi


First of all: Sorry for my lack of programming knowledge and my English as well.


Before I wanted to write down the question I wanted to check how my code works. The point is that its on a remote computer, so I've checked in via ssh username and my password. I've used to cd command to navigate me into a repository where my certain files are.


In this repository there are a .txt file called "surname.txt", where there are different strings and they're from each other with a new line and one code which is called rand1.cpp and reads from the previous .txt file. It looks like this: https://codeshare.io/Rb1Ze3


I've used the g++ complier in order to build the code, and the "./.out" in order to run the program, but it always wrote memory garbage. I've checked my surname.txt file and all the datas have been dissappeared. I remember that was one of those parts of my code which is actually worked... Nevermind. So I've rewrote it. And nothing.


I use nano in order to edit a file. I didn't touch it, I've just checked that all the strings are there. (Yes, they were.) After that I've used the g++ again and checked the .txt second time that all the strings are there. (Yes, they were.) I've run the code and again... Memory garbage. I did this multiple times.


Please help. What have I done wrong?

https://redd.it/zpxda7
@r_bash
Rookie question Getting the noscript report.

Hello community!

&#x200B;

I wonder if there is any possibility to make a statement in the bash noscript which create a report of recent changes in it and for example send a notification via e-mail? Is this even possible to do in bash, without any external plugins?

https://redd.it/zpx29b
@r_bash
How to enforce stdout=PIPE in bash without cat?

Sometimes I want to ensure, that stdout is a pipe as this may change the behavior of a program in a wanted way. E.g. more has a nice side effect when it sends output to a pipe instead of a terminal: It adds the file noscript - embedded in lines with colons - to the output. Hence a command like the following is a quick hack to generate an overview in the output:

more /etc/cron.d/* | cat

I‘m just curious: Does anybody knows another - easy to type - method, how to trigger this output mode of more?

https://redd.it/zq1gn4
@r_bash
I have a programming question :)

Hey fellas,

I'm on the quest to kind of automate my semester in terms of checking due dates and such things of that nature. Is there a way that I could grab the due dates that are posted to the website that holds my assignments and stuff? Like, for example:

&#x200B;

I would like to have a noscript that runs with cron every so often (That part I know how to do) and have it send me a desktop notification saying y'know.. something like "You have a math final due..... blah blah".

I know the wget command does things with websites and HTML and all that good stuff, but is there a way to do what I wanna execute within the command line?

&#x200B;

Ps: I am doing this strictly for fun :D because I have a newfound love for the linux command line because of its flexibility

so any fun ways to do this, please let me know!

https://redd.it/zq3ugq
@r_bash