grep: warning: stray \ before /
I am trying to run this noscript.
#!/bin/sh
movie=$(curl -s https://1337x.to/search/$query/1/ | grep -Eo "torrent\/0-9{7}\/a-zA-Z0-9?%-/" | head -n 1)
magnet=$(curl -s https://1337x.to/$movie | grep -Po "magnet:\?xt=urn:btih:[a-zA-Z0-9]" | head -n 1)
peerflix $magnet -l -v
I get the error of grep: warning: stray \\ before / . I have tried to get rid of the \\ before the /. This did not work. Can anyone help me?
https://redd.it/z2vfx0
@r_bash
I am trying to run this noscript.
#!/bin/sh
movie=$(curl -s https://1337x.to/search/$query/1/ | grep -Eo "torrent\/0-9{7}\/a-zA-Z0-9?%-/" | head -n 1)
magnet=$(curl -s https://1337x.to/$movie | grep -Po "magnet:\?xt=urn:btih:[a-zA-Z0-9]" | head -n 1)
peerflix $magnet -l -v
I get the error of grep: warning: stray \\ before / . I have tried to get rid of the \\ before the /. This did not work. Can anyone help me?
https://redd.it/z2vfx0
@r_bash
How to pass an associative array to another noscript
I want to pass an associative array in noscript1.sh to noscript2.sh. Here is what I have:
noscript1.sh:
declare -A queues
queues=( "key1"="value1" "key2"="value2" "key3"="value3" "key4"="value4" )
call noscript2:
noscript2.sh "$param1" "$param2" "$param3" "${queues@}"
noscript2.sh:
arg1=$1
arg2=$2
arg3=$3
declare -A arg4=$4
The associative array in noscript1 is fine. I can loop through the array and see its elements. However, when I tried to pass it to noscript2.sh, I can't see any of the elements in arg4. Thanks in advance.
https://redd.it/z2xyv5
@r_bash
I want to pass an associative array in noscript1.sh to noscript2.sh. Here is what I have:
noscript1.sh:
declare -A queues
queues=( "key1"="value1" "key2"="value2" "key3"="value3" "key4"="value4" )
call noscript2:
noscript2.sh "$param1" "$param2" "$param3" "${queues@}"
noscript2.sh:
arg1=$1
arg2=$2
arg3=$3
declare -A arg4=$4
The associative array in noscript1 is fine. I can loop through the array and see its elements. However, when I tried to pass it to noscript2.sh, I can't see any of the elements in arg4. Thanks in advance.
https://redd.it/z2xyv5
@r_bash
reddit
How to pass an associative array to another noscript
I want to pass an associative array in noscript1.sh to noscript2.sh. Here is what I have: noscript1.sh: declare -A queues queues=( ["key1"]="value1"...
Need help with sed and variables
Hi Everyone,
I've put together a sed for vnstat xml output for my openwrt router. (trying to get a cleaner output) My sed works if I have the year (2022) and month (11) in the sed command. When I replace 2022 with $y and 11 with $m, it doesnt work, no change in the output, like it doesn't recognize it.
​
The file looks like this:
2022 11 21 05:00 474322562 15172268
2022 11 21 06:00 536016232 651897033
2022 11 21 07:00 184569685 109642704
Here is what works (without the variables, just normal ):
vnstat --xml |grep -hnr "hour id" | sed "s/<^>>/ /g; s/2022//g; s/ //g; s/ 00/:00/g; s/11 /11-/g" | cut -d " " -f2- > houroutput.xml
-----------------------------------------------
and the output looks good:
11-21 05:00 474322562 15172268
11-21 06:00 536016232 651897033
11-21 07:00 184569685 109642704
​
my noscript looks like with the variables in sed, I even replaced the single quotes with double, but no change in output.
#!/bin/sh
y="date +%Y"
m="date +%m"
vnstat --xml |grep -hnr "hour id" | sed "s/<[^>]>/ /g; s/$y//g; s/ //g; s/ 00/:00/g; s/$m /$m-/g" | cut -d " " -f2- > houroutput.xml
Output doesnt look good:
2022 11 21 05:00 474322562 15172268
2022 11 21 06:00 536016232 651897033
2022 11 21 07:00 184569685 109642704
https://redd.it/z31cfq
@r_bash
Hi Everyone,
I've put together a sed for vnstat xml output for my openwrt router. (trying to get a cleaner output) My sed works if I have the year (2022) and month (11) in the sed command. When I replace 2022 with $y and 11 with $m, it doesnt work, no change in the output, like it doesn't recognize it.
​
The file looks like this:
2022 11 21 05:00 474322562 15172268
2022 11 21 06:00 536016232 651897033
2022 11 21 07:00 184569685 109642704
Here is what works (without the variables, just normal ):
vnstat --xml |grep -hnr "hour id" | sed "s/<^>>/ /g; s/2022//g; s/ //g; s/ 00/:00/g; s/11 /11-/g" | cut -d " " -f2- > houroutput.xml
-----------------------------------------------
and the output looks good:
11-21 05:00 474322562 15172268
11-21 06:00 536016232 651897033
11-21 07:00 184569685 109642704
​
my noscript looks like with the variables in sed, I even replaced the single quotes with double, but no change in output.
#!/bin/sh
y="date +%Y"
m="date +%m"
vnstat --xml |grep -hnr "hour id" | sed "s/<[^>]>/ /g; s/$y//g; s/ //g; s/ 00/:00/g; s/$m /$m-/g" | cut -d " " -f2- > houroutput.xml
Output doesnt look good:
2022 11 21 05:00 474322562 15172268
2022 11 21 06:00 536016232 651897033
2022 11 21 07:00 184569685 109642704
https://redd.it/z31cfq
@r_bash
reddit
Need help with sed and variables
Hi Everyone, I've put together a sed for vnstat xml output for my openwrt router. (trying to get a cleaner output) My sed works if I have the...
Somewhat probably generic post
What's your personal 'ah ha' moment when getting into learning bash? What made you think, "oh damn I need to know this"
https://redd.it/z3riln
@r_bash
What's your personal 'ah ha' moment when getting into learning bash? What made you think, "oh damn I need to know this"
https://redd.it/z3riln
@r_bash
reddit
Somewhat probably generic post
What's your personal 'ah ha' moment when getting into learning bash? What made you think, "oh damn I need to know this"
my first semi noob noscript - Loop through list of trackers and test if they are alive using nc
https://gist.github.com/neuthral/0ff41380958321d69888fead29d510ee
https://redd.it/z3rcka
@r_bash
https://gist.github.com/neuthral/0ff41380958321d69888fead29d510ee
https://redd.it/z3rcka
@r_bash
Gist
Loop through list of trackers and test if they are alive using nc
Loop through list of trackers and test if they are alive using nc - loop.sh
read contents of a file into a variable with bash without invoking other commands?
Is there some internal bash way to do this?
x=$(cat /proc/uptime)
And i am not thinking about the line-by-line "while read l; do bla bla; done < file" (for various reasons).
https://redd.it/z3ue97
@r_bash
Is there some internal bash way to do this?
x=$(cat /proc/uptime)
And i am not thinking about the line-by-line "while read l; do bla bla; done < file" (for various reasons).
https://redd.it/z3ue97
@r_bash
reddit
read contents of a file into a variable with bash without invoking...
Is there some internal bash way to do this? x=$(cat /proc/uptime) And i am not thinking about the line-by-line "while read l; do bla bla; done <...
This media is not supported in your browser
VIEW IN TELEGRAM
I've been working on this CLI tool to automate creation of noscript files, modification of file permissions, and input typical text. I spend a lot of time in the command line for work, but consider myself still learning noscripting. If you have any input I'd appreciate it!
https://redd.it/z4hi9r
@r_bash
https://redd.it/z4hi9r
@r_bash
Sorting by size with ls -S and reading each first line of .txt files
So i have this task to sort .txt files by size and then reading the first line of each of them and displaying them
i do know that i can sort by size with ls -S
also for the reading and displaying part
problem is that if i put
i do know that there is an awk command, tried with that either, but i cant use it as its for class and we just started with bash so we have to stick to the .. "basics"
https://redd.it/z4mvws
@r_bash
So i have this task to sort .txt files by size and then reading the first line of each of them and displaying them
i do know that i can sort by size with ls -S
also for the reading and displaying part
for i in *.txt; do head -n 1 $i; doneproblem is that if i put
ls -S | before this ... it doesnt work .. like i get the output but its not sorted by sizei do know that there is an awk command, tried with that either, but i cant use it as its for class and we just started with bash so we have to stick to the .. "basics"
https://redd.it/z4mvws
@r_bash
reddit
Sorting by size with ls -S and reading each first line of .txt files
So i have this task to sort .txt files by size and then reading the first line of each of them and displaying them i do know that i can sort by...
Having trouble with a bash user creation noscript for homework
The bash noscript pulls some stuff out of a csv file (firstname, lastname, dob, group)
I can get that stuff into an array, but when I try to massage the data in the array, it tries to run one of the variables as a command.
Can someone tell me what I'm doing wrong?
\#!/bin/bash
\#set -x
testdata="/home/diana/testdata.csv"
declare -a fnames
declare -a lnames
declare -a dob
declare -a course
while IFS="," read -r Student_Firstname Student_Lastname Student_BirthDate Course_Data trash;
do
fnames+=("$Student_Firstname")
lnames+=("$Student_Lastname")
dob+=("$Student_BirthDate")
done<$testdata
\## usernames[index\]= ${fnames[index\]::1}${lnames[index\]} | tr [:upper:\] [:lower:\]
for index in "${!fnames[@\]}";do
\#this next line tries to "run" the username.
usernames= "${fnames[index\]::1}${lnames[index\]} | tr [:upper:\] [:lower:\]"
\# echo ${fnames[index\]::1}${lnames[index\]} | tr [:upper:\] [:lower:\]
\# echo ${fnames[index\]::1}${lnames[index\]::1}${dob[index\]} | tr [:upper:\] [:lower:\]
\# echo $usernames
\#printf ${fnames[index\]}
done
https://redd.it/z4niaz
@r_bash
The bash noscript pulls some stuff out of a csv file (firstname, lastname, dob, group)
I can get that stuff into an array, but when I try to massage the data in the array, it tries to run one of the variables as a command.
Can someone tell me what I'm doing wrong?
\#!/bin/bash
\#set -x
testdata="/home/diana/testdata.csv"
declare -a fnames
declare -a lnames
declare -a dob
declare -a course
while IFS="," read -r Student_Firstname Student_Lastname Student_BirthDate Course_Data trash;
do
fnames+=("$Student_Firstname")
lnames+=("$Student_Lastname")
dob+=("$Student_BirthDate")
done<$testdata
\## usernames[index\]= ${fnames[index\]::1}${lnames[index\]} | tr [:upper:\] [:lower:\]
for index in "${!fnames[@\]}";do
\#this next line tries to "run" the username.
usernames= "${fnames[index\]::1}${lnames[index\]} | tr [:upper:\] [:lower:\]"
\# echo ${fnames[index\]::1}${lnames[index\]} | tr [:upper:\] [:lower:\]
\# echo ${fnames[index\]::1}${lnames[index\]::1}${dob[index\]} | tr [:upper:\] [:lower:\]
\# echo $usernames
\#printf ${fnames[index\]}
done
https://redd.it/z4niaz
@r_bash
reddit
Having trouble with a bash user creation noscript for homework
The bash noscript pulls some stuff out of a csv file (firstname, lastname, dob, group) I can get that stuff into an array, but when I try to...
Cron job for shell noscript not running
https://stackoverflow.com/questions/74577211/cron-job-for-shell-noscript-not-running
Full/detailed q in stack overflow above.
tl;dr cannot get my cron job to successfully execute a shell noscript, nor can I seem to get it to format as intended, despite the noscript working when called manually and absolute paths used for everything.
https://redd.it/z4mj18
@r_bash
https://stackoverflow.com/questions/74577211/cron-job-for-shell-noscript-not-running
Full/detailed q in stack overflow above.
tl;dr cannot get my cron job to successfully execute a shell noscript, nor can I seem to get it to format as intended, despite the noscript working when called manually and absolute paths used for everything.
https://redd.it/z4mj18
@r_bash
Stack Overflow
Cron job for shell noscript not running
I recently downloaded Speedtest onto my Raspberry Pi, and wrote a noscript to output the results in csv format to a CSV file.
I'm trying to do this regularly via a cron job, but for some reason, it w...
I'm trying to do this regularly via a cron job, but for some reason, it w...
Help with creating a noscript for transcoding files located in subdirectories with FFMPEG
Hi. I'm trying to write a noscript that locates all video files (.mkv in this case) from subdirectories, transcodes them with FFMPEG to HEVC, and stores the output in another HDD, **preserving the directory tree**.
**Example:**
I want to transcode /videos/pets/cats.mkv to HEVC and store the output inside /hdd2/pets/cats\_hevc.mkv
This is the noscript that I currently have, but it doesn't preserve the directory structure nor search in subdirectories (I tried to use 'find' but I couldn't create new folders in the output location):
#! /bin/bash
for file in *.mkv;
do
ffmpeg -i "$file" -pix_fmt yuv420p10le -map 0:v -map 0:a -c:v libx265 -crf 21 -preset slow -c:a aac -b:a 128k "/path/to/output/directory/${file%.*}_hevc.mkv";
done
echo "Conversion complete!"
How can I do that? I've been trying for hours but couldn't find a way to make it work.
Thanks.
https://redd.it/z4qa0n
@r_bash
Hi. I'm trying to write a noscript that locates all video files (.mkv in this case) from subdirectories, transcodes them with FFMPEG to HEVC, and stores the output in another HDD, **preserving the directory tree**.
**Example:**
I want to transcode /videos/pets/cats.mkv to HEVC and store the output inside /hdd2/pets/cats\_hevc.mkv
This is the noscript that I currently have, but it doesn't preserve the directory structure nor search in subdirectories (I tried to use 'find' but I couldn't create new folders in the output location):
#! /bin/bash
for file in *.mkv;
do
ffmpeg -i "$file" -pix_fmt yuv420p10le -map 0:v -map 0:a -c:v libx265 -crf 21 -preset slow -c:a aac -b:a 128k "/path/to/output/directory/${file%.*}_hevc.mkv";
done
echo "Conversion complete!"
How can I do that? I've been trying for hours but couldn't find a way to make it work.
Thanks.
https://redd.it/z4qa0n
@r_bash
reddit
Help with creating a noscript for transcoding files located in...
Hi. I'm trying to write a noscript that locates all video files (.mkv in this case) from subdirectories, transcodes them with FFMPEG to HEVC, and...
Master the command line, in one page
https://github.com/jlevy/the-art-of-command-line
https://redd.it/z4zcy5
@r_bash
https://github.com/jlevy/the-art-of-command-line
https://redd.it/z4zcy5
@r_bash
GitHub
GitHub - jlevy/the-art-of-command-line: Master the command line, in one page
Master the command line, in one page. Contribute to jlevy/the-art-of-command-line development by creating an account on GitHub.
Help with Bash homework, convert Uppercase to Lowercase in txt file
Hello, I have to write a line of simple Bash code to convert every Uppercase letter to lowercase in a .txt file.
Can anyone help?
https://redd.it/z5302q
@r_bash
Hello, I have to write a line of simple Bash code to convert every Uppercase letter to lowercase in a .txt file.
Can anyone help?
https://redd.it/z5302q
@r_bash
reddit
Help with Bash homework, convert Uppercase to Lowercase in txt file
Hello, I have to write a line of simple Bash code to convert every Uppercase letter to lowercase in a .txt file. Can anyone help?
no way to record PWD in the bash history i guess?
I want a better history, and did this
export HISTTIMEFORMAT="%F%H:%M:%S [$sshkeycomment] "
$ssh\key_comment is figured out in a profile.d noscript and simply contains the ssh key comment of the key of the person that logged in (via ssh...). Or contains "n/a".
I can see that the timestamps are now recorded as a #-comment in .bash_history.
Its just one thing missing, would be nice to see the current PWD where the comment was entered.
Adding $PWD to HISTTIMEFORMAT doesnt work because thats simply not recorded in the history.
Might there be a trick to get it recorded anyway? :)
Cant see any way from the man page...
https://redd.it/z583sh
@r_bash
I want a better history, and did this
export HISTTIMEFORMAT="%F%H:%M:%S [$sshkeycomment] "
$ssh\key_comment is figured out in a profile.d noscript and simply contains the ssh key comment of the key of the person that logged in (via ssh...). Or contains "n/a".
I can see that the timestamps are now recorded as a #-comment in .bash_history.
Its just one thing missing, would be nice to see the current PWD where the comment was entered.
Adding $PWD to HISTTIMEFORMAT doesnt work because thats simply not recorded in the history.
Might there be a trick to get it recorded anyway? :)
Cant see any way from the man page...
https://redd.it/z583sh
@r_bash
reddit
no way to record PWD in the bash history i guess?
I want a better history, and did this export HISTTIMEFORMAT="%F_%H:%M:%S [$ssh_key_comment] " $ssh\_key\_comment is figured out in a...
social nets from bash lynx
m.facebook.com worked for me in 2021. gmail stopped working early 2021 because of javanoscript, tho had used html mode a decade. a coupla years ago linkedin kept trying to catchpa me but despite scp failed. have seen bash noscripts for twitter and reddit but never worked. anyone care to give a general status report with urls?
https://redd.it/z5jr1y
@r_bash
m.facebook.com worked for me in 2021. gmail stopped working early 2021 because of javanoscript, tho had used html mode a decade. a coupla years ago linkedin kept trying to catchpa me but despite scp failed. have seen bash noscripts for twitter and reddit but never worked. anyone care to give a general status report with urls?
https://redd.it/z5jr1y
@r_bash
reddit
social nets from bash lynx
m.facebook.com worked for me in 2021. gmail stopped working early 2021 because of javanoscript, tho had used html mode a decade. a coupla years ago...
Pulling information about processes from /proc/pid/stat
Hi, I need to display information about all running processes (pid, ppid) from /proc/pid/stat. Any tips how to get around this?
https://redd.it/z5yxu4
@r_bash
Hi, I need to display information about all running processes (pid, ppid) from /proc/pid/stat. Any tips how to get around this?
https://redd.it/z5yxu4
@r_bash
reddit
Pulling information about processes from /proc/pid/stat
Hi, I need to display information about all running processes (pid, ppid) from /proc/pid/stat. Any tips how to get around this?
How to log bash commands in some simple way?
I would like to log bash commands to a log file. Seems easy enough, but i have searched and searched and not found a simple and sufficient method.
It seems like this should be possible by hooking in to some bash function/variable, but there is always something missing:/
I tried enhancing the history a bit here https://www.reddit.com/r/bash/comments/z583sh/no\_way\_to\_record\_pwd\_in\_the\_bash\_history\_i\_guess but that failed.
Sorry for that untested post by the way.
The utility "noscript" almost seems good enough, but for some reason there is no way to get a timestamp for each command!? (or is there?)
(i have seen solutions where the output of noscript is piped through for instance 'ts', but i would really like to avoid too many sub-processes and pipes and stuff, that will just cause problems later on).
I saw one solution where PROMPT_COMMAND was used together with "history | tail -n", but that wont work when commands take long to complete. The timestamp will be when the command finished...
Basically i would like to log like this
>2022-11-27 12:00 [user\] [env-var\] [cwd\] the command...
Where 'env-var' could be any variable from the environment.
Is there really no way to just get bash to execute some function that gets the input passed as arguments each time a command is executed?
Sorry for posting yet another of these questions. I have found many many questions kinda like this, but really strangely enough no simple and satisfactory solutions.
https://redd.it/z6119l
@r_bash
I would like to log bash commands to a log file. Seems easy enough, but i have searched and searched and not found a simple and sufficient method.
It seems like this should be possible by hooking in to some bash function/variable, but there is always something missing:/
I tried enhancing the history a bit here https://www.reddit.com/r/bash/comments/z583sh/no\_way\_to\_record\_pwd\_in\_the\_bash\_history\_i\_guess but that failed.
Sorry for that untested post by the way.
The utility "noscript" almost seems good enough, but for some reason there is no way to get a timestamp for each command!? (or is there?)
(i have seen solutions where the output of noscript is piped through for instance 'ts', but i would really like to avoid too many sub-processes and pipes and stuff, that will just cause problems later on).
I saw one solution where PROMPT_COMMAND was used together with "history | tail -n", but that wont work when commands take long to complete. The timestamp will be when the command finished...
Basically i would like to log like this
>2022-11-27 12:00 [user\] [env-var\] [cwd\] the command...
Where 'env-var' could be any variable from the environment.
Is there really no way to just get bash to execute some function that gets the input passed as arguments each time a command is executed?
Sorry for posting yet another of these questions. I have found many many questions kinda like this, but really strangely enough no simple and satisfactory solutions.
https://redd.it/z6119l
@r_bash
reddit
no way to record PWD in the bash history i guess?
I want a better history, and did this export HISTTIMEFORMAT="%F_%H:%M:%S [$ssh_key_comment] " $ssh\_key\_comment is figured out in a...