writing shell ssh script for uploading compiled sketch on multiple arduino yun i

I work with a couple of arduino yuns and want to write a script to upload sketches on multiple of them. Let's assume I have a compiled arduino program:sketch.hex. Now I'd like to upload this file via LAN. For a single device it works like this.

Copying the sketch onto the device. (password required)
scp sketch.hex root@yun1.local:/tmp/sketch.hex

Opening an ssh session with the device. (password required)
ssh root@yun1.local

And then load the program onto the Atmega with the following 2 commands.
merge-sketch-with-bootloader.lua /tmp/sketch.hex
run-avrdude /tmp/sketch.hex

Now my question would be, how to do this for multiple arduinos (yun1,yun2,...,yunN) without entering actually ssh-ing into each single device in order to run the bottom 2 commands.

Hope the question is not too confusing and thanks a lot in advance.

Have you considered that it might make sense to ask Yun questions in the Yun section of the Forum?


S/he might not have realized there was one. I'll move it.

If you don’t want to use SSH and the command line, the simplest way is to go the Yun’s configuration web pages. Log in, and the first page shows the current network status, and has a section with a button that allows you to upload the sketch .hex file.

If you don’t want to do even that much, and you want to remotely load files directly from another computer automatically (without manually typing any commands) then you will likely have to do some one-time setup work on the Yun. I’m sure there are many ways to do it, but basically you need a way to send a file, and then run a shell script. My first thought would be to write a CGI script (Python, PHP, or something like that) which accepts a file upload web request, saves the file, and then programs the sketch using the commands you list.

A search on this forum about how to set up a PHP or Python CGI script on the Yun should turn up some examples. A general Google search on CGI scripting should give you some ideas of how to handle a file upload and run a shell script.

With that working, then you would need to write some code on your host computer to give it a list of Yun addresses, and make the web request to each Yun, sending the file.

Please do post the results of your research and experimentation - I’m sure others will like to hear about it.

Plan A:

Using public keys ssh passwordless

Plan B:

Use sshpass

Plan C:

Use empty

Thanks for your responses. I was able to write a script for the exact purpose, if someone needs it in the future.
All the best.



Created by maggu on 21/02/16.

SSHCOMMAND=“ssh -p 22 -T -o StrictHostKeyChecking=no -o BatchMode=no”
for i in seq 1 $YUNS
sshpass -p “doghunter” scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $FILENAME $SSHACCOUNT:/tmp/sketch.hex
sshpass -p $SSHPASS $SSHCOMMAND $SSHACCOUNT << EOF_run_commands
merge-sketch-with-bootloader.lua /tmp/sketch.hex
run-avrdude /tmp/sketch.hex

The plan B (OP's method) as well as Plan C required password encode at filesystem.

Warning: huge security breach when password encode at filesystem!