r_bash – Telegram
Check if a string match given name together with a arimetic expression in one line.

I have this Script which compares numbers.
to see if they are between or equal to a set of Numbers.

And in the end of the noscript i would also like to
add variable b to compare to see if variable b
is equal to the "hello" string

/tmp/numbers.txt

9 #c

2 #d

19 #body

2022-10-18 23:17 #time1

Hello #hello string which i want to compare if it exists.

exec 4</tmp/numbers.txt
IFS= read -ru4 body #body
IFS= read -ru4 c
IFS= read -ru4 d
IFS= read -ru4 time1
IFS= read -ru4 b
exec 4<&-

if (( c >= 7 && c<= 10 && d >= 0 && d <= 3 && body >= 18 && body <= 20 && b == "Hello")); then
echo "Hello parameter exists"
fi


I know that if you want to compare strings you have to use the []

But what if i want for conveince to compare it inside the (()) expression.

https://redd.it/y7jgsu
@r_bash
Help to nodify bash noscript

\#!/bin/bash

riclist=(

''

)

\#Message depends on riclist ID

declare -A rcmsg

rcmsg[\]=''

\# Raw log filename

RAWSTAMP="$(date '+%Y_%m_%d')"

RAWLOG="raw_$RAWSTAMP.log"

while IFS='' read -r line; do

\# check for all strings in $riclist

# Raw logging

echo "\\date '+%Y-%m-%d %T'` $line" >> $RAWLOG`

double_filter="$double_filter"

double_filter2="$double_filter2"

double_filter3="$double_filter3"

double_filter4="$double_filter4"

count=0

while [ "${riclist[count\]}" != "" \]; do

if [ "${line/${riclist[count]}}" != "$line" ] ; then # if $line minus first apperence of $riclist is diffrent from $line

if [ "${line##*Alpha: }" != "$double_filter4" ] ; then double_filter4="$double_filter3"

if [ "${line##*Alpha: }" != "$double_filter3" ] ; then double_filter3="$double_filter2"

if [ "${line##*Alpha: }" != "$double_filter2" ] ; then double_filter2="$double_filter"

if [ "${line##*Alpha: }" != "$double_filter" ] ; then

&#x200B;

TIMESTAMP="$(date '+%Y-%m-%d %T')"

TIMESTAMP2="$(date '+%Y-%m-%d %T')"

id=${riclist[count\]}

RAW="${line##*Alpha: }"

RAW2="${line##*Alpha: }"

NOTNUL="$( echo "$RAW" | sed --regexp-extended 's/<(CR|NUL)>//g; s/<(LF|SYN)>/\\ /g' )"

NOTNUL2="$( echo "$RAW2" | sed --regexp-extended 's/<(CR|NUL)>//g; s/<(LF|SYN)>/\\ /g' )"

ADDBOT="$NOTNUL - ${rcmsg[$id\]}"

ADDBOT2="$NOTNUL2 - ${rcmsg[$id\]}"

echo "$TIMESTAMP2 $ADDBOT2" | mail -s "$TIMESTAMP $ADDBOT" mail@mail

&#x200B;

printf -v filename "rtj_\\date +%Y_%m_%d`.log"`

