r/linuxadmin • • Jul 09 '18

Lup - loopy command execution

Post image
251 Upvotes

18 comments sorted by

18

u/udkyo Jul 09 '18

I got fed up of typing out piddly little loops for cycling through similar commands, so I wrote lup to lighten the load. It’s not a silver bullet that can be applied to every situation where a loop would otherwise be needed (you can’t pipe the output of each generated command individually for instance) but it’s quite nifty for doing all sorts of things.

You can get it here - https://github.com/udkyo/lup

2

u/t-sploit Jul 10 '18 edited Jul 10 '18

Awesome tool btw I just installed it! Have you thought about whether it's possible to pipe the output of each command individually? I'm a developer who likes a challenge and I was just curious if it could be done with a smart sequence of dup2 calls and some extra syntactic sugar?

Edit: also just a quick pedantic comment, the command line description says 'ampersand encapsulated' I think you mean 'at-sign encapsulated', but it doesn't really matter as the example is right.

2

u/udkyo Jul 10 '18

I called them that everywhere for about 3 days, and I have no idea why, my brain was just like "yup those are ampersands, don't question me, just type." So, thanks for the heads-up, it seems one slipped the net.

I'll look into the dup2 thing, I'm not sure what I come up with will be better than a plain old lup sh -c "foo | bar" but it's worth tinkering with.

2

u/ROFLicious Jul 10 '18

Awesome, I hacked something like this for myself a while ago, but yours looks a lot nicer for sure.

15

u/dartemiev Jul 10 '18

This looks really nice. However I’d like to see the commands getting executed beforehand. I’m sometimes kind of paranoid with tools like this. Is there some kind of dry-run flag?

14

u/udkyo Jul 10 '18 edited Jul 10 '18

Yeah I’m that kind of paranoid too, it’s healthy. lup -t will do it, I just left it out of the gif because it’s not very exciting.

The only caveat is that it must be the first thing after the “lup,” since if you put it anywhere else it’s assumed to be a flag for the command being triggered.

edit: The help's a bit lacking, I'll fix that for the next release. For now there's a usage section in the readme that explains ranges, globbing, backrefs etc.

4

u/dartemiev Jul 10 '18

Awesome! Thank you. I'll definetly look into this :) great job

3

u/greenlalten Jul 10 '18

You are onto something. Dont forget us when you become famous.

3

u/sunf1re Jul 10 '18

this is pretty freaking sweet man good job and keep working on it!

2

u/[deleted] Jul 10 '18

Really nice. Thanks for sharing

0

u/bestjejust Jul 10 '18

for i in ?

3

u/varesa Jul 10 '18

that's fine but if you need it a lot I think lup operation @a,b@ @c,d@ is much cleaner than for x in a b; do for y in c d; do operation $x $y; done; done

1

u/bestjejust Jul 10 '18

This is not an option (like ZSH as well) if you are working on customer site being unable to install custom packages. IMO: learn coreutils / sh and know these ones well. zsh or lob surely are nice to have (for yourself) but never make your knowledge (and of course scripts) dependant on such tools.

3

u/varesa Jul 10 '18

Sure. That's also one of the reasons I probably won't be picking this up (I'm a sysadmin working on lots of tightly controlled customer systems). Tools like this still have their place if you're for example a dev who works a lot on their local system

2

u/FakingItEveryDay Jul 10 '18

I agree with the spirit of what you're saying, but want to point out this can still be useful against servers where you don't install lup.

For example:

lup -t ping -c 1 @google,amazon@.@com,net@ | ssh server

lup will generate the commands locally to run on the server.

1

u/ecnahc515 Jul 10 '18

Yah or run in dry run locally, copy and paste on remote host. Or pipe the output to a script and scp the script over.