How to connect and run commands in a ubuntu and windows machines? - linux

I want to run few scripts (jmeter scripts) in few AWS ubuntu machines and windows7 machines. Usually I use WinScp (transfer files), putty (run commands) for linux and Remote Desktop Connection for windows machines, to do the work manually.
Now I want to automate these processes and would like to know how to achieve that. My intention is to write code to,
connect to these machines,
copy the scripts,
run the scripts,
fetch the log files and
close the machine
I also want to schedule them. What is the best way of doing this? Also I prefer that the code that I write can be hosted somewhere (so that rest api can be exposed) or called as a direct library (API) in my java server.
I know that chef scripts can be written, but want to know any other alternatives. https://www.chef.io/chef/
Thanks a ton in Advance.

Related

How do I run a shell script on multiple CGE machines concurrently?

I have multiple Linux GCE machines and there's a bash script I want to run on some of them from time to time. Right now I'm connecting manually to each machine separately in order to run the script.
How do I run the script on several machines concurrently without connecting to each machine individually each time? How do I configure on which machines it should run?
you can use csshx to ssh into multiple servers at once. Once logged in into servers, you can execute script as per your need. you can follow this link to install it on mac.
Other alternative could be that you schedule a cronjob at all servers so they will run at specific time. you can edit these multiple cronjobs using csshx.
Try fabric. You can write simple scripts in Python that you can run on multiple hosts (which you will need SSH access to).

How to run a rails application in another computer while still coding in my own computer?

I have an iMac and when develop in Ruby on Rails I run everything on it: MySQL server, Redis service, ElasticSearch service, guard, and, of course, the proper rails server. By doing so, my computer runs pretty slow.
So I just bought a CPU and install linux in it, along with MySQL, Redis & ElasticSearch. Now I connect to that services from my iMac and it runs way faster.
However, Rspec/Guard still takes ages to load/run.
So, how do I make the linux server to take the hit and actually run this programs while I keep editing the code in my mac?
I know it may be a crude way and i haven't tested it
Place your project in Dropbox folder on your machine and have it open on the second computer
Run it on the quick machine. You can use following command to access it through ip address on the computers in same network
rails server -b 192.168.1.12 -p 8000
When saving code it should sync from one machine to another, may have slight delay for syncing
or set up Vagrant.
Thats the only ways I can see.

Running shell commands remotely on multiple servers?

I need to run shell commands on several servers. Is there a secure way to do this? Right now im thinking of exposing a php url that allows me to send pure script commands and let the web server spit out a json response. But this is a lot of work and doesnt sound like it will be very secure.
I want to run commands like "ping", "whois" and other network commands. Its about seeing connectivity between different servers. I.e. Server in germany can talk to the server in the us, etc
Use ssh. Read a good ssh tutorial. You want to use it with a public key (to avoid typing passwords).
Of course, you need to have an SSH server process running on the remote server machines.

How to write a shell script to run scripts on several remote machines without ssh?

Can anyone please tell me how I can write a bash shell script that executes another script on several remote machines without ssh.
The scenario is I've a couple of scripts that I should run on 100 Amazon Ec2 cloud instances. The naive approach is to write a script to scp both the source scripts to all the instances and then run them by doing a ssh on each instance. Is there a better way of doing this?
Thanks in advance.
If you just want to do stuff in parallel, you can use Parallel SSH or Cluster SSH. If you really don't want to use SSH, you can install a task queue system like celery. You could even go old school and just have a cron job that periodically checks a location in s3 and if the key exists, download the file and run it, though you have to be careful to only run it once. You can also use tools like Puppet and Chef if you're generally trying to manage a bunch of machines.
Another option is rsh, but be careful, it has security implications. See rsh vs. ssh.

Automated deployment of files to multiple Macs

We have a set of Mac machines (mostly PPC) that are used for running Java applications for experiments. The applications consist of folders with a bunch of jar files, some documentation, and some shell scripts.
I'd like to be able to push out new version of our experiments to a directory on one Linux server, and then instruct the Macs to update their versions, or retrieve an entire new experiment if they don't yet have it.
../deployment/
../deployment/experiment1/
../deployment/experiment2/
and so on
I'd like to come up with a way to automate the update process. The Macs are not always on, and they have their IP addresses assigned by DHCP, so the server (which has a domain name) can't contact them directly. I imagine that I would need some sort of daemon running full-time on the Macs, pinging the server every minute or so, to find out whether some "experiments have been updated" announcement has been set.
Can anyone think of an efficient way to manage this? Solutions can involve either existing Mac applications, or shell scripts that I can write.
You might have some success with a simple Subversion setup; if you have the dev tools on your farm of Macs, then they'll already have Subversion installed.
Your script is as simple as running svn up on the deployment directory as often as you want and checking your changes in to the Subversion server from your machine. You can do this without any special setup on the server.
If you don't care about history and a version control system seems too "heavy", the traditional Unix tool for this is called rsync, and there's lots of information on its website.
Perhaps you're looking for a solution that doesn't involve any polling; in that case, maybe you could have a process that runs on each Mac and registers a local network Bonjour service; DNS-SD libraries are probably available for your language of choice, and it's a pretty simple matter to get a list of active machines in this case. I wrote this script in Ruby to find local machines running SSH:
#!/usr/bin/env ruby
require 'rubygems'
require 'dnssd'
handle = DNSSD.browse('_ssh._tcp') do |reply|
puts "#{reply.name}.#{reply.domain}"
end
sleep 1
handle.stop
You can use AppleScript remotely if you turn on Remote Events on the client machines. As an example, you can control programs like iTunes remotely.
I'd suggest that you put an update script on your remote machines (AppleScript or otherwise) and then use remote AppleScript to trigger running your update script as needed.
If you update often then Jim Puls idea is a great one. If you'd rather have direct control over when the machines start looking for an update then remote AppleScript is the simplest solution I can think of.

Resources