4 ms·
Oh yeah, bash functions are great and absolutely abusable. Sometimes you need some grand hacks to get it to work well, but when it works well, it can do some ma
by chaps 5y ago
Oh yeah, bash functions are great and absolutely abusable. Sometimes you need some grand hacks to get it to work well, but when it works well, it can do some magic. You can even export functions over ssh!
I wrote this a few years back which ran on bunches of hosts and fed into an infrastructure network mapper based on each hosts' open network sockets to other known hosts. It wasn't really feasible to install a set of tools on random hosts.. but I still had root ssh access across the board. So I needed something tool agnostic, short, auditable, and effectively guaranteed to work:
https://github.com/red-bin/lsofer/blob/master/lsofer.sh https://github.com/red-bin/lsofer/blob/master/lsofer.sh
- throwawaygh 5y ago> You can even export functions over ssh! What does "export" mean in this context? Do you just mean `ssh host cmd` where cmd is some shell that happens to contain (and call) a function?
- xyzzy_plugh 5y agoProbably implying use of `declare -pf` to turn functions into strings which can be evaluated by a remote shell.
- chaps 5y agoExactly -- check out script in the link, it shows how it would be used. I'm not sure why the first `remote_cmd` is called (probably local testing and forgot to delete it), so ignore that. Try this and you'll see how it returns a dramatic amount of bash as its output: remote_cmd="`typeset -f` ; function test123 { echo hi! ; }" && echo -e $remote_cmd
- throwawaygh 5y agoAh, makes sense! Yeah, that's nice. You can do something similar with scripting languages by piping source code into the interpreter. Super useful back in the day for doing crap on machines in an LSF cluster when the NFS was down/slow.