Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Volguus
Mar 3, 2009

neurotech posted:

What does chmod u+x do? I normally just do chmod +x

https://linux.die.net/man/1/chmod

u - means user

That is, make the script executable for the current user. "g" would mean group, and "a" means all. "o" - not in the group.

Adbot
ADBOT LOVES YOU

neurotech
Apr 22, 2004

Deep in my dreams and I still hear her callin'
If you're alone, I'll come home.

Cool, thank you.

neurotech
Apr 22, 2004

Deep in my dreams and I still hear her callin'
If you're alone, I'll come home.

hifi posted:

If it only runs the first one then it's returning something other than zero; '&&' is a logical AND, so if the first one is false then there's no way the entire statement can be anything other than false.

How do I debug this? Is there an equivalent of try/catch for bash scripts?

hifi
Jul 25, 2012

neurotech posted:


Where should I be putting scripts like this ideally?


If you echo $PATH and there are directories that are in your user folder, then you can move them into that directory and execute them without the path, eg how you would run 'ls'. If there aren't any then you have to make ~/.bin or ~/tools or whatever sounds nice and then add it to your path and restart your session before you can do that.

Yaoi Gagarin
Feb 20, 2014

neurotech posted:

Thanks for those replies, that is a huge help.

AFAICT yt-dlp is not returning any errors.
Adding $SHELL to the end is (supposedly) to ensure the script doesn't kill my shell and drop my ssh connection. At least that's what superuser says haha

Where should I be putting scripts like this ideally?

What does chmod u+x do? I normally just do chmod +x

get rid of $SHELL and the exec. idk what your superuser answer is up to, it must have been for someone's very specific problem.

put the script anywhere you want in your home directory as long as its on your $PATH. you can check the value of $PATH by doing `echo $PATH` in your terminal. if you dont have anywhere then you can add one in your .bashrc, for example if i wanted to add a directory named ~/lmao I could add this line to .bashrc:

export PATH="$PATH:$HOME/lmao"

hifi
Jul 25, 2012

neurotech posted:

How do I debug this? Is there an equivalent of try/catch for bash scripts?

'set -x' will print everything that gets run. I dont really know how it works with exec and bash -c, etc

Yaoi Gagarin
Feb 20, 2014

first thing for that is to just run that command normally and then run `echo $?` to see what the return code was

Saukkis
May 16, 2003

Unless I'm on the inside curve pointing straight at oncoming traffic the high beams stay on and I laugh at your puny protest flashes.
I am Most Important Man. Most Important Man in the World.

neurotech posted:

AFAICT yt-dlp is not returning any errors.
Adding $SHELL to the end is (supposedly) to ensure the script doesn't kill my shell and drop my ssh connection. At least that's what superuser says haha

That sounds like a weird idea, never seen that used before. If you have the link to that advice I'd be interested to see it.

I suspect the $SHELL is also the reason why your command chaining doesn't work, 'music url2' will only be executed after 'music url1' finishes, but it never does since it's running your new shell. If you run your script a bunch of times and then run 'pstree' you will probably see several nested music- and bash-processes.

Also, you may want to use 'music url1 ; music url2' instead. '&&' is used in a situation where you don't want the second command to execute if the first one wasn't succesful.

Volguus
Mar 3, 2009

neurotech posted:

How do I debug this? Is there an equivalent of try/catch for bash scripts?

Welcome to debugging in bash, haha. As other have said, 'set -x' is your friend. Check out this page that has a couple of more helpful flags: https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425

Other than that, don't go too crazy with scripts.A few lines is fine, for more complex stuff just pick your favourite scripting language and solve your problem there.

Saukkis posted:

Also, you may want to use 'music url1 ; music url2' instead. '&&' is used in a situation where you don't want the second command to execute if the first one wasn't succesful.

The || operator exist too and does what it should (OR).

Volguus fucked around with this message at 02:10 on Mar 12, 2024

