r_bash – Telegram
Batch noscript conversion to BASH

Hello everyone,

I recently had to retire my windows server that I was using to run some batch noscripts. One of them was used to create nfo files for my media server. I am not confident using bash, but I am hoping someone here can. Would someone please convert this noscript for me? Any help is greatly appreciated, and noscript is posted below.

@echo off
setlocal
for /r %%a in (.mkv .avi .mp4 .mov .wav .mpeg .mpg) do (
(
echo ^<?xml version="1.0" encoding="UTF-8" standalone="yes"?^>
echo ^<episodedetails^>
for /f
"tokens=1, delims=-" %%b in ("%%~na") do call :gennoscript "%%c"
echo ^</episodedetails^>
) > "%%~dpna.nfo"
echo %%~dpna.nfo

)
goto :eof

:gennoscript
set "n=%~1"
:gt
if "%n:~0,1%" == " " (
set "n=%n:~1%"
goto gt
)
echo ^<noscript^>%n:&=^&%^</noscript^>

https://redd.it/xuykj0
@r_bash
Getting Timestamps from a text file

I have some big text files with time stamps in the format hh:mm:ss. I want to get all this timestamps as a list in a shell noscript. Can someone help me?

https://redd.it/xva983
@r_bash
comma between files in a ls

It's the first time I'm doing a noscript and the goal I'm aiming is to put a comma between every file name listed in the result message of the ls command. I'm a transferred student in a course where every other students have 1+ year experience in programming but that's not my case, the teacher won't help me since it's basic. He said me to make a condition, and if the argument (the file name) is not the last, then type a comma, if it's the last filename, type a point. But I don't know how to make a condition, how to write something, just how to type a command in a .sh.

&#x200B;

To put everything in a nutshell the goal is to make a noscript that act like ls, by using the ls command bt after each filename there is a comma. I doubt there's a tutorial for that on the internet, I'm still looking for but that seems to be pretty difficult without help. Have a great day :)

https://redd.it/xvcc9x
@r_bash
Create json array from bash string

I have the following string in bash


"3.8,3.9,3.10"


&#x200B;

Is there a way using shell to convert it into a json array, i.e.

["3.8", "3.9", "3.10"\]


https://redd.it/xvgndg
@r_bash
How do I highlight all the content within multiple directories in a directory without highlighting the directories themselves? Then how do I move all highlighted content into a new directory?



https://redd.it/xvrgrz
@r_bash
Echo to another terminal without the echo present"

I have this command that echo to antoher screen.

tmux send-keys -t screen1 $"echo 'hello'" Enter

And whenever i do that i get both echo 'Hello' and hello

root:/# echo 'hello'

hello

Is there a possibility to only get hello?

Im Stuck been googling for hours...

https://redd.it/xvt4sr
@r_bash
Advanced if statements.

So this is a tough one.

Im trying to incorporate multiple if statements, Where only 1 if statement is executed.

But I need to be able to see wich parameter(if) it took. So i can better enhance it.

This is my code.

Currently it executes all ifstatements if they are true.

c=2
d=15
body=30

&#x200B;

if (( c >= 0 && c<= 3 && d >= 13 && d <= 30 && body >= 13 && body <= 30)); then
bash -c "echo 'Parameter 1 were taken'"
fi;

if (( c >= 0 && c<= 3 && d >= 5 && d <= 7 && body >= 18 && body <= 24)); then
bash -c "echo 'Parameter 2 were taken'"
fi;

if (( c >= 0 && c<= 6 && d >= 4 && d <= 6 && body >= 25 && body <= 30)); then
bash -c "echo 'Parameter 3 were taken'"
fi;

Backticks

So based on this post i've read that you should use || \

Should i Remove the fi and then statements and make it only as ONE "then" and "fi"?

How would i accomplish that when i want to know what parameter it took?

Help is appreciated.

&#x200B;

&#x200B;

&#x200B;

&#x200B;

&#x200B;

&#x200B;

&#x200B;

||||
|:-|:-|:-|
||||

&#x200B;

https://redd.it/xw6z11
@r_bash
cron delete command help

Hi all,

&#x200B;

I am running this manual command to delete a kubernetes pod

kubectl delete pod -n testing-namespace tunnel-displace-665121cf-8c71y
pod "tunnel-displace-665121cf-8c71y" deleted

