r_bash – Telegram
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
Syntax error near unexpected token 'done'

Im sure its something embarrassingly simple, but i am new to this and ive been trying to get this to run for like an hour now. Can anyone help me understand why its not expecting done? This is on a chroot installation of fedora 35 on android 12 if it matters.

#!/usr/bin/bash
port=null
while :
do
wget -O ftp://192.168.1.3/port.txt
if $port == $(tail --lines 1 /home/port.txt | tr -d \\r);
then
echo "skipping service update and avahi restart"
cat >/dev/null << SKIPRESTART
else
echo "updating port, restarting avahi"
$port=$(tail --lines 1 /home/port.txt | tr -d \\r)
cat > /etc/avahi/services/oculus.service <<EOF
<?xml version="1.0" standalone='no'?>
<!--\*-nxml-\*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">oculus</name>
<service protocol="ipv4">
<type>_oculusal_sp._tcp</type>
<port>${port}</port>
<host-name>vr-pc.local</host-name>
</service>
</service-group>
EOF

servicectl restart avahi-daemon
fi
SKIPRESTART
sleep 10
done

Help plz

Edit: duh. When it skips to skiprestart the if is never closed nevermind

https://redd.it/yaf9zs
@r_bash
How to extract volume of active sink

Hi everyone

Trying to extract current volume of active sink. I use this to get active sink name

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

but now i don't know how to extract volume of active sink.

This is pactl list sinks output

Sink #0
State: SUSPENDED
Name: alsa_output.pci-0000_00_1f.3.analog-stereo
Denoscription: Built-in Audio Analog Stereo
Driver: module-alsa-card.c
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 6
Mute: no
Volume: front-left: 26071 / 40% / -24.02 dB, front-right: 26071 / 40% / -24.02 dB
balance 0.00
Base Volume: 65536 / 100% / 0.00 dB
Monitor Source: alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
Latency: 0 usec, configured 0 usec
Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY
Properties:
alsa.resolution_bits = "16"
device.api = "alsa"
device.class = "sound"
alsa.class = "generic"
alsa.subclass = "generic-mix"
alsa.name = "ALC257 Analog"
alsa.id = "ALC257 Analog"
alsa.subdevice = "0"
alsa.subdevice_name = "subdevice #0"
alsa.device = "0"
alsa.card = "0"
alsa.card_name = "HDA Intel PCH"
alsa.long_card_name = "HDA Intel PCH at 0xb273c000 irq 147"
alsa.driver_name = "snd_hda_intel"
device.bus_path = "pci-0000:00:1f.3"
sysfs.path = "/devices/pci0000:00/0000:00:1f.3/sound/card0"
device.bus = "pci"
device.vendor.id = "8086"
device.vendor.name = "Intel Corporation"
device.product.id = "9dc8"
device.product.name = "Cannon Point-LP High Definition Audio Controller"
device.form_factor = "internal"
device.string = "front:0"
device.buffering.buffer_size = "352800"
device.buffering.fragment_size = "176400"
device.access_mode = "mmap+timer"
device.profile.name = "analog-stereo"
device.profile.denoscription = "Analog Stereo"
device.denoscription = "Built-in Audio Analog Stereo"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card-pci"
Ports:
analog-output-speaker: Speakers (type: Speaker, priority: 10000, availability unknown)
analog-output-headphones: Headphones (type: Headphones, priority: 9900, not available)
Active Port: analog-output-speaker
Formats:
pcm

Sink #2
State: SUSPENDED
Name: bluez_sink.20_1B_88_1C_97_D7.a2dp_sink
Denoscription: Mi True Wireless EBs Basic 2
Driver: module-bluez5-device.c
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 24
Mute: no
Volume: front-left: 13099 / 20% / -41.95 dB, front-right: 13099 / 20% / -41.95 dB
balance 0.00
Base Volume: 65536 / 100% / 0.00 dB
Monitor Source: bluez_sink.20_1B_88_1C_97_D7.a2dp_sink.monitor
Latency: 0 usec, configured 0 usec
Flags: HARDWARE DECIBEL_VOLUME LATENCY
Properties:
bluetooth.protocol = "a2dp_sink"
device.denoscription = "Mi True Wireless EBs Basic 2"
device.string = "20:1B:88:1C:97:D7"
device.api = "bluez"
device.class = "sound"
device.bus = "bluetooth"
device.form_factor = "headphone"
bluez.path = "/org/bluez/hci0/dev_20_1B_88_1C_97_D7"
bluez.class = "0x240418"
bluez.alias = "Mi True Wireless EBs Basic 2"
device.icon_name = "audio-headphones-bluetooth"
Ports:
headphone-output: Headphone (type: Headphones, priority: 0, availability unknown)
Active Port: headphone-output
Formats:
pcm


I trying to extract volume of Sink #2

https://redd.it/yanv10
@r_bash