Yaoi Gagarin
Feb 20, 2014

im like 99% sure the script will work just fine without the exec in the alias and the $SHELL at the end lol

Saukkis
May 16, 2003

Unless I'm on the inside curve pointing straight at oncoming traffic the high beams stay on and I laugh at your puny protest flashes.
I am Most Important Man. Most Important Man in the World.

Volguus posted:

Welcome to debugging in bash, haha. As other have said, 'set -x' is your friend. Check out this page that has a couple of more helpful flags: https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425

Another option is to run it with 'bash -x script', so there isn't need to edit the file.

neurotech
Apr 22, 2004

Deep in my dreams and I still hear her callin'
If you're alone, I'll come home.

Yeah. It works nicely with the exec and $SHELL removed. Thanks everyone.


Saukkis posted:

That sounds like a weird idea, never seen that used before. If you have the link to that advice I'd be interested to see it.

I suspect the $SHELL is also the reason why your command chaining doesn't work, 'music url2' will only be executed after 'music url1' finishes, but it never does since it's running your new shell. If you run your script a bunch of times and then run 'pstree' you will probably see several nested music- and bash-processes.

Also, you may want to use 'music url1 ; music url2' instead. '&&' is used in a situation where you don't want the second command to execute if the first one wasn't succesful.
https://askubuntu.com/questions/20330/how-to-run-a-script-without-closing-the-terminal

Yaoi Gagarin
Feb 20, 2014

just to explain why that question is different from your situation - they want to run the script with a double-click and have it leave the terminal open. you are just trying to run the script from an already open terminal. in your case when the script finishes running you just get back to your current shell anyway.

neurotech
Apr 22, 2004

Deep in my dreams and I still hear her callin'
If you're alone, I'll come home.

Yaoi Gagarin posted:

just to explain why that question is different from your situation - they want to run the script with a double-click and have it leave the terminal open. you are just trying to run the script from an already open terminal. in your case when the script finishes running you just get back to your current shell anyway.

Much appreciated, that makes sense.

hifi
Jul 25, 2012

neurotech posted:

Yeah. It works nicely with the exec and $SHELL removed. Thanks everyone.

https://askubuntu.com/questions/20330/how-to-run-a-script-without-closing-the-terminal

No, that guy's problem is like if you have a .bat file in windows and you double click it and it opens an instance of cmd.exe disappears instantly

Inceltown
Aug 6, 2019

neurotech posted:

pre:
music url1 && music url2

Just as a side note to all the stuff you've got, you can use $@ so the script will read an arbitrary number of file names instead of having to chain together
code:
music url1; music url2
It would be
code:
music url1 url2 url<n>

neurotech
Apr 22, 2004

Deep in my dreams and I still hear her callin'
If you're alone, I'll come home.

Inceltown posted:

Just as a side note to all the stuff you've got, you can use $@ so the script will read an arbitrary number of file names instead of having to chain together
code:
music url1; music url2
It would be
code:
music url1 url2 url<n>

Ahhh that's perfect, thanks.

Klyith
Aug 3, 2007

GBS Pledge Week

Inceltown posted:

Just as a side note to all the stuff you've got, you can use $@ so the script will read an arbitrary number of file names instead of having to chain together
code:
music url1; music url2
It would be
code:
music url1 url2 url<n>

More familiar with Windows command line than linux, I started to say "Up to the max length for commands, which you can fill up with long url strings faster than you'd think."

And then I thought "but what's the Linux maximum?" Turns out it's variable, but you can run a command to see your local limit: getconf ARG_MAX

Suffice to say, you can download a whole lot of youtubes.

Yaoi Gagarin
Feb 20, 2014

is there something that works like cat, but it can print some kind of header before each file telling you what the name of that file was? I can script this myself but I want to know if there's already a tool for it

pseudorandom name
May 6, 2007

If it is something that can be done in five seconds as a one line script at the prompt itself then you can assume that nobody has bothered to write a tool for it.

