r_bash – Telegram
help: delete largest duplicate file

Hi everyone, I'm struggling with a little bash noscript this morning and while I often like to experiment and find it myself, I'm stuck.

I have a directory that contains about 1k video files. Each file is duplicated and have different encodings and frame sizes. Since it's for archival I only want to keep the smallest file for each video.

Both duplicates of a file have the same name until the last 16 characters which are a random string of characters/timestamp. And the extensions are inconsistent.

I can list all files, ordered by name which places the duplicates next to each other, but then how do i find the one with the largest filesize and delete that one?
Also i can't just go though the list 2 by 2 because not 100% of the files have a duplicate. But I can't think of another way to traverse the file list with my current skillset.

I'm a beginner at bash, have only written 4-5 complex noscripts and that was while constantly looking at basic documentation just to get a ''if statement'' syntax right. So any help would be greatly appreciated.

https://redd.it/y70r7j
@r_bash
Bash help

I need urgent help with bash for an upcoming assessment. I usually wouldn't ask help but I've no clue how bash works. If anyone can help please dm

https://redd.it/y753m9
@r_bash
Problem with handling with datetimes in Bash

I'm quite new to bash noscripting, and test in general. I'm writing a noscript to automatically update Docker images, when I get this error:

/home/misery/update-images.sh: line 31: [[: 2022-10-07T02: value too great for base (error token is "07T02")


Before I call test, I logged the timestamp I extract from the Docker API:
Remote image created on 2022-10-07T02:22:37
^^^^^^^^^^^^^^^^^^^
In a variable called 'remoteImage'


For debugging purposes, I tried echoing localImage too:
"2022-10-07T02:22:37


Yet why am I getting an error in line 31?

Here's the code where I do an if
if [[ "$remoteImage" -eq "${localImage:1}" ]]; then
echo $image is outdated!
else
echo $image is up-to-date
fi


https://redd.it/y78wln
@r_bash
What is this local and where I can learn more

Is this maybe obsolete?




pause(){

local message="$@"

[ -z $message ] && message="Press Enter key to continue..."


read -p "$message" readEnterKey
}

https://redd.it/y7afy6
@r_bash
Newbie question, How do I convert a string to numeric

For example.

$username =?

Im trying to give each user a UID that matches to the numaric value of its name.

Any help will be appricated

https://redd.it/y7e7uo
@r_bash
Error during a noscript, but running fine when doing it manually.

In my noscript I have a line which goes

read -s password

When I execute the noscript it gives me an error "read: illegal option -s"

But when I type it manually into the terminal it works fine. I tried running the noscript as sudo didn't solve it.
Any help would be appricated.

https://redd.it/y7kabe
@r_bash
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