"table=2 dl_dst=00:00:00:00:00:07 action=strip_vlan,output(2)"
\#vlan 2
ovs-ofctl --protocols=OpenFlow13 add-flow s3 "table=3 dl_dst=00:00:00:00:00:02 action=strip_vlan,output(1)"
ovs-ofctl --protocols=OpenFlow13 add-flow s3 "table=3 dl_dst=00:00:00:00:00:04 action=strip_vlan,output(4)"
ovs-ofctl --protocols=OpenFlow13 add-flow s3 "table=3 dl_dst=00:00:00:00:00:06 action=strip_vlan,output(3)"
ovs-ofctl --protocols=OpenFlow13 add-flow s3 "table=3 dl_dst=00:00:00:00:00:08 action=strip_vlan,output(2"
\#vlan 1 broadcast
ovs-ofctl --protocols=OpenFlow13 add-flow s3 "table=4 action=resubmit(,0)"
​
\# rules for switch 4
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=0 dl_vlan=1 priority=100 action=resubmit(,2)"
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=0 dl_vlan=2 priority=100 action=resubmit(,3)"
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=0 priority=1 action=resubmit(,1)"
​
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=1 dl_src=00:00:00:00:00:05 action=mod_vlan_vid:1,resubmit(,4)"
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=1 dl_src=00:00:00:00:00:06 action=mod_vlan_vid:2,resubmit(,4)"
\#vlan 1
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=2 dl_dst=00:00:00:00:00:05 action=strip_vlan,output(1)"
\#vlan 2
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=3 dl_dst=00:00:00:00:00:06 action=strip_vlan,output(2)"
\#vlan 1 broadcast
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=4 action=resubmit(,0)"
​
\# rules for switch 5
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=0 dl_vlan=1 priority=100 action=resubmit(,2)"
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=0 dl_vlan=2 priority=100 action=resubmit(,3)"
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=0 priority=1 action=resubmit(,1)"
​
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=1 dl_src=00:00:00:00:00:07 action=mod_vlan_vid:1,resubmit(,4)"
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=1 dl_src=00:00:00:00:00:08 action=mod_vlan_vid:2,resubmit(,4)"
\#vlan 1
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=2 dl_dst=00:00:00:00:00:07 action=strip_vlan,output(1)"
\#vlan 2
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=3 dl_dst=00:00:00:00:00:08 action=strip_vlan,output(2)"
\#vlan 1 broadcast
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=4 action=resubmit(,0)"```
I'm getting this error when I run it
```ovs-ofctl: none of the usable flow formats (OpenFlow10+table_id,NXM+table_id) is among the allowed flow formats (OXM-OpenFlow13)```, I've looked online and have used a few ai bots to help fix it but I can't.
​
Where am I going wrong? What do I do to fix it and make it work the way I want it too?
​
Any help is great thanks.
https://redd.it/18fzy3d
@r_bash
\#vlan 2
ovs-ofctl --protocols=OpenFlow13 add-flow s3 "table=3 dl_dst=00:00:00:00:00:02 action=strip_vlan,output(1)"
ovs-ofctl --protocols=OpenFlow13 add-flow s3 "table=3 dl_dst=00:00:00:00:00:04 action=strip_vlan,output(4)"
ovs-ofctl --protocols=OpenFlow13 add-flow s3 "table=3 dl_dst=00:00:00:00:00:06 action=strip_vlan,output(3)"
ovs-ofctl --protocols=OpenFlow13 add-flow s3 "table=3 dl_dst=00:00:00:00:00:08 action=strip_vlan,output(2"
\#vlan 1 broadcast
ovs-ofctl --protocols=OpenFlow13 add-flow s3 "table=4 action=resubmit(,0)"
​
\# rules for switch 4
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=0 dl_vlan=1 priority=100 action=resubmit(,2)"
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=0 dl_vlan=2 priority=100 action=resubmit(,3)"
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=0 priority=1 action=resubmit(,1)"
​
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=1 dl_src=00:00:00:00:00:05 action=mod_vlan_vid:1,resubmit(,4)"
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=1 dl_src=00:00:00:00:00:06 action=mod_vlan_vid:2,resubmit(,4)"
\#vlan 1
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=2 dl_dst=00:00:00:00:00:05 action=strip_vlan,output(1)"
\#vlan 2
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=3 dl_dst=00:00:00:00:00:06 action=strip_vlan,output(2)"
\#vlan 1 broadcast
ovs-ofctl --protocols=OpenFlow13 add-flow s4 "table=4 action=resubmit(,0)"
​
\# rules for switch 5
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=0 dl_vlan=1 priority=100 action=resubmit(,2)"
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=0 dl_vlan=2 priority=100 action=resubmit(,3)"
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=0 priority=1 action=resubmit(,1)"
​
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=1 dl_src=00:00:00:00:00:07 action=mod_vlan_vid:1,resubmit(,4)"
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=1 dl_src=00:00:00:00:00:08 action=mod_vlan_vid:2,resubmit(,4)"
\#vlan 1
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=2 dl_dst=00:00:00:00:00:07 action=strip_vlan,output(1)"
\#vlan 2
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=3 dl_dst=00:00:00:00:00:08 action=strip_vlan,output(2)"
\#vlan 1 broadcast
ovs-ofctl --protocols=OpenFlow13 add-flow s5 "table=4 action=resubmit(,0)"```
I'm getting this error when I run it
```ovs-ofctl: none of the usable flow formats (OpenFlow10+table_id,NXM+table_id) is among the allowed flow formats (OXM-OpenFlow13)```, I've looked online and have used a few ai bots to help fix it but I can't.
​
Where am I going wrong? What do I do to fix it and make it work the way I want it too?
​
Any help is great thanks.
https://redd.it/18fzy3d
@r_bash
Metrics on a bash noscript
Hello all!
Does anyone know some good ways to gather metrics on a bash noscript? I’m doing a report on a noscript and aside from the time command, I can’t think of any other way to gather data about the noscript.
https://redd.it/18g1urs
@r_bash
Hello all!
Does anyone know some good ways to gather metrics on a bash noscript? I’m doing a report on a noscript and aside from the time command, I can’t think of any other way to gather data about the noscript.
https://redd.it/18g1urs
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
OK, I give up. I am search fail. A little grep help please.
I have a file with mostly a crap ton of lines that start with "http".
There are a few lines that start with an English word. A few of those lines are followed by another line which also starts with an English word.
I'd like to grep, or whatever, and get all of the lines that start with a word and are followed by a line with a word, but I only want the fist line displayed in result. eg..
heading
subheading
http..bla...
http..bla...
http..bla...
subheading
http...bla
heading
subheading
http.. bla..
I just want all of the heading lines.
https://redd.it/18guyqu
@r_bash
I have a file with mostly a crap ton of lines that start with "http".
There are a few lines that start with an English word. A few of those lines are followed by another line which also starts with an English word.
I'd like to grep, or whatever, and get all of the lines that start with a word and are followed by a line with a word, but I only want the fist line displayed in result. eg..
heading
subheading
http..bla...
http..bla...
http..bla...
subheading
http...bla
heading
subheading
http.. bla..
I just want all of the heading lines.
https://redd.it/18guyqu
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Techniques and methods for obtaining access to data protected by linux-based encryption – A reference guide for practitioners
https://www.sciencedirect.com/science/article/pii/S2666281723001816
https://redd.it/18h9atw
@r_bash
https://www.sciencedirect.com/science/article/pii/S2666281723001816
https://redd.it/18h9atw
@r_bash
Reddit
From the bash community on Reddit: Techniques and methods for obtaining access to data protected by linux-based encryption – A…
Posted by throwaway16830261 - 1 vote and 1 comment
Just wrote a quick & dirty Bash noscript for debugging a TetherFi issue, what do you think?
The following is a quick and dirty noscript I wrote to help debug a TetherFi issue:
<https://gitlab.com/brlin/tetherfi-debugging-utils/-/blob/v1.0.2/measure-time-between-switching-tetherfi-to-background-and-the-proxy-service-stops-working.sh>
Previously I posted a portion of my noscript for review and the reception is generally quite well, so here's my second attempt! :3
https://redd.it/18hfyp1
@r_bash
The following is a quick and dirty noscript I wrote to help debug a TetherFi issue:
<https://gitlab.com/brlin/tetherfi-debugging-utils/-/blob/v1.0.2/measure-time-between-switching-tetherfi-to-background-and-the-proxy-service-stops-working.sh>
Previously I posted a portion of my noscript for review and the reception is generally quite well, so here's my second attempt! :3
https://redd.it/18hfyp1
@r_bash
GitHub
GitHub - pyamsoft/tetherfusenet: TetherFuseNet - Internet sharing without Root
TetherFuseNet - Internet sharing without Root. Contribute to pyamsoft/tetherfusenet development by creating an account on GitHub.
I want to "cat" some files with unknown names and a small pause in between
This can easly be explained with an example.
I have a directory with several txt files: 1.txt 2.txt 3.txt and I want to read 1.txt, then press enter and read 2.txt, press enter and read 3.txt. Instead of pressing enter I currently just use
​
Problem (or better said challenge, since there are no problems):
When I type
https://redd.it/18hllm1
@r_bash
This can easly be explained with an example.
I have a directory with several txt files: 1.txt 2.txt 3.txt and I want to read 1.txt, then press enter and read 2.txt, press enter and read 3.txt. Instead of pressing enter I currently just use
sleep 5, but I know how to change that later. However, the names are not 1 2 3 but something else I don't know, because I want to use this skript in several directories with different content. ​
Problem (or better said challenge, since there are no problems):
When I type
cat *.txt it will display all .txt files, but I cannot read that fast. I would like to do something like cat 1.txt; sleep 5; clear; cat 2.txt; sleep 5; clear; cat 3.txt; just without typing every filename in there. Is there a way to read the contents of a directory and fill this out automatically?https://redd.it/18hllm1
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Join 2 Bash Arrays in Json using jq
I have two bash arrays.
COLORS=(blue yellow)
FOODS=(cheese ham)
I would like to use jq to combine the two arrays into json that looks something like this.
{
"blue": "cheese",
"yellow": "ham",
}
Or even this
{
"blue": "cheese"
}
{
"yellow": "ham"
}
If not possible I could make it work this way as well, although this would be less preferred.
{
"key1": "blue",
"key2": "cheese",
}
{
"key1": "yellow",
"key2": "ham",
}
Any thoughts on how to do this? Thanks!
https://redd.it/18hmyuv
@r_bash
I have two bash arrays.
COLORS=(blue yellow)
FOODS=(cheese ham)
I would like to use jq to combine the two arrays into json that looks something like this.
{
"blue": "cheese",
"yellow": "ham",
}
Or even this
{
"blue": "cheese"
}
{
"yellow": "ham"
}
If not possible I could make it work this way as well, although this would be less preferred.
{
"key1": "blue",
"key2": "cheese",
}
{
"key1": "yellow",
"key2": "ham",
}
Any thoughts on how to do this? Thanks!
https://redd.it/18hmyuv
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Receive notification at SSH Login
Hi all!
I have a new machine on which I have set up an SSH server. I wanted to setup a little noscript so that I can receive a Telegram notification upon login. Following a few online guides I have put together the following noscript:
#!/usr/bin/env bash
TELEGRAMTOKEN="MYTOKEN"
CHATID="MYCHATID"
# Build the SSH login message
SSHMESSAGE="SSH login detected on $(hostname) at $(date) by user $(whoami) from $(echo $SSHCONNECTION | awk '{print $1}')"
# Send the message to Telegram
curl -s -X POST "https://api.telegram.org/bot$TELEGRAMTOKEN/sendMessage" \
-H 'Content-Type: application/json' \
-d '{"chatid": "'"$CHATID"'", "text": "'"$SSHMESSAGE"'"}' > /dev/null 2>&1
How can I have this running at each SSH login without interfering with the process? I had this set up in the past by modifying the SSH configuration under etc/ssh/sshd_config with
ForceCommand /usr/local/bin/sshloginnotify.sh; CANT REMEMBER
The command in the square bracket was added because initially the noscript would run at login, and log me out immediately after, but I can't remember how I had fixed that.
Ultimately however, completely removed the ForceCommand as it would not let me work remotely using Remote SSH login with Vscode.
Any help on how to set this up properly is highly appreciated, and sorry for my scarce knowledge, I am just getting into this!
https://redd.it/18hmv25
@r_bash
Hi all!
I have a new machine on which I have set up an SSH server. I wanted to setup a little noscript so that I can receive a Telegram notification upon login. Following a few online guides I have put together the following noscript:
#!/usr/bin/env bash
TELEGRAMTOKEN="MYTOKEN"
CHATID="MYCHATID"
# Build the SSH login message
SSHMESSAGE="SSH login detected on $(hostname) at $(date) by user $(whoami) from $(echo $SSHCONNECTION | awk '{print $1}')"
# Send the message to Telegram
curl -s -X POST "https://api.telegram.org/bot$TELEGRAMTOKEN/sendMessage" \
-H 'Content-Type: application/json' \
-d '{"chatid": "'"$CHATID"'", "text": "'"$SSHMESSAGE"'"}' > /dev/null 2>&1
How can I have this running at each SSH login without interfering with the process? I had this set up in the past by modifying the SSH configuration under etc/ssh/sshd_config with
ForceCommand /usr/local/bin/sshloginnotify.sh; CANT REMEMBER
The command in the square bracket was added because initially the noscript would run at login, and log me out immediately after, but I can't remember how I had fixed that.
Ultimately however, completely removed the ForceCommand as it would not let me work remotely using Remote SSH login with Vscode.
Any help on how to set this up properly is highly appreciated, and sorry for my scarce knowledge, I am just getting into this!
https://redd.it/18hmv25
@r_bash
Hacky bashy way to restart a server when frozen?
Whenever a tomcat server inside linux is frozen(by frozen, I mean stops printing logs and gets stuck), I want to restart it, automatically.
What is a bashy way to do it?
https://redd.it/18i1mij
@r_bash
Whenever a tomcat server inside linux is frozen(by frozen, I mean stops printing logs and gets stuck), I want to restart it, automatically.
What is a bashy way to do it?
https://redd.it/18i1mij
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Run a command as a non-root user when logged in as root
I have a noscript that requires root privileges and I don't want to hard code sudo (or doas) in the noscript. Thus, I run the noscript with sudo. So far, so simple.
However, some commands in the noscript have to be run as a non-root user. Is there a way to accomplish this?
https://redd.it/18i8a1r
@r_bash
I have a noscript that requires root privileges and I don't want to hard code sudo (or doas) in the noscript. Thus, I run the noscript with sudo. So far, so simple.
However, some commands in the noscript have to be run as a non-root user. Is there a way to accomplish this?
https://redd.it/18i8a1r
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
ffmpeg and stdout vs stderr
Hi there...
I am aware that ffmpeg outputs everything on screen to stderr. I know how to make it output to stdin, but what I actually want is only the progress stats to output to stdin. Does anyone have an idea on how to accomplish this?
https://redd.it/18i8zpn
@r_bash
Hi there...
I am aware that ffmpeg outputs everything on screen to stderr. I know how to make it output to stdin, but what I actually want is only the progress stats to output to stdin. Does anyone have an idea on how to accomplish this?
https://redd.it/18i8zpn
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Resizing all images in a folder, with GUI progress bar, and total size
I created a simple noscript that uses imagemagick to go through all files in a folder and resize them, but I wanted to improve it, since the only way to monitor the progress of the command was to actually watch the files as they changed sizes (noscript is saved in *\~/.local/share/nautilus/noscripts* so I can access it from a right-click menu).
I also have a habit of checking the folder size before and after, because I like seeing how much space it saved after the noscript has run. There are two noscripts I use, one to resize to 4K (4000px on long edge), and one to resize to 1920 on the long edge.
I learned about *zenity* yesterday, and spent a few hours going through documentation and experimenting with the results. I don't have anyone else to share it with, so here it is!
#!/bin/bash
DIR="."
SIZE_ORIG=`du -h . | cut -f1`
# Starting Count
PROGRESS=0
NUMBER_OF_FILES=`find $DIR -maxdepth 1 -type f -name "*.*" | wc -l`
(for file in *.*; do
PROGRESS=$(( PROGRESS+1 ))
SIZE=`du -h . | cut -f1`
echo "# Resizing $file ... ( $SIZE_ORIG → $SIZE )"
mogrify -resize "1920x1920>" -quality 90% $file; sleep 0
echo $(( 100*$PROGRESS/$NUMBER_OF_FILES ))
done) | zenity --progress --width=420 --noscript "Resizing "$NUMBER_OF_FILES" files..." --percentage=0
The result looks like this:
​
https://preview.redd.it/mek0ykrts96c1.png?width=789&format=png&auto=webp&s=846aea13d344c3dee04e296c1e98e22c8671abfd
https://redd.it/18i9upl
@r_bash
I created a simple noscript that uses imagemagick to go through all files in a folder and resize them, but I wanted to improve it, since the only way to monitor the progress of the command was to actually watch the files as they changed sizes (noscript is saved in *\~/.local/share/nautilus/noscripts* so I can access it from a right-click menu).
I also have a habit of checking the folder size before and after, because I like seeing how much space it saved after the noscript has run. There are two noscripts I use, one to resize to 4K (4000px on long edge), and one to resize to 1920 on the long edge.
I learned about *zenity* yesterday, and spent a few hours going through documentation and experimenting with the results. I don't have anyone else to share it with, so here it is!
#!/bin/bash
DIR="."
SIZE_ORIG=`du -h . | cut -f1`
# Starting Count
PROGRESS=0
NUMBER_OF_FILES=`find $DIR -maxdepth 1 -type f -name "*.*" | wc -l`
(for file in *.*; do
PROGRESS=$(( PROGRESS+1 ))
SIZE=`du -h . | cut -f1`
echo "# Resizing $file ... ( $SIZE_ORIG → $SIZE )"
mogrify -resize "1920x1920>" -quality 90% $file; sleep 0
echo $(( 100*$PROGRESS/$NUMBER_OF_FILES ))
done) | zenity --progress --width=420 --noscript "Resizing "$NUMBER_OF_FILES" files..." --percentage=0
The result looks like this:
​
https://preview.redd.it/mek0ykrts96c1.png?width=789&format=png&auto=webp&s=846aea13d344c3dee04e296c1e98e22c8671abfd
https://redd.it/18i9upl
@r_bash
TIL to continue too
So I have this wee app (bash function),
I do ignore
But I still don't want to see them in this app, they're not often inetresting.
So I asked the GPT how to add my own ignores list, and it suggested
declare -a CUSTOMIGNORES=("fred" "." "*.cd")
for file in $(gitstatuslinedirchanges); do
[ -f "$file_" ] || continue
git check-ignore -q "$file" && continue
for ignore in "${CUSTOMIGNORES@}"; do
[ "$file_" == *"$ignore"* ] && continue 2
done
done
I've been writing bash for 30+ years, I never knew you could
HTH you next week, ...
https://redd.it/18if7qa
@r_bash
So I have this wee app (bash function),
gsi, which loops through files in a git clone, offering actions on each. And it showed me the dir fred/ today. I do ignore
fred.* files in git, but I don't ignore fred/ dirs, could be intersting stuff in them. But I still don't want to see them in this app, they're not often inetresting.
So I asked the GPT how to add my own ignores list, and it suggested
declare -a CUSTOMIGNORES=("fred" "." "*.cd")
for file in $(gitstatuslinedirchanges); do
[ -f "$file_" ] || continue
git check-ignore -q "$file" && continue
for ignore in "${CUSTOMIGNORES@}"; do
[ "$file_" == *"$ignore"* ] && continue 2
done
done
I've been writing bash for 30+ years, I never knew you could
continue 2.HTH you next week, ...
https://redd.it/18if7qa
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Why is this bash command not doing anything on macOS?
For some reason following command doesn't work on macOS in bash. It does work on other linux machine. Any idea why it doesn't work on macOS?
Just
https://redd.it/18ihhfm
@r_bash
For some reason following command doesn't work on macOS in bash. It does work on other linux machine. Any idea why it doesn't work on macOS?
~ $ du -cBG . --max-depth=1 2>/dev/null | sort -n~ $ ~ $ which $SHELL/bin/bashJust
du works.https://redd.it/18ihhfm
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to grep a word where I only know the beginning and end of the word?
Let's say I have a long text and I want to find words that start with a and end with n. I thought I could simply
https://redd.it/18imi6b
@r_bash
Let's say I have a long text and I want to find words that start with a and end with n. I thought I could simply
grep -o a*n but this will get me no results, even tho those words exist. I guess grep tries to find a three letter word that is a * and n. What can I use here to express an unknown string in between the a and n?https://redd.it/18imi6b
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Curl - Collection history fzf support
Hello
Are there any CLI utility that you came across where I can do the following using Curl
\- History of the past requests
\- Store it as a collection
\- Search using fzf like utility.
If none, anyone interested to build such a thing and I can initiate a thread on that.
​
https://redd.it/18it5fk
@r_bash
Hello
Are there any CLI utility that you came across where I can do the following using Curl
\- History of the past requests
\- Store it as a collection
\- Search using fzf like utility.
If none, anyone interested to build such a thing and I can initiate a thread on that.
​
https://redd.it/18it5fk
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
What sed delimiter to use when all are being ued in my variable?
i have a txt file with a bunch of youtube video noscripts (alot of witch contain / , # , | ... and pretty much all special chars i can think of) i then need to add that to a second file (at the beginning of the second file) useing sed -i "1s/ ( here goes that video noscript) /" (the second txt file) . Should i maybe use something else than sed?
To specify my situation: i loop trough all lines in the first txt and if that youtube noscript does not exist in the second file i add it to the beginning of the second file with sed -i "1s/ $(that line as a varibale) /" second_file.txt
https://redd.it/18iwi2y
@r_bash
i have a txt file with a bunch of youtube video noscripts (alot of witch contain / , # , | ... and pretty much all special chars i can think of) i then need to add that to a second file (at the beginning of the second file) useing sed -i "1s/ ( here goes that video noscript) /" (the second txt file) . Should i maybe use something else than sed?
To specify my situation: i loop trough all lines in the first txt and if that youtube noscript does not exist in the second file i add it to the beginning of the second file with sed -i "1s/ $(that line as a varibale) /" second_file.txt
https://redd.it/18iwi2y
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Double brackets quirk
Hi,
While I was messing with my code, I made what I thought was a typo but it seems to work anyway.
Notice how I'm not referencing the array item with ${codei}.
codes=(101 202 303)
i=0
echo $(( codesi == 101 ))
-> 1
echo $(( codesi == 202 ))
-> 0
What am I missing here? Is it a know behavior? I couldn't find anything in the references.
https://redd.it/18ixixg
@r_bash
Hi,
While I was messing with my code, I made what I thought was a typo but it seems to work anyway.
Notice how I'm not referencing the array item with ${codei}.
codes=(101 202 303)
i=0
echo $(( codesi == 101 ))
-> 1
echo $(( codesi == 202 ))
-> 0
What am I missing here? Is it a know behavior? I couldn't find anything in the references.
https://redd.it/18ixixg
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Background Processes kept running after exiting
Hi all, first time poster here. Hope this is the right place. I was ssh’d into a server that I work on, where I was running a few processes in the background like this
- ./noscript &
I accidentally exited the server, and thought the processes would have ended. But they kept going and seemingly finished. Why is that? Can I trust that everything was done right? Thanks!
https://redd.it/18j0h5u
@r_bash
Hi all, first time poster here. Hope this is the right place. I was ssh’d into a server that I work on, where I was running a few processes in the background like this
- ./noscript &
I accidentally exited the server, and thought the processes would have ended. But they kept going and seemingly finished. Why is that? Can I trust that everything was done right? Thanks!
https://redd.it/18j0h5u
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Variable substitution in a command
So I'm making this bash noscript that essentially transfers files from a source directory to a destination directory and organises them based on their extensions. I've completed this part but now I want to add a flag to exclude certain extensions like -e. I have done this with getopts and it's working fine.
The problem I'm encounterung is while executing the find command that gets me the file paths. I'm building the conditional string based on the input to the -e flag.
The code for this part :
declare excluded_extensions="-name '*.*'"
if [ ! "$excluded_extensions" == "-name '*.*'" ]; then
extension_string="-not \("
for ext in $excluded_extensions; do
extension_string+=" -name '*.$ext' -o"
done
extension_string="${extension_string:0:-2}"
extension_string+="\)"
fi
The logic is that I set a default value to the variable which is `-name '*.*'`. So if the user doesn't want to exclude any extensions (so the -e is not used) the variable value is substituted as is : `-name '*.*'` which means find all files in the directory. But if there are any extensions specified by the user then it builds the string and it becomes `-not /( -name ext1 -o -name ext2 /)` and so on. Then the value is substituted in the find command:
`find source_dir -type f $extension_string`
This is to get all the file paths
I've echoed the content of the command with the string based on various inputs and the value is showing up properly formatted in the terminal.
However when I run it there's an error with find :
`find:paths must precede expression : ``\('``
I know the code and method is very messy so I would really appreciate any help or even if there's a better strategy to this. Researched a lot for this problem on stack overflow, chatgpt but no answer. Thanks in advance. Kindly let me know if there's anything more that I should explain about the noscript, I'll gladly do so.
https://redd.it/18j79wk
@r_bash
So I'm making this bash noscript that essentially transfers files from a source directory to a destination directory and organises them based on their extensions. I've completed this part but now I want to add a flag to exclude certain extensions like -e. I have done this with getopts and it's working fine.
The problem I'm encounterung is while executing the find command that gets me the file paths. I'm building the conditional string based on the input to the -e flag.
The code for this part :
declare excluded_extensions="-name '*.*'"
if [ ! "$excluded_extensions" == "-name '*.*'" ]; then
extension_string="-not \("
for ext in $excluded_extensions; do
extension_string+=" -name '*.$ext' -o"
done
extension_string="${extension_string:0:-2}"
extension_string+="\)"
fi
The logic is that I set a default value to the variable which is `-name '*.*'`. So if the user doesn't want to exclude any extensions (so the -e is not used) the variable value is substituted as is : `-name '*.*'` which means find all files in the directory. But if there are any extensions specified by the user then it builds the string and it becomes `-not /( -name ext1 -o -name ext2 /)` and so on. Then the value is substituted in the find command:
`find source_dir -type f $extension_string`
This is to get all the file paths
I've echoed the content of the command with the string based on various inputs and the value is showing up properly formatted in the terminal.
However when I run it there's an error with find :
`find:paths must precede expression : ``\('``
I know the code and method is very messy so I would really appreciate any help or even if there's a better strategy to this. Researched a lot for this problem on stack overflow, chatgpt but no answer. Thanks in advance. Kindly let me know if there's anything more that I should explain about the noscript, I'll gladly do so.
https://redd.it/18j79wk
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
I don't understand what is going on here.
I have a noscript that parse command line for flags that modify the noscript behaviour.
By accident, I typed invoking the noscript on cmd line with "=v" instead of "-v" and for my surprise, looks like its breaks getopts somehow because looks like that none of flags are processed in the `while getopts` loop:
```
....
set -o errexit -o nounset -o noclobber -o pipefail
trap go_exit EXIT SIGHUP SIGQUIT SIGTERM
export LC_ALL=C
...
while getopts "s:d:r:hnv" OPTION; do
case $OPTION in
s)
f_src=1
src="${OPTARG}" ;;
d)
f_dst=1
dst="${OPTARG}" ;;
r)
f_regex=1
regex="${OPTARG}" ;;
h)
usage ;;
v)
f_verbose=1 ;;
n)
f_dry=1 ;;
:)
echo "Option -${OPTARG} requires an argument." > /dev/sdtderr
usage
;;
?)
echo "unknow argument." > /dev/sdtderr
usage ;;
esac
done
# sanity checks
if [ "$f_src" == "0" ]; then
echo "Usage: the source folder must be specified." > /dev/stderr
usage
fi
```
All sanity checks that test the f_whatever=0, succeed (as f_whatever are all equal to 0, but it shouldn't as I am passing -s, -d, -r, -n.... - except instead -v it is =v)
Another question related to `set -o errexit .. trap go_exit EXIT `:
If there is any error during the execution the program simply call the go_exit as intended.
How to I get a feedback of which error generated the TRAP and where ?
https://redd.it/18jnvok
@r_bash
I have a noscript that parse command line for flags that modify the noscript behaviour.
By accident, I typed invoking the noscript on cmd line with "=v" instead of "-v" and for my surprise, looks like its breaks getopts somehow because looks like that none of flags are processed in the `while getopts` loop:
```
....
set -o errexit -o nounset -o noclobber -o pipefail
trap go_exit EXIT SIGHUP SIGQUIT SIGTERM
export LC_ALL=C
...
while getopts "s:d:r:hnv" OPTION; do
case $OPTION in
s)
f_src=1
src="${OPTARG}" ;;
d)
f_dst=1
dst="${OPTARG}" ;;
r)
f_regex=1
regex="${OPTARG}" ;;
h)
usage ;;
v)
f_verbose=1 ;;
n)
f_dry=1 ;;
:)
echo "Option -${OPTARG} requires an argument." > /dev/sdtderr
usage
;;
?)
echo "unknow argument." > /dev/sdtderr
usage ;;
esac
done
# sanity checks
if [ "$f_src" == "0" ]; then
echo "Usage: the source folder must be specified." > /dev/stderr
usage
fi
```
All sanity checks that test the f_whatever=0, succeed (as f_whatever are all equal to 0, but it shouldn't as I am passing -s, -d, -r, -n.... - except instead -v it is =v)
Another question related to `set -o errexit .. trap go_exit EXIT `:
If there is any error during the execution the program simply call the go_exit as intended.
How to I get a feedback of which error generated the TRAP and where ?
https://redd.it/18jnvok
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community