Remove a function when vim or any other program opens
So, I have a function in my bashrc which displays the time in my terminal, however I don't want the function to run when vim or some other program is opened is this possible?
https://redd.it/x7xkpy
@r_bash
So, I have a function in my bashrc which displays the time in my terminal, however I don't want the function to run when vim or some other program is opened is this possible?
https://redd.it/x7xkpy
@r_bash
reddit
Remove a function when vim or any other program opens
So, I have a function in my bashrc which displays the time in my terminal, however I don't want the function to run when vim or some other program...
wild card works in shell but not in noscript
So I'm writing a noscript for my church and I'm trying to use a wild card to copy some files from one directory to another. It's noteworthy to mention that it's on a flash drive. So when I run the command the the terminal it works just fine, but when I run it as a noscript it doesn't work. Here's an example, and I'll post the actual noscript if that would be helpful
Cp /run/media/username/church/noscript\ resources/ hymnal/hymns/tlh"$hymn1"*.mid /run/media/username/church/"$datefolder"
I should note that the wild card is to fill in the unknown parts of the file name, things like \_5 for 5 verses
Also both of the variables are defined already
I will probably be posting the noscript because I realize that will be helpful
Here is the noscript:
#!/bin/bash
user=$(pwd | cut -d / -f 4)
distro=$(distro | grep Fedora)
if [ $? != 0 ]
then
distro=/media/
else
distro=/run/media/
fi
fdrive="$distro$user/church"
hymnpath="$fdrive/Script\ resources/hymns/Lutheran\ hymnal/"
hymn_1=$1
hymn_2=$2
hymn_3=$3
hymn_4=$4
date=$5
date_folder="$fdrive/$date"
litpath="$fdrive/Script\ resources/Litergies/"
if [ "$1" == "-n" ]
then
read -p "Enter the first hymn " hymn_1
read -p "Enter the second hymn " hymn_2
read -p "Enter the third hymn " hymn_3
read -p "Enter the fourth hymn " hymn_4
read -p "Enter the date " date
fi
if [ "$1" == "-h" ]
then
echo "Syntax:"
echo "./hymnnoscript [hymn 1] [hymn 2] [hymn 3] [hymn 4] [date]"
echo "enter n for no parameters"
echo "enter h for help"
fi
regular (){
echo "regular"
cp "$hymnpath"tlh"$hymn_1"*.mid $date_folder
cp "$litpath"revisedPAGE5best*.mid $date_folder
cp "$hymnpath"tlh"$hymn_2"*.mid $date_folder
cp "$litpath"OFFERPG5*.mid $date_folder
cp "$hymnpath"tlh"$hymn_3"*.mid $date_folder
cp "$litpath"2collectbendpg14*.mid $date_folder
cp "$hymnpath"tlh"$hymn_4"*.mid $date_folder
}
mkdir $date_folder
ls /run/media/user-0/church/Script\ resources/*/
regular
Here is the error:
cp: cannot stat '/run/media/user-0/church/Script\ resources/hymns/Lutheran\ hymnal/tlh123*.mid': No such file or directory
cp: cannot stat '/run/media/user-0/church/Script\ resources/Litergies/revisedPAGE5best*.mid': No such file or directory
cp: cannot stat '/run/media/user-0/church/Script\ resources/hymns/Lutheran\ hymnal/tlh125*.mid': No such file or directory
cp: cannot stat '/run/media/user-0/church/Script\ resources/Litergies/OFFERPG5*.mid': No such file or directory
cp: cannot stat '/run/media/user-0/church/Script\ resources/hymns/Lutheran\ hymnal/tlh124*.mid': No such file or directory
cp: cannot stat '/run/media/user-0/church/Script\ resources/Litergies/2collectbendpg14*.mid': No such file or directory
cp: cannot stat '/run/media/user-0/church/Script\ resources/hymns/Lutheran\ hymnal/tlh127*.mid': No such file or directory
​
https://redd.it/x7t7f8
@r_bash
So I'm writing a noscript for my church and I'm trying to use a wild card to copy some files from one directory to another. It's noteworthy to mention that it's on a flash drive. So when I run the command the the terminal it works just fine, but when I run it as a noscript it doesn't work. Here's an example, and I'll post the actual noscript if that would be helpful
Cp /run/media/username/church/noscript\ resources/ hymnal/hymns/tlh"$hymn1"*.mid /run/media/username/church/"$datefolder"
I should note that the wild card is to fill in the unknown parts of the file name, things like \_5 for 5 verses
Also both of the variables are defined already
I will probably be posting the noscript because I realize that will be helpful
Here is the noscript:
#!/bin/bash
user=$(pwd | cut -d / -f 4)
distro=$(distro | grep Fedora)
if [ $? != 0 ]
then
distro=/media/
else
distro=/run/media/
fi
fdrive="$distro$user/church"
hymnpath="$fdrive/Script\ resources/hymns/Lutheran\ hymnal/"
hymn_1=$1
hymn_2=$2
hymn_3=$3
hymn_4=$4
date=$5
date_folder="$fdrive/$date"
litpath="$fdrive/Script\ resources/Litergies/"
if [ "$1" == "-n" ]
then
read -p "Enter the first hymn " hymn_1
read -p "Enter the second hymn " hymn_2
read -p "Enter the third hymn " hymn_3
read -p "Enter the fourth hymn " hymn_4
read -p "Enter the date " date
fi
if [ "$1" == "-h" ]
then
echo "Syntax:"
echo "./hymnnoscript [hymn 1] [hymn 2] [hymn 3] [hymn 4] [date]"
echo "enter n for no parameters"
echo "enter h for help"
fi
regular (){
echo "regular"
cp "$hymnpath"tlh"$hymn_1"*.mid $date_folder
cp "$litpath"revisedPAGE5best*.mid $date_folder
cp "$hymnpath"tlh"$hymn_2"*.mid $date_folder
cp "$litpath"OFFERPG5*.mid $date_folder
cp "$hymnpath"tlh"$hymn_3"*.mid $date_folder
cp "$litpath"2collectbendpg14*.mid $date_folder
cp "$hymnpath"tlh"$hymn_4"*.mid $date_folder
}
mkdir $date_folder
ls /run/media/user-0/church/Script\ resources/*/
regular
Here is the error:
cp: cannot stat '/run/media/user-0/church/Script\ resources/hymns/Lutheran\ hymnal/tlh123*.mid': No such file or directory
cp: cannot stat '/run/media/user-0/church/Script\ resources/Litergies/revisedPAGE5best*.mid': No such file or directory
cp: cannot stat '/run/media/user-0/church/Script\ resources/hymns/Lutheran\ hymnal/tlh125*.mid': No such file or directory
cp: cannot stat '/run/media/user-0/church/Script\ resources/Litergies/OFFERPG5*.mid': No such file or directory
cp: cannot stat '/run/media/user-0/church/Script\ resources/hymns/Lutheran\ hymnal/tlh124*.mid': No such file or directory
cp: cannot stat '/run/media/user-0/church/Script\ resources/Litergies/2collectbendpg14*.mid': No such file or directory
cp: cannot stat '/run/media/user-0/church/Script\ resources/hymns/Lutheran\ hymnal/tlh127*.mid': No such file or directory
​
https://redd.it/x7t7f8
@r_bash
reddit
wild card works in shell but not in noscript
So I'm writing a noscript for my church and I'm trying to use a wild card to copy some files from one directory to another. It's noteworthy to...
If I can use bash on Windows, why bother using Linux at all?
I know this might be a noob question for you people, however, I think there are few other noob people like me wondering about this :)
I have been using Linux for 3 months now for work (we use an application that only works on Linux). My boss has taught me some Linux tricks and he is a long-time Linux user. All the things he showed me are just Bash commands.
It seemed like it was all about the command window and how powerful Linux is because of that only.
Then I asked, "Wait for a second, it turns out I can use bash on Windows too, then why Linux?"
Is it bash that makes Linux powerful, or something else?
https://redd.it/x89c1l
@r_bash
I know this might be a noob question for you people, however, I think there are few other noob people like me wondering about this :)
I have been using Linux for 3 months now for work (we use an application that only works on Linux). My boss has taught me some Linux tricks and he is a long-time Linux user. All the things he showed me are just Bash commands.
It seemed like it was all about the command window and how powerful Linux is because of that only.
Then I asked, "Wait for a second, it turns out I can use bash on Windows too, then why Linux?"
Is it bash that makes Linux powerful, or something else?
https://redd.it/x89c1l
@r_bash
reddit
If I can use bash on Windows, why bother using Linux at all?
I know this might be a noob question for you people, however, I think there are few other noob people like me wondering about this :) I have been...
Is This Geocode Script Broken?
Hi, I have an address string, ex: "2240 Saint Claude Avenue, New Orleans, LA 70117"
And have been searching for a noscript to convert this type of input into a pair of longitude and latitude coordinates. A noscript I found on [Webgears](https://www.webgears.com/blog/simple-noscript-to-get-latitude-and-longitude-from-an-address/) seems perfect/practical for that purpose and appears as follows
#!/bin/sh
url='http://www.mapquestapi.com/geocoding/v1/address?key='
args='&location='
key='YourMapQuestAPIKey'
converter="$url$key$args"
addr="$(echo $* | sed 's/ /+/g')" curl -s "$converter$addr" | \
cut -d\" -f117,119 | \
sed 's/[^0-9\.\,\-]//g;s/,$//' exit 0
Except it doesn't seem to work at all. Apparently searching for files etc instead of performing any function. The author says input should appear as such:
>./geocode.sh 8865 SE Bridge Road, Hobe Sound, FL
Does anyone have an idea of why this might be? I've tried to execute this on both Win10 and Ubuntu.
https://redd.it/x7ohgn
@r_bash
Hi, I have an address string, ex: "2240 Saint Claude Avenue, New Orleans, LA 70117"
And have been searching for a noscript to convert this type of input into a pair of longitude and latitude coordinates. A noscript I found on [Webgears](https://www.webgears.com/blog/simple-noscript-to-get-latitude-and-longitude-from-an-address/) seems perfect/practical for that purpose and appears as follows
#!/bin/sh
url='http://www.mapquestapi.com/geocoding/v1/address?key='
args='&location='
key='YourMapQuestAPIKey'
converter="$url$key$args"
addr="$(echo $* | sed 's/ /+/g')" curl -s "$converter$addr" | \
cut -d\" -f117,119 | \
sed 's/[^0-9\.\,\-]//g;s/,$//' exit 0
Except it doesn't seem to work at all. Apparently searching for files etc instead of performing any function. The author says input should appear as such:
>./geocode.sh 8865 SE Bridge Road, Hobe Sound, FL
Does anyone have an idea of why this might be? I've tried to execute this on both Win10 and Ubuntu.
https://redd.it/x7ohgn
@r_bash
Webgears
Simple Script to get Latitude and Longitude from an address
A Simple Script to get the Latitude and Longitude (forward Geocode values) from an address using the MapQuest API
Having Issues Comparing Strings
In part of my noscript I am trying to check if the string variable is equal to an uppercase B, but the check doesn't seem to return true with the variable is B. Does any part of this code look incorrect?
i = 0
if [ $f0 == `B` ];
then
((i++))
fi
Prior to the code snippet above, my code gets f0 by finding a file path and removing the all parts of the path and file extension except for the name - which is B (i.e. path/to/file/B.png gets turned into B)
https://redd.it/xd7a3p
@r_bash
In part of my noscript I am trying to check if the string variable is equal to an uppercase B, but the check doesn't seem to return true with the variable is B. Does any part of this code look incorrect?
i = 0
if [ $f0 == `B` ];
then
((i++))
fi
Prior to the code snippet above, my code gets f0 by finding a file path and removing the all parts of the path and file extension except for the name - which is B (i.e. path/to/file/B.png gets turned into B)
https://redd.it/xd7a3p
@r_bash
reddit
Having Issues Comparing Strings
In part of my noscript I am trying to check if the string variable is equal to an uppercase B, but the check doesn't seem to return true with the...
Download root-owned files via scp or rsync as a sudo user
How to download the file which requires
Note that this sudo-user is not configured to not require the password for
And
And download command may look like this
This command gives a "permission denied" error as
In order to download this file, sudo-user should be switched to root
So is there a way in
https://redd.it/xd7nml
@r_bash
How to download the file which requires
root permission from a remote server (via scp or rsync) as a sudo-user (non-interactive way)?Note that this sudo-user is not configured to not require the password for
sudo commands.And
sshpass is installed on both local and remote systems.And download command may look like this
sshpass -p {sudo-user-pass} scp {sudo-user}@{host}:/path/to/some/root/owned/file.tar.gz ./
This command gives a "permission denied" error as
file.tar.gz is owned by the root.In order to download this file, sudo-user should be switched to root
sudo -suSo is there a way in
scp or rsync where sudo-user can switch to root and download the root-owned files (non-interactively)?https://redd.it/xd7nml
@r_bash
reddit
Download root-owned files via scp or rsync as a sudo user
How to download the file which requires `root` permission from a remote server (via `scp` or `rsync`) as a sudo-user (non-interactive...
How to get raw output of network list?
i making a bash noscript to control my wifi via dmenu and i use this command to get list of available networks:
iwctl station wlan0 get-networks
i am really new in bash, so i'd like to chop-chop the table i get using this command)
i don't know where to start, i don't really understand tools like cut/grep/awk( pls help
i want to output to be just list of names of this networks
​
sample:
Available networks
--------------------------------------------------------------------------------
Network name Security Signal
--------------------------------------------------------------------------------
> lll psk
eee psk
aaa psk
sample output
lll
eee
aaa
​
https://redd.it/xd9enh
@r_bash
i making a bash noscript to control my wifi via dmenu and i use this command to get list of available networks:
iwctl station wlan0 get-networks
i am really new in bash, so i'd like to chop-chop the table i get using this command)
i don't know where to start, i don't really understand tools like cut/grep/awk( pls help
i want to output to be just list of names of this networks
​
sample:
Available networks
--------------------------------------------------------------------------------
Network name Security Signal
--------------------------------------------------------------------------------
> lll psk
eee psk
aaa psk
sample output
lll
eee
aaa
​
https://redd.it/xd9enh
@r_bash
reddit
How to get raw output of network list?
i making a bash noscript to control my wifi via dmenu and i use this command to get list of available networks: iwctl station wlan0...
Run commands in same Time
So I have multiple command that I want to run it in the same time what is best options ?
https://redd.it/xd760p
@r_bash
So I have multiple command that I want to run it in the same time what is best options ?
https://redd.it/xd760p
@r_bash
Help me figure out the right way to format this curl command? ("@" in URL password)
Edit: Solved using curl -u admin:p@ssword -H "Range: depth=1" -H "Accept: application/json" --digest "http://10.0.0.1/restapi/"
​
I'm pulling my hair out on this one and everything I find says to just put the URL in quotes and it'll be good. It is not good.
​
>curl -H "Range: depth=1" -H "Accept: application/json" \\
>
>\--digest "http://admin:p@ssword@10.0.0.1/restapi/"
The "@" in "p@ssword" is causing this command to be interpreted as the hostname of the base URL being "ssword@10.0.0.1", which is clearly not the intent. I cannot, for the life of me, figure out how to escape this character.
Thanks
https://redd.it/x7pd11
@r_bash
Edit: Solved using curl -u admin:p@ssword -H "Range: depth=1" -H "Accept: application/json" --digest "http://10.0.0.1/restapi/"
​
I'm pulling my hair out on this one and everything I find says to just put the URL in quotes and it'll be good. It is not good.
​
>curl -H "Range: depth=1" -H "Accept: application/json" \\
>
>\--digest "http://admin:p@ssword@10.0.0.1/restapi/"
The "@" in "p@ssword" is causing this command to be interpreted as the hostname of the base URL being "ssword@10.0.0.1", which is clearly not the intent. I cannot, for the life of me, figure out how to escape this character.
Thanks
https://redd.it/x7pd11
@r_bash
reddit
Help me figure out the right way to format this curl command? ("@"...
Edit: Solved using curl -u admin:p@ssword -H "Range: depth=1" -H "Accept: application/json" --digest "http://10.0.0.1/restapi/" I'm...
Two first lines of csv files using bash + general explanation
I want to find the first two lines of a csv file using bash in a jupyter notebook.
This is my code for the moment, what I should put in the X in order to obtain the first two lines of the csv file?
​
%%sh
head -X data/earthquakes.csv
​
I'm learning a bit of how to using bash with jupyter notebooks, in fact in don't understand a why is bash used in data science. Could somebody also explain this to me and why %%sh does not work in windows?
​
Thank you very much!
https://redd.it/x7e8a8
@r_bash
I want to find the first two lines of a csv file using bash in a jupyter notebook.
This is my code for the moment, what I should put in the X in order to obtain the first two lines of the csv file?
​
%%sh
head -X data/earthquakes.csv
​
I'm learning a bit of how to using bash with jupyter notebooks, in fact in don't understand a why is bash used in data science. Could somebody also explain this to me and why %%sh does not work in windows?
​
Thank you very much!
https://redd.it/x7e8a8
@r_bash
reddit
Two first lines of csv files using bash + general explanation
I want to find the first two lines of a csv file using bash in a jupyter notebook. This is my code for the moment, what I should put in the X in...
Not having success moving a file at the end of my noscript after transcoding completes
Hello! I have a noscript that I borrowed to help me post process recordings from Plex to A) remove commercials with an app called Comcut and B) transcode it with Handbrake CLI.
The problem I am running into is that once the noscript removes the commercials and then transcodes the file, it is not successfully replacing the newly transcoded file at the end of the noscript...
I even tried to embed the users password and run the "mv -f" command with sudo, but that did not seem to work either. Here is the noscript, and the command to move the newly transcoded file is the 7th line to the end, marketed with "# \*\*\*\* OVERWRITE HERE \*\*\*\*"
Any suggestions would be greatly appreciated! Thank you!
#! /bin/bash
#
# Plex DVR Postprocessing
# Version 0.0.1
# twitter.com/thatvirtualboy
# www.thatvirtualboy.com
#
# FIRST, RUN COMCUT TO REMOVE COMMERCIALS, THEN TRANSCODE AND COMPRESS
lockFile='/tmp/dvrProcessing.lock'
inFile="$1"
tmpFile="$1.mp4"
dvrPostLog='/tmp/dvrProcessing.log'
time=`date '+%Y-%m-%d %H:%M:%S'`
handbrake=/opt/homebrew/Cellar/handbrake/1.5.1_1/bin/HandBrakeCLI
cut=/opt/homebrew/Cellar/comskip/bin/comcut
echo "'$time' Plex DVR Postprocessing noscript started" | tee $dvrPostLog
# Check if post processing is already running
while [ -f $lockFile ]
do
echo "'$time' $lockFile' exists, sleeping processing of '$inFile'" | tee -a $dvrPostLog
sleep 10
done
# Create lock file to prevent other post-processing from running simultaneously
echo "'$time' Creating lock file for processing '$inFile'" | tee -a $dvrPostLog
touch $lockFile
# Run comcut
echo "'$time' Comcut started on '$inFile'" | tee -a $dvrPostLog
$cut "$inFile"
# Encode file to MP4 with handbrake-cli
echo "'$time' Transcoding started on '$inFile'" | tee -a $dvrPostLog
$handbrake -i "$inFile" -o "$tmpFile" --preset="Apple 1080p30 Surround" --encoder-preset="veryfast" -O
# **** OVERWRITE HERE ****
# Overwrite original ts file with the transcoded file
echo "'$time' File '$tmpFile' move started" | tee -a $dvrPostLog
echo "REDACTED" | sudo -S mv -f "$tmpFile" "$inFile"
#Remove lock file
echo "'$time' All done! Removing lock for '$inFile'" | tee -a $dvrPostLog
rm $lockFile
exit 0
https://redd.it/x7dtah
@r_bash
Hello! I have a noscript that I borrowed to help me post process recordings from Plex to A) remove commercials with an app called Comcut and B) transcode it with Handbrake CLI.
The problem I am running into is that once the noscript removes the commercials and then transcodes the file, it is not successfully replacing the newly transcoded file at the end of the noscript...
I even tried to embed the users password and run the "mv -f" command with sudo, but that did not seem to work either. Here is the noscript, and the command to move the newly transcoded file is the 7th line to the end, marketed with "# \*\*\*\* OVERWRITE HERE \*\*\*\*"
Any suggestions would be greatly appreciated! Thank you!
#! /bin/bash
#
# Plex DVR Postprocessing
# Version 0.0.1
# twitter.com/thatvirtualboy
# www.thatvirtualboy.com
#
# FIRST, RUN COMCUT TO REMOVE COMMERCIALS, THEN TRANSCODE AND COMPRESS
lockFile='/tmp/dvrProcessing.lock'
inFile="$1"
tmpFile="$1.mp4"
dvrPostLog='/tmp/dvrProcessing.log'
time=`date '+%Y-%m-%d %H:%M:%S'`
handbrake=/opt/homebrew/Cellar/handbrake/1.5.1_1/bin/HandBrakeCLI
cut=/opt/homebrew/Cellar/comskip/bin/comcut
echo "'$time' Plex DVR Postprocessing noscript started" | tee $dvrPostLog
# Check if post processing is already running
while [ -f $lockFile ]
do
echo "'$time' $lockFile' exists, sleeping processing of '$inFile'" | tee -a $dvrPostLog
sleep 10
done
# Create lock file to prevent other post-processing from running simultaneously
echo "'$time' Creating lock file for processing '$inFile'" | tee -a $dvrPostLog
touch $lockFile
# Run comcut
echo "'$time' Comcut started on '$inFile'" | tee -a $dvrPostLog
$cut "$inFile"
# Encode file to MP4 with handbrake-cli
echo "'$time' Transcoding started on '$inFile'" | tee -a $dvrPostLog
$handbrake -i "$inFile" -o "$tmpFile" --preset="Apple 1080p30 Surround" --encoder-preset="veryfast" -O
# **** OVERWRITE HERE ****
# Overwrite original ts file with the transcoded file
echo "'$time' File '$tmpFile' move started" | tee -a $dvrPostLog
echo "REDACTED" | sudo -S mv -f "$tmpFile" "$inFile"
#Remove lock file
echo "'$time' All done! Removing lock for '$inFile'" | tee -a $dvrPostLog
rm $lockFile
exit 0
https://redd.it/x7dtah
@r_bash
How to use sed command to replace values in a list & dictionary in a yaml file
I want to change the value of the seeds here.
seed_provider:
\- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
\- seeds: "127.0.0.1:7000"
And want to change value of this :
data_file_directories:
\- /etc/test/config.yaml
https://redd.it/x7176q
@r_bash
I want to change the value of the seeds here.
seed_provider:
\- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
\- seeds: "127.0.0.1:7000"
And want to change value of this :
data_file_directories:
\- /etc/test/config.yaml
https://redd.it/x7176q
@r_bash
reddit
How to use sed command to replace values in a list & dictionary in...
I want to change the value of the seeds here. seed\_provider: \- class\_name:...
Parameter Expansion for building cmd in for loop
Regarding building the source and target variables why does this work:
declare -a elemens=(
# hostname user filetotransfer file_suffix
"hostname1 username1 /path/to/file/on/remote suffix1"
"hostname2 username2 /path/to/file/on/remote suffix2"
)
for elem in "${elemens[@]}"
do
read -a strarr <<< "$elem"
source="${strarr[1]}@${strarr[0]}.hostname:${strarr[2]}"
target="./filename_${strarr[3]}"
scp -p $source $target
done
...and not just building them in the same line as scp as so:
scp -p "${strarr[1]}@${strarr[0]}.hostname:${strarr[2]} ./filename_${strarr[3]}"
With the later I just get the scp help message.
I realize it has something to do with variable expansion, but I do not understand why.
https://redd.it/x78gny
@r_bash
Regarding building the source and target variables why does this work:
declare -a elemens=(
# hostname user filetotransfer file_suffix
"hostname1 username1 /path/to/file/on/remote suffix1"
"hostname2 username2 /path/to/file/on/remote suffix2"
)
for elem in "${elemens[@]}"
do
read -a strarr <<< "$elem"
source="${strarr[1]}@${strarr[0]}.hostname:${strarr[2]}"
target="./filename_${strarr[3]}"
scp -p $source $target
done
...and not just building them in the same line as scp as so:
scp -p "${strarr[1]}@${strarr[0]}.hostname:${strarr[2]} ./filename_${strarr[3]}"
With the later I just get the scp help message.
I realize it has something to do with variable expansion, but I do not understand why.
https://redd.it/x78gny
@r_bash
reddit
Parameter Expansion for building cmd in for loop
Regarding building the source and target variables why does this work: declare -a elemens=( # hostname user filetotransfer...
Count totals and correlate to $1
Hi all, I'm stumped by a problem and would love if I could get some help. I have a txt with lines and lines of data like this:
xxx.xxx.xx.xxx ftp ssh
yyy.yyy.yy.yyy ssh
zzz.zzz.zz.zzz smtp ftp
I need to count and correlate each service to the IP address, so the output would be similar to:
ftp count: 2
xxx.xxx.xx.xxx
zzz.zzz.zz.zzz
ssh count: 2
xxx.xxx.xx.xxx
yyy.yyy.yy.yyy
smtp count: 1
zzz.zzz.zz.zzz
I've been trying tons of stuff with
Anything you could give me to point me in the right direction would be awesome! Thanks!
https://redd.it/x6l7t5
@r_bash
Hi all, I'm stumped by a problem and would love if I could get some help. I have a txt with lines and lines of data like this:
xxx.xxx.xx.xxx ftp ssh
yyy.yyy.yy.yyy ssh
zzz.zzz.zz.zzz smtp ftp
I need to count and correlate each service to the IP address, so the output would be similar to:
ftp count: 2
xxx.xxx.xx.xxx
zzz.zzz.zz.zzz
ssh count: 2
xxx.xxx.xx.xxx
yyy.yyy.yy.yyy
smtp count: 1
zzz.zzz.zz.zzz
I've been trying tons of stuff with
awk but I'm getting nowhere and am afraid I'm deep down a rabbit hole. I think I need someone else's perspective on this one.Anything you could give me to point me in the right direction would be awesome! Thanks!
https://redd.it/x6l7t5
@r_bash
reddit
Count totals and correlate to $1
Hi all, I'm stumped by a problem and would love if I could get some help. I have a txt with lines and lines of data like this: xxx.xxx.xx.xxx...
Grepping for whitespace and double quotes as part of an if-then statement
I am attempting to create a noscript that will eventually run as a cron to check a conf file, and if it does not have a critical setting within it, to execute another noscript that regenerates the conf file.
The critical setting is:
I can get the grep on my bash prompt just fine:
user@host ~# grep --color -h 'SecRuleEngine "On"' /path/to/conf-file.conf
SecRuleEngine "On"
And what I was wanting to do was to have a simple 1 for yes, 0 for no, like:
user@host ~# grep -c -h 'SecRuleEngine "On"' /path/to/conf-file.conf
1
Which I was hoping to feed into an if then statement in the noscript to test it, like:
if grep -c -h 'SecRuleEngine "On"' /path/to/conf-file.conf = "1" ; then
echo "all good"
fi
But on the line that starts with "if" I get:
: too many arguments
What I was hoping to do was get the noscript to see the grep as intended, then reverse it by putting a `!` after the `if` and then issuing the command to run the configuration noscript. What corrections do I need to make to my syntax?
[https://redd.it/xdmqhu
@r_bash
I am attempting to create a noscript that will eventually run as a cron to check a conf file, and if it does not have a critical setting within it, to execute another noscript that regenerates the conf file.
The critical setting is:
SecRuleEngine "On"I can get the grep on my bash prompt just fine:
user@host ~# grep --color -h 'SecRuleEngine "On"' /path/to/conf-file.conf
SecRuleEngine "On"
And what I was wanting to do was to have a simple 1 for yes, 0 for no, like:
user@host ~# grep -c -h 'SecRuleEngine "On"' /path/to/conf-file.conf
1
Which I was hoping to feed into an if then statement in the noscript to test it, like:
if grep -c -h 'SecRuleEngine "On"' /path/to/conf-file.conf = "1" ; then
echo "all good"
fi
But on the line that starts with "if" I get:
: too many arguments
What I was hoping to do was get the noscript to see the grep as intended, then reverse it by putting a `!` after the `if` and then issuing the command to run the configuration noscript. What corrections do I need to make to my syntax?
[https://redd.it/xdmqhu
@r_bash
reddit
Grepping for whitespace and double quotes as part of an if-then...
I am attempting to create a noscript that will eventually run as a cron to check a conf file, and if it does not have a critical setting within it,...
How do you export a mongo db into a JSON?
mongoexport --uri="mongodb://localhost:27017/" --username admin --password root --authenticationDatabase "admin" --db products --collection shoes --out dump.json
What's wrong with this command?
2022-09-02T18:00:24.492-0400 could not connect to server: connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
There shouldn't be any authentication. Looking inside Studio 3T, I see Authentication Mode: None.
https://redd.it/x6zz1k
@r_bash
mongoexport --uri="mongodb://localhost:27017/" --username admin --password root --authenticationDatabase "admin" --db products --collection shoes --out dump.json
What's wrong with this command?
2022-09-02T18:00:24.492-0400 could not connect to server: connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
There shouldn't be any authentication. Looking inside Studio 3T, I see Authentication Mode: None.
https://redd.it/x6zz1k
@r_bash
reddit
How do you export a mongo db into a JSON?
mongoexport --uri="mongodb://localhost:27017/" --username admin --password root --authenticationDatabase "admin" --db products --collection shoes...
Parsing a csv with Unix time and an integer on each line.
Hello,
My csv looks something like this:
timestamp,Value
1662353808788,5
1662354108786,12
.
.
.
Hundreds of lines, ordered by time.
My goal is for the noscript to return the biggest value recorded in the last 24hours and ideally if given a parameter should be also able to return the biggest value for a specific day. I imagined something like placing a 0 as a parameter for today, 1 for the day before, 2 for the day before that, but not set on that.
Any help appreciated, even if you could just tell me what I will need to accomplish it, some algorithm, pseudo code, commands I should look at. Never worked with unix time before.
Thank you
https://redd.it/x6cacz
@r_bash
Hello,
My csv looks something like this:
timestamp,Value
1662353808788,5
1662354108786,12
.
.
.
Hundreds of lines, ordered by time.
My goal is for the noscript to return the biggest value recorded in the last 24hours and ideally if given a parameter should be also able to return the biggest value for a specific day. I imagined something like placing a 0 as a parameter for today, 1 for the day before, 2 for the day before that, but not set on that.
Any help appreciated, even if you could just tell me what I will need to accomplish it, some algorithm, pseudo code, commands I should look at. Never worked with unix time before.
Thank you
https://redd.it/x6cacz
@r_bash
reddit
Parsing a csv with Unix time and an integer on each line.
Hello, My csv looks something like this: timestamp,Value 1662353808788,5 1662354108786,12 . . . Hundreds of lines, ordered by time. My...
printf vs echo - Showing last command
Hey all!
I've been writing a pretty basic noscript to take care of some file backup tasks for me. I'm trying to be good by commenting and producing log output. I'm having an issue getting the last command run to display in a function I've declared.
Here are the function declarations:
# Declare conditional logging
function success()
{
echo -e ${date} "$? ran successfully!" >> ${dockerDir}/shared/archive.log
}
function fail()
{
echo -e ${date} "\xF0\x9F\x92\x80" "$? failed..." "\xF0\x9F\x92\x80" >> ${dockerDir}/shared/archive.log
}
Pretty straightforward, right?
Here is one example of calling the functions with nested if statements:
#Tar 'em up
tar --create --bzip2 --file ${dockerDir}/shared/${archiveTar} ${dockerDir}${bookstack}*bookstackFiles.tar ${dockerDir}${bookstack_db}*bookstack_db.sql
if [ $? -eq 0 ]; then
success
else
fail
if [[ -e ${dockerDir}${bookstack}*bookstackFiles.tar || ${dockerDir}${bookstack_db}*bookstack_db.sql ]]
then
rm ${dockerDir}${bookstack}*bookstackFiles.tar
rm ${dockerDir}${bookstack}*bookstack_db.sql
EXIT
fi
fi
Now, here's the output from archive.log:
2022/09/13 20:54:29 0 ran successfully!
✅ 2022/09/13 20:54:29 \ Bookstack files tarred and bzipped successfully! 202209132054-bookstackArchive.tar.bz2 ✅
2022/09/13 20:54:29 0 ran successfully!
✅ 2022/09/13 20:54:29 \ Bookstack files encrypted successfully! 202209132054-bookstackArchive.tar.bz2.gpg ✅
The issue I'm trying to figure out is why it's not showing me in the log the last command that was run. In the first line, it should show something like "tar ran successfully!" (I'm not positive if it's going to include the command args or not). The third line should show something like "gpg ran successfully!".
Instead I'm just getting "0". I've tried different permutations of this using printf, echo -e, echo. I've tried different ways of referencing the previous command like $?, !:0, referencing a different variable I declare earlier in a trap statement.
Nothing is giving me the expected output. Thoughts?
https://redd.it/xds4z6
@r_bash
Hey all!
I've been writing a pretty basic noscript to take care of some file backup tasks for me. I'm trying to be good by commenting and producing log output. I'm having an issue getting the last command run to display in a function I've declared.
Here are the function declarations:
# Declare conditional logging
function success()
{
echo -e ${date} "$? ran successfully!" >> ${dockerDir}/shared/archive.log
}
function fail()
{
echo -e ${date} "\xF0\x9F\x92\x80" "$? failed..." "\xF0\x9F\x92\x80" >> ${dockerDir}/shared/archive.log
}
Pretty straightforward, right?
Here is one example of calling the functions with nested if statements:
#Tar 'em up
tar --create --bzip2 --file ${dockerDir}/shared/${archiveTar} ${dockerDir}${bookstack}*bookstackFiles.tar ${dockerDir}${bookstack_db}*bookstack_db.sql
if [ $? -eq 0 ]; then
success
else
fail
if [[ -e ${dockerDir}${bookstack}*bookstackFiles.tar || ${dockerDir}${bookstack_db}*bookstack_db.sql ]]
then
rm ${dockerDir}${bookstack}*bookstackFiles.tar
rm ${dockerDir}${bookstack}*bookstack_db.sql
EXIT
fi
fi
Now, here's the output from archive.log:
2022/09/13 20:54:29 0 ran successfully!
✅ 2022/09/13 20:54:29 \ Bookstack files tarred and bzipped successfully! 202209132054-bookstackArchive.tar.bz2 ✅
2022/09/13 20:54:29 0 ran successfully!
✅ 2022/09/13 20:54:29 \ Bookstack files encrypted successfully! 202209132054-bookstackArchive.tar.bz2.gpg ✅
The issue I'm trying to figure out is why it's not showing me in the log the last command that was run. In the first line, it should show something like "tar ran successfully!" (I'm not positive if it's going to include the command args or not). The third line should show something like "gpg ran successfully!".
Instead I'm just getting "0". I've tried different permutations of this using printf, echo -e, echo. I've tried different ways of referencing the previous command like $?, !:0, referencing a different variable I declare earlier in a trap statement.
Nothing is giving me the expected output. Thoughts?
https://redd.it/xds4z6
@r_bash
reddit
printf vs echo - Showing last command
Hey all! I've been writing a pretty basic noscript to take care of some file backup tasks for me. I'm trying to be good by commenting and producing...
[OC] shortbashpwd: prompt for bash with abbreviated directory names like in fishgi
https://github.com/NikitaIvanovV/shortbashpwd
https://redd.it/x60spv
@r_bash
https://github.com/NikitaIvanovV/shortbashpwd
https://redd.it/x60spv
@r_bash
GitHub
GitHub - NikitaIvanovV/shortbashpwd: Shorter working directory in prompt like in fish shell
Shorter working directory in prompt like in fish shell - GitHub - NikitaIvanovV/shortbashpwd: Shorter working directory in prompt like in fish shell
What does this command do in .zsh file
I am using the docker-compose plugin in zsh and want to use docker compose v2 commands. so when exploring the plugins I found this line
can someone explain what does this do?
https://redd.it/xdxqvd
@r_bash
I am using the docker-compose plugin in zsh and want to use docker compose v2 commands. so when exploring the plugins I found this line
(( ${+commands[docker-compose]} )) && dccmd='docker-compose' || dccmd='docker compose'can someone explain what does this do?
https://redd.it/xdxqvd
@r_bash
reddit
What does this command do in .zsh file
I am using the docker-compose plugin in zsh and want to use docker compose v2 commands. so when exploring the plugins I found this line `((...