I was wondering is there a way to set it up in a cron job noscript or one liner to delete it, bear in mind that the pods ending name '665121cf-8c71y' constantly changes when deleted and a new one is spun up.

https://redd.it/xwa1so
@r_bash
Help with recovering files in vim

I was working on a file in vim and I press :wq, I closed, but when I opened it again, I loaded stuff form some swap file (from 6 hours ago) so I lost all of my data.

I tried vim recover, but still, its loading only from the swap file from 6 hours ago.

Is there any way I can recover my data?

(Anything will work, like when I scroll up on my terminal, I can see prev data, but I does not go up to the point where I was working on my file, is there any way I can see my data this way atleatst?)

&#x200B;

Any help will be appreciated (I have to submit an assignment in 6hrs and all my data was on that file I lost)

https://redd.it/xwa0o1
@r_bash
Please how can I fix this Linux Bash related error?

For context, I am currently undergoing a Software Engineering program for full stack dev training, and I am currently exploring basics of shell with some questions to be answered at the end of my study of the basics and concepts. I am doing very ok with it considering my background in Computer Engineering, but a final question here has me stumped.

Question - Create a magic file school.mgc that can be used with the command file to detect School data files. School data files always contain the string SCHOOL at offset 0.

Below is the command I used on bash to key in the noscript into the file school.mgc

echo -e '0 string SCHOOL School data\n!:mime School' > school.mgc

But when the software program autochecker runs through my answer, I get the error msg below.

*\*\[Got\]*

*(0 chars long)*

*\[Expected\] 0-current\_working\_directory: text/plain 100-lets\_move: text/plain 101-clean\_emacs: text/plain 102-tree: text/plain 103-commas: text/plain 10-back: text/plain 11-lists: text/plain 12-file\_type: text/plain 13-symbolic\_link: text/plain 14-copy\_html: text/plain 1-listit: text/plain 2-bring\_me\_home: text/plain 3-listfiles: text/plain 4-listmorefiles: text/plain 5-listfilesdigitonly: text/plain 6-firstdirectory: text/plain 7-movethatfile: text/plain 8-firstdelete: text/plain 9-firstdirdeletion: text/plain fake\_school0: text/plain fake\_school1: text/plain file\_school0: School file\_school1: School file\_test0: inode/x-empty h\_school.mgc: application/octet-stream README.md: ... (2168 chars long)\**

&#x200B;

**I am assuming something is wrong with my noscript in school.mgc. Can someone please assist and point me in the right direction please?**

**Thanks.**

https://redd.it/xw8cdb
@r_bash
Looking for help with montage issues “montage: UnableToOpenConfigurefile” “montage: NoDecodeDelegateForThisImageFormat”
https://redd.it/xwk022
@r_bash
Docker writing to program STDIN after starting it up?

Hi! I'm trying to set up a docker container that runs a steamcmd server.

It's all working fine, the server is downloaded an executed correctly. But it's the first time that i stumble upon this roadblock.

The first time that the server starts it asks for an admin password - that cannot be set as an argument or environment variable - that it reads from stdin.

My startup.sh noscript looks like this

#!/bin/bash

echo "Starting"

steamcmd +runnoscript /server/steam-noscript.txt

start-server.sh -servername server

When the server starts it complains that no password could be read

LOG> Command line admin password: null
LOG> Enter new administrator password:
Exception in thread "main" ERROR: General ,
1665004316009> 10,911,614> java.util.NoSuchElementException: No line found

How can i write some password to the stdin before the process starts?

https://redd.it/xwmmb1
@r_bash
This media is not supported in your browser
VIEW IN TELEGRAM
arttime's v1.9.1 brings joy to sysadmins and power-users by enabling the use of arttime right after booting OS for the first time and installing zsh (i.e. in a very limited terminal environment). More denoscription and links in comment below.
https://redd.it/xwqgl0
@r_bash
Here’s a playlist of 7 hours of music I use to focus when I’m coding/studying. Post yours as well if you also have one!
https://open.spotify.com/playlist/3gk5HsGrGwKQTHinbuPgRE

https://redd.it/xwtbca
@r_bash
I trying to write a noscript that created a number of files, each containing facts about specific people

I’m trying to write a noscript where the expected result is a noscript that takes a file, reads the people names, and creates several files named “facts-PERSON.txt”, for example “facts-mari.txt”, “facts-ole.txt”.