xzzy
Mar 5, 2009

'more' will do that, assuming you don't mind hitting a key for the pages. It doesn't look like it has an option to skip pagination.

But if you pipe it to cat you get what you want. :v:

tjones
May 13, 2005
tail -vn+0 $file

Klyith
Aug 3, 2007

GBS Pledge Week

Yaoi Gagarin posted:

is there something that works like cat, but it can print some kind of header before each file telling you what the name of that file was? I can script this myself but I want to know if there's already a tool for it

here's my "cat all the files in this directory":

code:
alias catstar='for file in *; do echo -e "\n--- $file ---"; cat "$file"; done'
which I made for looking at stuff in /sys

OnceIWasAnOstrich
Jul 22, 2006

Among other things bat will do this and many other overly-fancy cat things.

xzzy
Mar 5, 2009

This may end up just being rubber ducking but I'll try anyways:

We have a requirement to run a firewall on our linux systems (using nftables) and also a requirement to let users run podman containers AND expose ports to those containers. There's two issues with that: for one podman doesn't support nftables yet, and for two, podman seems to assume you're running a blank firewall so there's not really any documentation on how to actually fit it into an existing management setup.

Fortunately the first problem is simple, podman makes its iptables rules and for the most part they "just work" alongside the nftables rules. Containers can reach the world, containers can talk to each other, and dns is working.

The second one is being an rear end in a top hat though. Our FORWARD chain has a default drop policy as well as a reject at the end of the chain. So I need to craft a rule to accept traffic when it hits a certain port. If I got a container run with something 'podman run -dt -p 8080:80 quay.io/libpod/banner' I would expect I need to open up port 8080 to the world (eg, tcp dport 8080 counter accept). However it doesn't work, but if I instead use a rule like 'tcp dport 80 counter accept' external access works.

This feels like a misunderstanding of packet mangling inside the kernel. Does this mean the forward chain is being processed after nat translation so the 8080 dport is "lost"? I don't have a great concept of packet flow in the kernel despite much time scrolling around on the flowchart image that's available and I find it very hard to debug single packets because as near as I can tell there's no tools for it. Is there some other field in these incoming packets I can filter on? Or some kind of modification in prerouting that I can make that helps?

I guess worst case I can just filter on the internal port of the containers but that feels bad and dumb to me.

Alternatively I can change the forward change to a default accept policy. That feels like bad practice but is it really? The forward chain only gets parsed when the system is trying to route a packet so maybe the methods of attack are pretty insignificant.

xzzy
Mar 5, 2009

After sleeping/thinking on it I came up with using marks to fix this.

In prerouting I added a rule to set a mark on any packet that hits a port I want to be world accessible, eg 'counter tcp dport 8080 meta mark set 1'.

Then in my forward chain I added a rule to accept any packet with that mark set that is also destined for the podman subnet, eg 'ip daddr 10.88.0.0/16 meta mark 1 counter accept'

This does what I want but I am unsure if this is a sane practice or is an idiot decision that will break later in ways I am too dumb to predict.

Woolie Wool
Jun 2, 2006


skooma512 posted:

So I want to try dual booting again and using Linux as my desktop beyond just the container platforms I use now.

I'm gonna section off a piece of my boot drive for it. For games and such is it ok if I just the NTFS drives as is and install stuff to those/use the games that are already there or should I aim to have an ext4 partition? I'm trying to avoid making new partitions or disrupting the file system as much as possible, but I'm otherwise comfortable with the mechanics of doing so.

In my experience using NTFS to run modern games on Linux works but is very slow. Not a problem with old games but a big problem with modern AAA titles. Also you must make sure the drive is mounted such that your user owns it, not root, because chown does not seem to work properly on NTFS.

Woolie Wool fucked around with this message at 22:02 on Mar 13, 2024

mila kunis
Jun 10, 2011
drat, installing TLP seems to have made a big difference to power consumption on my laptop. Inflection point here is where I installed it. Wasn't doing much but browsing and youtube, power consumption before seemed pretty abnormally high

