Remote Compilation Using ssh and make
Occasionally I use my Linux machine at home to write code that I intend to compile on a remote machine.
While maintaining open FTP and TELNET connections to the remote machine to handle the transfer and compilation steps is a manageable solution, I decided to explore ssh and make to develop a more automated method.
The benefits of my solution:
No need to remember which files have been modified.
Ability to use Emacs' compilation capabilities to move to errors in the source.
As mentioned above, no need to use FTP or TELNET, and hence no reason to keep an open dial-up connection when not compiling.
Automate, automate, automate—laziness is a virtue.
My first step was to set up ssh and related tools in order to allow secure copying of files to my remote system. While setting up a .rhosts file is a (barely) acceptable solution, my IP address and name is different each time I dial in, and it would be rather awkward to change the remote system's .rhosts file each time I dialed in.
ssh gives me a much more secure form of authentication for copying files and executing remote commands.
Once I had ssh behaving properly, I used Emacs' info facility to explore implicit rules in Makefiles and wrote a simple Makefile to handle the file transfers and remote compilation.
As an example of the intended effect, assume my remote machine is called “remote” (and my local machine “local”), and I've just modified a source file called daemon.c. I would like to execute the following commands in an automated fashion (note that scp is a secure copy command packaged with ssh, and that the -C option specifies compression, useful for dialup connections):
scp -C daemon.c jdaily@remote:~/source-directory ssh -C remote "cd source-directory && make"
First, I needed sshd running on the remote system to handle my secure connections. Fortunately, sshd was already running on the remote system in question. According to the man pages, it can be run by any user (i.e., user does not have to be root) and is restricted to handling connections for that user (which should provide sufficient security for our needs).
Then, I needed to install the ssh tool set on my local machine. Again, ideally these would be installed in a public binary directory such as /usr/local/bin, but any user can install them in his/her home directory.
I also wanted a key which would allow me to authenticate myself between systems and eliminate the need to type my password each time I tried to run one of the ssh commands. For this, I ran ssh-keygen and made sure not to give a pass phrase, so that none would be needed when using my private key to establish the connection. Listing 1 shows an example ssh-keygen session.
Once I had a public key, I used scp to copy it to the remote machine.
$ scp -C ~/.ssh/identity.pub \jdaily@remote:~/.ssh/keyjdaily's password: <entered my remote password>
Then I logged onto the remote host and copied the key file into ~/.ssh/authorized_keys. If that file had already existed, I would have appended the key file.
Following all this, I could run ssh and scp without needing either a password or a pass phrase to connect to remote.
Now I needed a makefile to automate my system. Ideally, the files on the remote machine would be checked to see if they were older than the files on my local machine, and if so, they would be replaced. To simplify matters, I decided to keep a record of the “last transferred date” for each file by touching a corresponding file each time I copied a source file over.
As an example, when I transferred a newer copy of daemon.c over, I touched daemon.ct in the same directory. Any transfer of a .h file would be marked by the creation of a file with a .ht suffix.
After poking around the info file for make, I came up with the Makefile shown in Listing 2. This Makefile had one limitation in particular; I was unable to specify command-line arguments for make on the remote machine without writing them directly into the makefile on my local system. While this was fine for the current application, I decided to generalize it by creating a run-make shell script which would handle the remote execution of make after calling make on the local system. Listing 3 is my run-make shell script. I then removed the line from my Makefile which remotely ran make. Listing 4 is the output from a successful compilation sequence.
John Daily works for BBN (or is that GTE?) as a systems administrator/software engineer. He spends far too much time in front of computers. Whenever he can, he prefers to be outside riding his new bicycle and exploring New England. He can be reached via e-mail at jdaily@bbn.com.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?
| Non-Linux FOSS: libnotify, OS X Style | Jun 18, 2013 |
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
| Introduction to MapReduce with Hadoop on Linux | Jun 05, 2013 |
- Containers—Not Virtual Machines—Are the Future Cloud
- Non-Linux FOSS: libnotify, OS X Style
- Linux Systems Administrator
- Validate an E-Mail Address with PHP, the Right Way
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Introduction to MapReduce with Hadoop on Linux
- RSS Feeds
- user namespaces
1 hour 49 min ago - yea
2 hours 15 min ago - One advantage with VMs
4 hours 43 min ago - about info
5 hours 17 min ago - info
5 hours 18 min ago - info
5 hours 19 min ago - info
5 hours 21 min ago - info
5 hours 22 min ago - abut info
5 hours 23 min ago - info
5 hours 24 min ago




Comments
Immediate help in automating a small shell script
Q) I had done the ssh public/private key generation process and my system get connected to remote system automatically with out password. But I want to get this executed through script and when doing this after getting connected to the remote system,the script is being not working.
for example:
#!/bin/bash
ssh 123.12.3.45 {sample ip}
echo "hai vamsi"
output:
just connecting to remote system and stopping over there.
I need your help in this regards to proceed further ,where I get connect to the remote system and then display the echo string.
Thanks in advance
Vamsi
SSH in script
Once the ssh command connects to the remote system the script is going to "pause" execution until the ssh command exits. This is normal behavior: the shell waits for each command to complete execution before it moves on to the next command.
If you were thinking that the echo command was going to execute on the remote system... it doesn't work that way. If you want to execute the echo remotely then your script needs to be:
If you want to execute more than one command remotely then you should place them in a script on the remote system and execute the script with the ssh command.
Mitch Frazier is an Associate Editor for Linux Journal.