echo "\\date '+%Y-%m-%d %T'` ${line##*Alpha: }" >> $filename`

double_filter="${line##*Alpha: }"

fi

fi

fi

fi

fi

count=$(( $count + 1 ))

done

done

The best solution to not send an email if ${line##*Alpha: } contain specific words in this noscript. How would you do it?

https://redd.it/y7t4qb
@r_bash
remove the character before a specific string or append contents of a file to another file without adding a newline character after?

im trying to write a noscript to auto update an avahi service whenever a program on another pc changes the port it is listening on and restart the daemon - and i'm almost there. i have gotten batch files monitoring and updating a file with the current ports on the windows pc, i network shared the file with the ports

#!/bin.sh
echo "<?xml version=\\"1.0\\" standalone=\\'no\\'?><!--\*-nxml-\*-->\n<!DOCTYPE service-group SYSTEM \\"avahi-service.dtd\\">" > /etc/avahi/services/oculus.service
echo -n "<service-group>\n<name replace-wildcards=\"yes\">oculus</name>\n<service>\n<service protocol=\"ipv4\">\n<type>_oculusal_sp._tcp</type>\n<port>" >> /etc/avahi/services/oculus.service
tail --lines 1 /mnt/win_share/port.txt | cut -d\n -f1 >> /etc/avahi/services/oculus.service
echo -n "</port>\n<host-name>vr-pc.local</host-name>\n</service>\n</service-group>\n" >> /etc/avahi/services/oculus.service
service avahi-daemon restart

outputs the following

<?xml version="1.0" standalone=\\'no\\'?><!--\*-nxml-\*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">oculus</name>
<service>
<service protocol="ipv4">
<type>_oculusal_sp._tcp</type>
<port>56199
</port>
<host-name>vr-pc.local</host-name>
</service>
</service-group>

i need it to say <port>56199</port>

instead of

<port>56199

</port>


&#x200B;

ive tried a bunch of different ways to do it and i just cant figure it out. someone help?

https://redd.it/y7uq18
@r_bash
Send signal to itself

My noscript:

trap "rm -rf '$CACHE'; exit 1" 15
my_program || kill -15 "$$"

Does this work? I want to exit my noscript if my program fails, but also delete the temp directory before the noscript exits.

Also I am talking about posix dash noscripting and not bash noscripting.

Thank you

https://redd.it/y7xqc4
@r_bash
Script for volup/voldown/mute

Hi everyone

I have error with my volup/voldown/mute noscript so any help is welcome

inc='10'
activesink=`pacmd list-sinks |awk '/* index:/{print $3}'`

case "$1" in
up)
exec pactl set-sink-volume ${active
sink} +${inc}%
;;
down)
exec pactl set-sink-volume ${activesink} -${inc}%
;;
mute)
exec pactl set-sink-volume ${active
sink} toggle%
;;
esac

When run i get these errors

: not found: 3:
pavolume.sh: 4: Syntax error: word unexpected (expecting "in")


Thanks in advanced

https://redd.it/y89mjb
@r_bash
Learning noscripting, but code seems to work depending on how I call it

So as the noscript suggests, I am trying to learn noscripting with BASH. I find that when I run my noscript as:

'bash iftesting.sh'

\- it runs perfectly.

However, when I run it as:

'./iftesting.sh'

\- it results in the error 'iftesting.sh: 6: [[: not found

Is running it from './' wrong or different in some way? Again, this is all new to me, thanks!

https://redd.it/y8cf2j
@r_bash
Access items in JSON using Bash

I have a json structure similar to the following (created using the AWS CLI)



[
{
"Instance":"10.120.100.234",
"Name":"Server A"
}
,

{
"Instance":"10.120.101.210",
"Name":"Server B"
}
,

{
"Instance":"10.120.100.175",
"Name":"Server C"
}

]

If I have this in a variable ($OUTPUT, for example), how can I access each item in turn? I need to run a command on each server in turn, then write a line with the server name and instance IP (and return status of the command) on it.


I'm working in bash, jq is available, and I could (if I needed to) write/run this in python also; whichever gives me the quickest way forward.

https://redd.it/y8bih3
@r_bash
Timeout command not killing Python noscript

Hey there,

I have a Python noscript that I need to kill after it's been running for 10 seconds.

I've tried both of the following commands but it doesn't kill the process for some reason I can't diagnose:

timeout 10 python example.py
timeout --kill-after=10 10 example.py

Thanks for your help.

https://redd.it/y8osfi
@r_bash
getting the month number by the month name

Hello, folks. I need your help. Is there a native method for getting the month number by the month name? for example: <some command> May. Answer 5.

https://redd.it/y8pnes
@r_bash
Newbie question. How to extract the first columm of a line containing a range of values?

Im trying to grep or awk the first word of each line that contains value between 1000-6000

I managed to extract the value it self or the first value of every columm regardless of value, but can't manage to do both at once.

https://redd.it/y8yibd
@r_bash
Can you help me with my homework?

I've just started uni and I don't understand noscripting at all. The lectures aren't really good so I only know the basics from online.

The homework is:

&#x200B;

There is an input.txt file I have to read from, it looks like this:

&#x200B;

James Smith, Mon 1 3 4 5, Tu 1 2 3, Wed, Thur 3 4 5 6 7, Fri 1 2 3 4

Larry Wheels, Mon 1 3 5, Tu 1 2 3 5, Wed 1 2, Thur 3 4 5 7, Fri 1 2 3

...

(Teachers names, Days and their classes)

&#x200B;

a) Get the name of the teachers who don't have classes on Wednesday, if everybody has then print "None"

b) Print the name of the Teachers and how many classes do they have.

c) Read a day from the terminal and print the names of the teachers who don't have first classes.

&#x200B;

I would really appreciate your help. I will learn a lot from this and I think I will be able to do the next homework on my own.

https://redd.it/y95rog
@r_bash
This media is not supported in your browser
VIEW IN TELEGRAM
How do i get history suggestion like this in my bash is there any plugin for oh my zsh. Not autocomplete but history suggestion.
https://redd.it/y9gja2
@r_bash
sed replace non-ascii chars in substrings, but only between double quotes

Hello,

&#x200B;

i have a lot of text files (*.cue files) which contain the following line among others:

FILE "hello - world..!!.flac" WAVE

What i want:

FILE "hello_-_world____.flac" WAVE

(replace all dots except last would be the luxus version, but not necessary)

&#x200B;

The problem:

I can't figure it out to get sed to replace every non ascii [\^A-Za-z0-9-_.\] by a underscore. What i found until now:

sed '/FILE /s/".*"/"_"/g' test.cue

This edits only the correct line (i want it that way) but it replaces the whole string hello - world !! by only one underscore. What im doing wrong ?

&#x200B;

https://redd.it/y9np6x
@r_bash
Help

Joined a course a bit late. Would really appreciate if someone could help me with some simple assignments of bash noscripts that I have to submit. DM me if you're kind enough. Would take hardly 5-10 mins if you're well versed. Thanks.

https://redd.it/y9opbc
@r_bash
How can I bind output to variable?

For example if I run

awk -F: '{ if ($3 >= 1000 && $3 <= 60000) { print $1 } }' /etc/passwd | nl

And it gives me a numbered list of users, next I want to put them into a variable so the user can choose which one by inputting a number.

Any help would be appricated!

https://redd.it/y9p9mw
@r_bash
Problem with sed when adding to end of line

Hello all,

I'm trying to add a string to the end of a line here (it's for a csv import):

address,denoscription,dnsname,status

192.168.62.1/24,Console aro,con-aro.e.retobu.com, 192.168.62.4/24,Console ski,con-ski.e.retobu.com,

I'm trying to add "active" to every line for the status field. I tried it like this:

sed 's/$/active/'

At least thats what the internet told me to do. But when I do this, this is the result:

actives,denoscription,dns
name,status
active8.62.1/24,Console aro,con-aro.e.retobu.com,
active8.62.4/24,Console ski,con-ski.e.retobu.com,

I don't get what I'm doing wrong...

https://redd.it/y9t1zk
@r_bash
variable value to create new variable

I'm new to bash and wondering whether it is possible to have the value stored in a variable to create another variable?

myvar=helloworld1

The value of myvar will be a dynamic, meaning that it will output helloworld1, or helloworld2 or helloworld3.

How can i achieve making the value of myvar as the name of a new variable?

https://redd.it/y9qo1l
@r_bash
increase the size of command history

I think this is a simple configuration using two environment variables. But, for some reason my system is honoring these variables. Does anyone have an idea why could this be?

$ echo $HISTSIZE 
10000
$ echo $HISTFILESIZE
20000
$ wc $HISTFILE
503 1549 14025 /home/someuser/.bash_history


thank you

https://redd.it/ya0hkh
@r_bash
Good Beginner Manual Recommendations?

I’m fairly new to bash noscripting and i’m currently working on a program for my bioinformatics class. I feel like my notes aren’t sufficient though for efficacy and I was wondering if anyone recommends an updated beginner manual that they liked.

Thanks :)

https://redd.it/yaekmr
@r_bash