r_bash – Telegram
[Help] Parsing password to openssl OCSP

Hello everyone,

Hope everyone is doing great.

I'm implementing an OCSP server in my job and I ran into an issue.

While running \`openssl req/ca\` we can use the flag \`-passin\` or \`-passout\`, that flag doesn't exist in \`openssl ocsp\` version 1.1.1 only on version 3.

​

**Question is:**

Is there a way for me to parse the password via STDIN?

This is the command I'm trying to run:

openssl ocsp -index intermediate/index.txt -port 8080 -rsigner ${INTERMEDIATE_CRT_PATH} -rkey ${INTERMEDIATE_KEY_PATH} -CA ${INTERMEDIATE_CRT_PATH} -text

This will prompt:

Enter pass phrase for <cert_path>:

I have tried all the shell or bash magic I know and could find, tried getting the PID and redirecting to /proc/pid/fd/0 with no luck.

&#x200B;

Any help would be appreciated. Thanks !

https://redd.it/xomaxz
@r_bash
How to print to bad sector count when disk is inserted?

(using BASH version 5.1.16 on Ubuntu 22.04)

&#x200B;

Hello,

I would like to see the bad sector count of a drive when it is attached to the computer (not mounted). For example, I can run:

sudo smartctl -a /dev/sdb | grep ReallocatedSectorCt

&#x200B;

and the output I get is something like:

&#x200B;

5 ReallocatedSectorCt 0x0033 154 154 140 Pre-fail Always - 386

&#x200B;

When I hotswap a SATA drive, I would like the command run again and outputted to the display.

Any help would be appreicated

https://redd.it/xoqz7i
@r_bash
Saving a folder path to a variable

Please excuse such simple question newbie to bash :)

Pretty much what the noscript saids.
Looking to store a folder path into a variable to be later used in the noscript.
The noscript asks a few questions and based on your answer, nmap runs a scan against a set of IPs from File A or File B and then save the output to a folder.

There will be multiple different scan in which the output file is name different but all save to the same folder.

I’ve tried a few different method and get stuck with its Outputting everything in the file (CAT) or tells me the individual IPs in the files “no such file or directory xx.xx.xx.xx”

Few things I’ve tired:
Results= $Path://home/kali/Desktop/Results

FileA= $Path://home/kali/Desktop/FileA.txt

This is met with “No such file or directory”

Or
FileB= cat /home/kali/Desktop/FileB.txt

Thank you for any input!

https://redd.it/xowj9l
@r_bash
Running Multiple Python Scripts

I have multiple python noscripts that need to run, consecutively. I think the easiest way to implement this is using a cron job to run a bash noscript that runs the python noscripts one after another.

The python noscripts use argparse to take arguments from the cli and are reused in other places, so I'd like to be able to implement this without needing to change the python noscripts themselves.

Something like

#!/bin/bash
/venv/bin/python3 mynoscript.py somearg -u 'anotherarg' -p 'athirdarg'
/venv/bin/python3 mynoscript1.py somearg -u 'anotherarg' -p 'athirdarg'

https://redd.it/xpi4xs
@r_bash
Creating a magic file.

Hello,

I look to create a magic file that can be used with the command
file
to detect
School
data files.
School
data files always contain the string
SCHOOL
at offset 0.
My solution has been:

 1: 0 string SCHOOL School data


 2: !:mime School


compile


My problem is that when I run the file, the output is incorrect and I don't know why or where my blunder is. The output is:

 1: Warning: offset `�' invalid


 could not find any valid magic files!


https://redd.it/xq5ur4
@r_bash
Tmux Issues

So i have this command and when i launch it from tmux it executes more than 8 times. But on regular terminal screen it executes one time with no issues.

Basically what it does it monitors a file and if that file has changed it executes the program.

btcusd1.sh

And sends the data to Screen named minute.

So in tmux terminal i've tried.

bash -c 'inotifywait -m -e modify /tmp/btcusd_min.txt | while read -r dir; do tmux send-keys -t minute /files/ifvalueminute/btcusd1.sh ENTER; sleep 2; /files/ifvalueminute/ifvaluebtcusdminute.sh; break; done' &

And

inotifywait -m -e modify /tmp/btcusd_min.txt | while read -r dir; do $(tmux send-keys -t minute "/files/ifvalueminute/btcusd1.sh" ENTER; sleep 2; "/files/ifvalueminute/ifvaluebtcusdminute.sh"); done

This works with no issue in the regular terminal screen window. Not in tmux though