Each of these generated files must contain:

*On the first line, the name of the person.

*Then, all “fact lines” that contain that persons’s name, one line per fact.

*On the last line, the number of facts about that person.

Basic example for "john" with filename "facts-john.txt": 

john
John has a farm.
Mari loves John.
In the last 10 years, John went to Sweden only once.
3

I have a file called filteredlist.txt with all the names, and a file called factlist.txt with all the fact about the people.

I have used:

for name in ‘cat filteredlist.txt; do touch — facts-$name.txt; done

To create files for each person, but I don’t know how to move the facts from the other file into the persons file and the word count at the end.

I have tried:

cat filteredlist.txt factlist.txt | grep -i -E $name >> facts-$name.txt

and

cat facts-$name.txt | wc -l $1 | awk '{print $1 - 1}'n >> facts-$name.txt

But they don’t work, they just work on the first name, not the rest.

https://redd.it/xx5h8i
@r_bash
Needing Help with a File Extraction Script for my Dad

Hi everyone -

My dad archived old family photos and documents as ISO’s and has them saved to an old network hard drive back up. I don’t know why he did it this way but he has seemingly thousands of ISOs made for every album or folder the photos and documents belonged in. Decades worth of things I am trying to extract for him.

He doesn’t trust any programs out there to extract the files within the ISOs as he is worried it would give the company access to his family photos. In his words, he wants “the computer to handle it”… aka “me”.

I am hoping to not have to open each one to extract data but instead have a noscript mount the ISO, extract the data, (Unmount?) and move onto the next ISO automatically. Or even accomplish data extracting without needing to mount the ISO works as well. He put in a lot of work organizing the folders and files before saving as an ISO, so I am hoping it keeps its naming structure so he doesn’t have to do that again.

I am currently in possession of his networked hard drive but it sometimes loses its connection when trying to access via USB due to a loose cable connection, so hoping to see if this can be done on a networked drive and if there are failures is there a log that can tell me the files it couldn’t extract? I just don’t want to accidentally miss one or two.

I hope this is enough information and not too large of an ask. I want to try to get this done for an upcoming family reunion this thanksgiving and surprise him.

Thank you everyone for any guidance you can give. Can a noscript even accomplish this and is there anyone kind enough to assist? It would mean the world to me.

https://redd.it/xx8hf5
@r_bash
Opinions on the right tool

Hi Everybody! (Hi Dr. Nick!)

What I like about this subreddit is that while it's bash focused, it's not generally populated with bash zealots or bash absolutists. What I've seen over a number of posts is more of an approach of "Right tool for the right job". So with that in mind I want to explain my problem/desired outcome and get your opinions on what the right tool is for this.

Problem: (Better) Websites will provide you with the file hash for the file you're downloading so you can verify authenticity/integrity when you have it on your system. My eyes are lazy. When I'm verifying a hash I simply make sure the last 6 or so characters match between the two files. My eyes are also assholes and like to tell my brain whatever they want.

Solution: I'd like to noscript out a utility do do the following:

Read input from the user to specify the known good hash.
One of the following:
Have the user specify the hashing algorithm to use (md5, sha, sha256, etc) via command line flags OR, if I get especially froggy, I'd love to learn how to make a live selection menu.
Use regex matching to recognize the kind of hashing algorithm based on the hash input. This is a blind assumption currently as I haven't looked at all the mechanisms and their outputs yet.
Read input from a CLI argument specifying the file we're trying to verify.
Run the appropriate hashing mechanism against the file and store the hash portion of the output. (Using the preexisting commands in Linux/MacOS like sha(x)sum, md5sum, etc)
Compare the known value against the generated value and return a happy little message.
Provide a command line help option with a print of the available options and command usage.

Now, this is a learning project for me. I'm in the market to learn bash (Better, I'm a hopeless novice currently) or python (Even more of a novice). I'm not sure which approach is more appropriate for the stated goals. From what I can tell, both can perform all of the requirements without blinking an eye.

While researching for this post I did find that my suspicion is correct and the target OSs (linux and macos) use different commands for the goals, so I guess it'll also need to determine the current OS as well.

https://redd.it/xxcy90
@r_bash
using acpi with fahrenheit printout