RFC2324
Jun 7, 2012

http 418

sericea is pretty wild. an immutable distro with all text file editing for configs.

its giving me serious whiplash lol. what decade is it?

Kibner
Oct 21, 2008

Acguy Supremacy

RFC2324 posted:

sericea is pretty wild. an immutable distro with all text file editing for configs.

its giving me serious whiplash lol. what decade is it?

I've been using it for a couple weeks now. I think I really like tiling window managers. I have had some issues with things, but that is more related to the immutable distro and primarily using containerized apps part.

The toolbox is cool. An even easier way to manage podman containers that need access to some of your user's files. I tend to create one for each coding project I am working on in order to prevent any kind of dependency issues. I also have one to run virt-manager for my Windows VM so that I can watch NBA League Pass (they blocked out Linux from accessing it a year or so ago) and also update the firmware of some of my devices that don't have Windows utils working. I still need to figure out how to get USB redirecting working for that part, though. Getting an error when trying to do it through virt-manager.

I have had some sound issues, too, but I think that is mostly a thing with the niche audio devices I use more than anything else. Most of it has worked pretty well. Flatseal has been a wonderful tool.

ziasquinn
Jan 1, 2006

Fallen Rib
Idk if its my networking on Windows or what but I was getting loads of connection and prediction errors in Apex, so on a lark I reinstalled Arch and switched over it for a night and it was like butter.

"Hold I gotta boot up my Linux drive to play games guys, sorry!" words spoken by the utterly deranged

RFC2324
Jun 7, 2012

http 418

Kibner posted:

I've been using it for a couple weeks now. I think I really like tiling window managers. I have had some issues with things, but that is more related to the immutable distro and primarily using containerized apps part.

The toolbox is cool. An even easier way to manage podman containers that need access to some of your user's files. I tend to create one for each coding project I am working on in order to prevent any kind of dependency issues. I also have one to run virt-manager for my Windows VM so that I can watch NBA League Pass (they blocked out Linux from accessing it a year or so ago) and also update the firmware of some of my devices that don't have Windows utils working. I still need to figure out how to get USB redirecting working for that part, though. Getting an error when trying to do it through virt-manager.

I have had some sound issues, too, but I think that is mostly a thing with the niche audio devices I use more than anything else. Most of it has worked pretty well. Flatseal has been a wonderful tool.

Im genuinely enjoying it, and think I am going to use it for my new work machine. Its a terrible idea for a gaming rig, but amazing for a work machine. Toolbox immediately made me start thinking how to use it to make sysadmin better

Kibner
Oct 21, 2008

Acguy Supremacy

RFC2324 posted:

Im genuinely enjoying it, and think I am going to use it for my new work machine. Its a terrible idea for a gaming rig, but amazing for a work machine. Toolbox immediately made me start thinking how to use it to make sysadmin better

I'm actually using it for gaming, too! :v:

Only Steam games, so far, and the only unexpected problem has been needing to switch away from my 24-input mixer to my stereo DAC in order before launching some games in order to get sound to work. I can switch audio devices back to my mixer after the game finishes launching and it gets sound just fine. Just can't launch with it as the default device.

Still need to install Battle.Net and I am messing around with trying to get the old game Asheron's Call working, too. But, hey, that is what Lutris and company are for!

I think the one thing that I have not found a fix or work around for is having my notifications go to my top monitor (I have a vertical stack). The bottom monitor is my main monitor both in how I use it and how the Sway sees it (because my primary monitor has the "first" virtual desktop). System notifications just seem to default to the top monitor for whatever reason.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Kibner posted:

the only unexpected problem has been needing to switch away from my 24-input mixer to my stereo DAC in order before launching some games in order to get sound to work. I can switch audio devices back to my mixer after the game finishes launching and it gets sound just fine. Just can't launch with it as the default device.