inotifywait -m -e modify /tmp/btcusd_min.txt | while read -r dir; do /files/ifvalueminute/btcusd1.sh; done &

Help or guidence is appreciated.

https://redd.it/xqf0bu
@r_bash
Check if each row in a file exists in a set of files, and if it does, update the last column in the first file with a value from the set of files

Hello!

There is a file A.tsv, which has these columns:
a b c d

With certain values in those columns. What I want to do, is for all rows, check if a row in this file exists in around 50 or so files that fall in different locations. The columns that those 50 files have are:
a b c d e f g h (first 4 are the same as above)


I'm trying to do:

for file in /my/location/50/files

for each row in A.tsv

if row exists in file1

A.tsv$5=corresponding value in file1$g

A.tsv$6=value in file1$h

if row exists in file2

A.tsv$7=file2$g

A.tsv$8=file2$h

And so on. Hence, the columns in A.tsv in which the data has to be stored will be changing for each file

The final file format for A.tsv is:

a b c d file1$g file1$h file2$g file2$h file3$g file3$h

and so on.

Now, I'm not sure what the best way to go about it is, and I'm having trouble coding it. Any help would be appreciated
Thank you!

https://redd.it/xqkakr
@r_bash
How to keep hold of another directory's path whilst using mv command?

Hi, I am getting used to bash but not there yet to be intermediate.

I would like to mv <my_folder> <destination> // #how do I find my destination file path whilst keeping this command alive? Use variables or am i missing something much simpler?

Now I could manually just find the file path of the directory I would like to move this folder to, however I might not an easier way of doing this in bash. What would you suggest?

https://redd.it/xqs2bn
@r_bash
One-liner Script Issue

Hello, this is my first post here. I have a question about noscripting, not specifically bash noscripting, but more general noscripting, which I hope is allowed here. I'm trying to get the api output using curl, but I need to read from a text file and pass it to the curl. Here's an example:

CURL command:curl --location --request GET '`https://conversations.messages.com/v1/messages/d909afaec435463aa433899dc00111b4`' --header 'Authorization: AccessKey 123AbcDefgh456' | python3 -mjson.tool

`d909afaec435463aa433899dc00111b4` is the ID of the message I want to retrieve and the result is as follows:

{"id": "d909afaec435463aa433899dc00111b4","name": "Alex Baldwin",}

And I have a msg.csv file with, say, 1,000 message IDs that I want to pass to curl. Here is my one-liner and the result.

$ cat msg.csv | while read line; do curl --location --request GET '`https://conversations.messages.com/v1/messages/$line`' --header 'Authorization: AccessKey 123AbcDefgh456' | python3 -mjson.tool; done

{"errors":[{"code":20,"denoscription":"Message not found"}]}

Any suggestions or pointers on what's wrong with the above one-liner would be greatly appreciated. Thank you very much.

https://redd.it/xqzop5
@r_bash
how to share a variable between function calls

hi guys, hope you all doing well. i have two functions f1 and f2

those look like this

f1 () {
var=0
f2 &
echo $var # prints 0
}

f2 () {
var=1
sleep 10
echo $var # prints 1
}


I want the echo in f1 to notice the change in the $var how can i do this while having f2 run in

the background (or at least have the sleep function run in the background while f1 continues running )

https://redd.it/xr212s
@r_bash
Examples of cool || non-standard || "simply insane" bash stuff?

Hi guys.

So recently I encountered following project: https://github.com/Jack000/Expose

Basically, it is bash noscript which makes sort of photo-based static blog/site. Got me curious about shell noscripting in general (although I am Linux user little less than 2 decades), because most of my "shell" noscripts are actually written in Ruby.

Do you have other examples where size or purpose of Bash/shell project is unusual or non-standard? Simply something where "sane" people would use a general dynamic programming language?

Also, I found out that Chet Ramey is sole maintainer. Anyone knows what he uses to develop bash? I assume it is not Mac. :P

Thank you.

https://redd.it/xr1vce
@r_bash
Viewing rows based on condition with awk ?

Hi,

I'm getting disk information using df -kh

Filesystem Size Used Avail Use% Mounted on
devtmpfs 5.7G 0 5.7G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 818M 7.0G 11% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 4.0G 2.6G 1.5G 64% /
/dev/sda2 4.0G 33M 4.0G 1% /media/sda2
/dev/sda5 509M 26M 483M 6% /media/sda5
/dev/sda6 18G 5.6G 12G 33% /media/sda6
/dev/sda3 4.0G 33M 4.0G 1% /media/sda3
tmpfs 1.6G 0 1.6G 0% /run/user/0