The temperature readouts via tooltips in the taskbar for icewm are in celsius. For me, this is inconsistent with my conky configuration and could lead to confusion on my part. The \~/.icewm/preferences file does not seem to provide a way to set temp defaults to fahrenheit. The naming conventions for the variable names in preferences seems to imply that acpi is being used in the background. Acpi has a -f flag that enables printout in fahrenheit. Nowhere does man indicate that there is a config file for acpi. Any ideas? Using ubuntu 20.04. This question is about the executable command at /usr/bin/acpi, not the kernel mod.

https://redd.it/xxix59
@r_bash
Updating BASH Script

Hello,

I have a bash noscript that another user created that I am having issues performing how I want. I want the noscript to create an nfo file for every episode name in all sub folders. I want to put the noscript in the main folder and run it, and I want it to generate the files for all the files in every sub folder of the main folder. Below is the noscript and when it runs, it just creates 1 .nfo file with the names of all episodes in that one, and that does not work. Any help is greatly appreciated, and I want to thank anyone who can help in advance. The code is below.

&#x200B;

#!/bin/sh
# Un-comment the following line to have the shell print the data it's working with
#set -x
cd "/Users/user1/Downloads/show/"
filelist="files.lst"
collect
files() {
# Recursively search the directory noted by the first argument, or the current working directory if not
# provided that matches the regular expression matching the various file extensions we care about,
# and print the results to the file specified by the second argument, or the value of the variable $filelist
# if not specified.
(find "${1:-.}" -maxdepth 2 -type f -iname '*.(mkv|avi|mp4|mov|wav|mpeg|mpg)' -print > "${2:-${file
list}}")
}

generatexml() {
# Collect all the files of interest using the function `collect
files telling it where to search
# as well as where to record the results
collect_files "${search_directory:-${PWD}}" "${file_list}"

# Verify there are results and they can be read
if [ -s "${file_list}" ] && [ -r "${file_list}" ]
then
# Set the shell to operate on text a full line at a time
OLD_IFS="${IFS}"
IFS='\n'
# Read a line out of the file and store the value in the variable $filename
while read -r filename
do
# Reset the shell to operate on text normally
IFS="${OLD_IFS}"
# Strip all text leading to and including the first '-' character from the variable $filename
# storing the result in the variable $file_noscript
file_noscript="${filename##*-}"
# Remove the file extension from the variable $file_noscript
file_noscript="${file_noscript%.*}"
printf '<noscript>%s</noscript>\n' "${file_noscript}"
# Ensure the next loop iteration gets a full line of text
IFS='\n'
done < "${file_list}"
# Ensure the shell's configured to operate on text normally again
IFS="${OLD_IFS}"
fi
}

main() {
# Look at
man 1 getopts or man bash to see how you can add argument handling
# to specify where to look for files instead of having to remember which order the arguments go in

# Allow the user to specify the output filename
output_file="${2:-dpna.nfo}"
# Allow for searching a specific directory
search_directory="${1:-.}"

# Create the XML header
printf '%s\n' \
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' \
'<episodedetails>' > "${output_file}"

# Use the
generatexml` function to produce all the noscripts and fill in that portion of the file
generate
xml >> "${outputfile}"

# Close the episode list
printf '%s\n' '</episodedetails>' >> "${output
file}"

}

main "${@}"

https://redd.it/xxqjfc
@r_bash
how to set a variable as a functions name

hi.

i am using a for loop to make functions from code stored in there own files.

if [ ! -x "$DATA/internal/$cmd" ]
then chmod +x "$DATA/internal/$cmd" ; fi


function $cmd {
$DATA/internal/$cmd
}
done

but that wont work, becouse you for some reason cant use a variable to set a function's name... how could i do this? or what are alternatives? alias won't work for me, as you cant use aliases in a shellnoscript.

https://redd.it/xxuzve
@r_bash
MKVpropedit all files in directory

I'm trying to create a bash noscript to bulk change the color metadata of all files in a folder.

The command is

mkvpropedit [FILE] --edit track:v1 --set colour-transfer-characteristics=0

The noscript I usually use for loops is giving the error "Error: More than one file name has been given ('a.mkv' and 'b.mkv')

for file in *; do mkvpropedit *.mkv --edit track:v1 --set colour-transfer-characteristics=0

How do I write the noscript to execute all files?

https://redd.it/xy4i6z
@r_bash