Earlier quoted context omitted.
make a small change: for host in ... ; do ssh -l root $host "..." & done; wait and it's very parallel. All that key exchange takes a while, so it's not ridiculously fast, but it's pretty good. If you've got ControlMaster set up already to be per-host, this might very well be very fast the second time.
You may want to look into using GNU parallel with that.
Unix Commands I Wish I’d Discovered Years Earlier
161–170 of 259 posts
Re: Unix Commands I Wish I’d Discovered Years Earlier
#162One of the more useful bits of ssh is not mentioned: remotely running commands. Example: ssh username@host "echo $HOSTNAME && sudo somecommand && cat somecommand.log" There's probably a better way to do this, but in a pinch I can fix a problem on dozens of machines just by altering the host string.
The single most useful thing about ssh to me is that it connects stdout/in across the channel (this is behavior inherited from rsh). This allows for e.g.: % (cd /foo; tar cpf - .) | ssh bar \(cd /baz\; tar xpf -\) Or: % cat ~/.ssh/id_rsa.pub | ssh bar tee -a .ssh/authorized_keys
ssh-copy-id - install your public key in a remote machine’s authorized_keysRe: Unix Commands I Wish I’d Discovered Years Earlier
#163Re: Unix Commands I Wish I’d Discovered Years Earlier
#164xargs. Can't tell you how many times I wrote quickie C programs and awk scripts to do what xargs does. http://sidvind.com/wiki/Xargs_by_example
Re: Unix Commands I Wish I’d Discovered Years Earlier
#165Mac OS: pbpaste & pbcopy For instance: pbpaste | fgrep -i "`pbpaste -pboard find`" To search the copy clipboard with the find clipboard.
On X11 systems, there's also xclip: xclip -o -selection clipboard
… | xsel -b # Copy.
xsel -b | … # Paste.Re: Unix Commands I Wish I’d Discovered Years Earlier
#166I'm unreasonably excited about discovering xxd.
I can't remember how many times I implemented hexadecimal dumps and undumps because I didn't want to coerce od into working the way I wanted.
Re: Unix Commands I Wish I’d Discovered Years Earlier
#167Earlier quoted context omitted.
Forgive my ignorance, but I don't know what what it means to connect "across the channel", but it sounds important. Do you know a link that explains the concept? I've failed to Google it.
It means that whatever you put into the ssh process's STDIN gets sent to the STDIN of the remote process. For example you can do this: tar cj $bigdir | ssh host 'tar xj' That creates a tar.bz2 archive on your machine, sends it over ssh to the remote host, where it's unpacked. Ad hoc compressed and encrypted file transfers made easy.
rsync -az $bigdir host:$bigdirRe: Unix Commands I Wish I’d Discovered Years Earlier
#168Earlier quoted context omitted.
I lean towards nohup time whatever >whatever.out & because so many programs behave differently when attached to a tty (like prompting for input) and I just want a plain text log that says when it succeeded or where it blew up.
Well that is fine, but that is only covering a very small sliver of what screen/tmux are used for.
Re: Unix Commands I Wish I’d Discovered Years Earlier
#169I want a command that counts files in a tree like du does sizes but without having to pipe find through wc which is crazy for hundred thousand files. Can't they just directly access inodes for high speed counting?
function lc() { if [[ "$#" -gt 1 ]]; then for DIR in "$@"; do echo -n "$DIR - " ; ls -AU1 $DIR | wc -l ; done ; else ls -AU1 "$@" | wc -l ; fi; }
Then "lc dir/" will print the number of files in the directory, and "lc dir/*" will print the number of files in each of the subdirectories. This exactly what you're looking for because it doesn't descend into the tree. If you're working with directories that may have tens or hundreds of thousands of files in them, it's useful to check first.
Re: Unix Commands I Wish I’d Discovered Years Earlier
#170Earlier quoted context omitted.
Well that is fine, but that is only covering a very small sliver of what screen/tmux are used for.
Agreed, and my problem with even the usage above is that I often realize too late that "whatever" is not going to finish before I need to unplug. Then I have to kill "whatever" and restart with nohup and logging. tmux/screen always has me covered.