But I only want to see rows with storage space 30% or more used. How can I add condition to awk to get this information along with Headers

Expected Output

Filesystem Use%
/dev/sda1 64%
/dev/sda6 33%

How can I achieve this.

I have this so far but no header noscripts

df -kh | awk 'FNR == 6 {print $1" "$5}'
/dev/sda1 64%

Thank You

https://redd.it/xr1925
@r_bash
Different Oout of same Script ?

Hi,

I have the following noscript:

# Text Color
RED='\0330;31m'
BLUE='\033[0;34m'
NC='\033[0m'

if [ $reqSpace -lt $availableSpace
then
echo -e "${BLUE}Backup Possible, Log Data size $result MB, Free Space $availableSpace MB${NC}"
else
echo -e "${RED}Backup Not Possible, Log Data size $result MB, Free Space $availableSpace MB${NC}"
fi

This noscript when run once shows as expected result

https://preview.redd.it/p5ks73exgtq91.jpg?width=697&format=pjpg&auto=webp&s=649e36d797013fdf319c49319d58f0cf1eabe974

But when run with watch command does not parse the color variables.

https://preview.redd.it/ukm9f2d2htq91.jpg?width=701&format=pjpg&auto=webp&s=c83a7ae79f05902b3507725b6f9e259290f87de8

Any idea what's going on ?

https://redd.it/xravbu
@r_bash
Printing out command to terminal but not executing

Hi everyone. How do you print out a command to terminal without executing it in bash? For example, fzf's CTRL-R command will print it out to terminal before executing. How does one do that for arbitrary command?

https://redd.it/xrjtxf
@r_bash
exiftools, bad substitution error when trying to modify Content Create Date metadata

I used this command last year to remove the timezone from the "Content Create Date" field in a MP4 file. But now when I run this command, I get the following error...

$ exiftool -overwrite_original "-ContentCreateDate#<${ContentCreateDate; s/[+-].*//}" "file.mp4"

bash: -ContentCreateDate#<${ContentCreateDate; s/[+-].*//}: bad substitution

Not sure why this is the case now. Is there a way to get around this? Thanks in advanced.

https://redd.it/xrpux1
@r_bash
How to redirect stdin from an Interactive program to a File

I'm hoping to redirect the inpit of the python repl to a file

For example; would it be possible to set exec 3>&1 file denoscriptor somehow pipe stdin from the python repl to stdout into a log file?

my first attempt was doing exec 3>&1

and then python 2>&1 | >&3 tee -a SomeFile.log

The issue there is it's grabbing only the output from the repl and the output of the interpreter, now the i/o stream of reading the commands.

Any ideas are welcome..

https://redd.it/xrsdjv
@r_bash
FuzzyFind with Array

### I want to pipe the content of a directory(both files and directories) to fzf
this is my attempt so far. it's not functional
#!/usr/bin/env bash
content_dir="$HOME/DevRepo"
### this is my array
arr=$(ls "$content_dir")
fzf --preview "printf '%s\n' \"\${arr[{n}]}\""

### the expected output:
fzf the content of the specified directory
### the current ouput:
fzf the content of the current directory===>$PWD


Thx in advance

https://redd.it/xs1egg
@r_bash
Bash Newbie - How to do a foreach in bash?

Hello! This is my first time writing in bash, and I am having troubles understanding something basic. I would like to use a for each on a .txt file that consists of multiple commands to check machine information.

&#x200B;

In powershell, I would do something like this:

&#x200B;

$commandlist = get-content 'c:\commandlist.txt'
foreach ($command in $commandlist)
{Write-host "Running the command $command"
invoke-expression $command}

In bash, I am doing something like this:

#!/bin/bash
commandlist='commands.txt'

for command in $commandlist

do
echo "Running the command $command"
bash "$command"
done

however my output is like this:

Doing command commands.txt
MyHostName
IFconfigDetails

It seems that I am not looping correctly. What am I missing?

&#x200B;

I also read about this and this seems to work:
#!/bin/bash
cat commands.txt | while read -r line
do
echo "$line"
"$line"
done


Is this the only way I can do a foreach on a .txt file? thank you!

thank you in advance!

&#x200B;

PS. commands.txt contains only 2 lines

Hostname

IFconfig

https://redd.it/xs47yz
@r_bash
Reversing order of input

How do I do this? I want to take an input say, "Input Number One", and print back "One Number Input". I've been able to reverse the entire thing, but not the order. All online I've seen talks about reversing files.

https://redd.it/xs7dym
@r_bash