5 ms·
meh... for h in host1 host2 host3; do \ echo -e "\n$h\n===========\n"; \ ssh $h 'ln -s /some/path /path/to/link && ls -l /path/to/link'; \
by ilikepi 16y ago
meh...
for h in host1 host2 host3; do \
echo -e "\n$h\n===========\n"; \
ssh $h 'ln -s /some/path /path/to/link && ls -l /path/to/link'; \
done
edit: woops, left out a couple semicolons...
- geocar 16y ago> edit: woops Exactly. One-offs are easy to test interactively with cssh, and despite what anyone thinks, there are always one-offs in the real world.
- ilikepi 16y agoTrue. Usually when creating a shell loop like this, I prepend 'echo' in front of 'ssh...' as a dry run first. I also wouldn't actually use something like this for commands that are destructive in nature. Usually it's for things like running informational commands ('rpm -q', 'uptime', etc). Of course anything can become destructive if you fat-finger it hard enough. In short, use automation with care.
- fragsworth 16y agoFUCKING SERIOUSLY?! Thank you for this comment, I never knew you could pass commands to ssh.
- joh6nn 16y agoi suggest perusing the ssh man, then, as it seems likely that it has other capabilities you don't know about.
- rbranson 16y agoLike how SSH agent forwarding can allow you to hop from box to box with the SSH keys loaded onto your local machine's SSH agent? Found that one a few months ago, made me reflect on what I've been doing in life the past 10 years not thoroughly reading UNIX man pages.
- erikig 16y agoThanks for this one. You just added a few days to my life and helped push out the onset of carpal tunnel/arthritis. ~ http://www.unixwiz.net/techtips/ssh-agent-forwarding.html http://www.unixwiz.net/techtips/ssh-agent-forwarding.html
- jberryman 16y agossh is magic. checkout -X for X11 forwarding to run remote GUI apps, and -R which lets you set up a reverse SSH tunnel when you need to connect to a machine behind a firewall.
- Raphael_Amiard 16y agosuch a polite version of RTFM, i love you
- taylorbuley 16y agoBased on a similar reaction a few months ago, this will definitely change the way you go about system work.
- z2amiller 16y agoNow combine that with dsh (http://www.netfort.gr.jp/~dancer/software/dsh.html.en http://www.netfort.gr.jp/~dancer/software/dsh.html.en) and authorized_keys, you can _really_ get in trouble. dsh is similar to this Cluster SSH, but is appropriate for use in scripts, cron jobs, etc. Example: dsh -Mg all-machines -F 20 'do something' -M: Prepend any line of output with the machine that emitted it -g: runs the group all-machines (just a text file in etc/dsh/group) -F 20: forks at most 20 copies of ssh in the background so you don't overload the server you're running this from
- veritgo 16y agoYou probably already know this, but if you have a significant number of hosts: for i in `seq 1 30`; do \ echo -e "\nhost$i\n===========\n"; \ ssh host$i 'ln -s /some/path /path/to/link && ls -l /path/to/link'; \ done Also, if you just start typing for i in `seq 1 30` do commands more commands done On the command line itself, you don't need to worry about semicolons. Bash will take care of it.