This is why Linux is so dangerous for me. There’s a decent chance that I would hit this and then end up pulling source for the whole dependency chain of the audio system, and then I spend two weeks becoming an audio-sampling-and-buffering Guy to no practical avail except that I’m now on 3 additional mailing lists and am following two dozen noisy GitHub issues.

On Windows I just try updating drivers, rebooting, maybe poking in device manager, and then give up and live with it.

cruft
Oct 25, 2007

Subjunctive posted:

This is why Linux is so dangerous for me. There’s a decent chance that I would hit this and then end up pulling source for the whole dependency chain of the audio system, and then I spend two weeks becoming an audio-sampling-and-buffering Guy to no practical avail except that I’m now on 3 additional mailing lists and am following two dozen noisy GitHub issues.

On Windows I just try updating drivers, rebooting, maybe poking in device manager, and then give up and live with it.

Get out of my head.

Back in the early aughts, I bought a Sharp Zaurus, and immediately replaced the entire operating system with an open source fork. I didn't like how it booted, and set about fixing it. That lasted about a year, during which time my Zaurus was essentially inoperable. Moving to a Palm Pilot was great, because it didn't allow me to break the locked-down OS in an attempt to improve it.

Great memories of debugging early userspace initialization scripts on a moving bus using the craptastic keyboard and a 6-pixel tall console font.

cruft fucked around with this message at 17:18 on Mar 14, 2024

Kibner
Oct 21, 2008

Acguy Supremacy
Well, I fixed the notification issue just now. I found the default config file at /usr/etc/xdg/dunst/dunstrc

I copied it to ~/.config/dunst/dunstrc and changed the line "monitor = 0" to "monitor = 1" and then restarted my session. Tested it with the command `dunstify "title" "content"` and it works how I want!

I also learned that you can change the "follow = none" line to "follow = keyboard" or "follow = mouse" and the notifications will pop-up accordingly. For Wayland, both keyboard and mouse options work the same.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

FYI, while Toolbox is totally fine, there's little reason not to install Distrobox.

They're both wrappers around podman, but Distrobox has some important improvements like automatic export of desktop apps and restricting container mounts to something other than your full $home.

Woolie Wool
Jun 2, 2006


Is there a way to force a fullscreen program to run on a specific monitor on KDE/Wayland from the console? There are some games I would like to play on my CRT which is set as my secondary monitor, and often they don't respond well to using Alt+F3 to try to relocate them.

ziasquinn
Jan 1, 2006

Fallen Rib

Woolie Wool posted:

Is there a way to force a fullscreen program to run on a specific monitor on KDE/Wayland from the console? There are some games I would like to play on my CRT which is set as my secondary monitor, and often they don't respond well to using Alt+F3 to try to relocate them.

I just use a keyboard shortcut to point to Arandr script to change the Primary Monitor before launching the game (for Xorg, ofc) but I'm sure there's a similar one for Wayland?

Reddit says:

Plasma's tool is kscreen-doctor, kscreen-doctor --help for an introduction. (oh this is a Xrandr replacement, not Arandr, but I'm sure it'd work similarly).

Alternatively, idk since you're talking KDE: https://github.com/maxwellainatchi/gnome-randr-rust

Adbot
ADBOT LOVES YOU

Klyith
Aug 3, 2007

GBS Pledge Week
Another option is to use gamescope, which both
a) can set a display output via command line
b) is probably helpful for games with janky response to window repositioning / resize / alt-tab (as it is containing the game inside a dedicated micro-compositor and doesn't let the game know about such things)

So if I wanted to run a steam game on my second monitor, I could do it with:
gamescope -W 1680 -H 1050 -f --display-index 1 -- %command%



I'm kinda 50/50 on gamescope, some games it's very helpful and some game it causes some small problems that seem pretty unique to itself. So I generally don't reach for it unless there are already issues. (OTOH I don't have a VRR monitor, a CRT, or other unusual stuff.)

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply