Getting Tasker and ssh to play nicely

2,954 views
Skip to first unread message

ryan rodriguez

unread,
Sep 5, 2012, 8:00:32 PM9/5/12
to tas...@googlegroups.com
Here's my end goal:
I want to set my phone on an nfc sticker and have my mac run an applescript that launches my study workflow-wolfram alpha, my textbook pdf, evernote etc...

The script is in the bag. I can even run it from my phone using ssh and the command osascript "script_name_here".

I've figured out how to get nfc tags to run tasks.

So it goes like this.

NFC---> nfc launcher --> Tasker--->  ????----->ssh(Connect Bot w/ public key)---->run script on my mac.

I've been pulling my hair out on that one missing step. Currently, i have a hack running where the script runs as soon as i start the ssh.
This is very lame and not at all what I want. This means EVERY TIME i start an ssh ive got this damn script running.

I'm thinking a shell script could help me out. Has anyone figured out how to get tasker to send commands through an open ssh??
(starting the ssh too would be out of this world, but I'll take what I can get)

Many thanks in advance,
Ryan

UncleMike

unread,
Sep 5, 2012, 10:27:21 PM9/5/12
to tas...@googlegroups.com
I'm using ConnectBot for my SSH needs, and you can setup each connection to automatically run a script when the connection is made.  You could probably make two host entries in ConnectBot - one that runs the script, and one that does not, with all other parameters being the same.

Vladimir Oz

unread,
Sep 6, 2012, 3:12:02 AM9/6/12
to tas...@googlegroups.com
Uncle, why You didn't advise Your experience with intent? https://groups.google.com/d/msg/tasker/Au-fEJ9qork/SZz_ZjdZNzIJ

I think if ryan make in ConnectBot (or VX connect bot) a profile which runs the command on the mac and send intent, all be done.
Message has been deleted

ryan rodriguez

unread,
Sep 6, 2012, 11:35:00 AM9/6/12
to tas...@googlegroups.com
Vladimir, 
I've worked with the original intent mike posted, but the best I can get is for ConnectBot to open that particular connection, running or not. Any arguments I can pass in that would also start the ssh?

fubaya

unread,
Sep 6, 2012, 11:46:52 AM9/6/12
to tas...@googlegroups.com
Im not sure if this is what you want but if you can log into your mac from a shell using ssh and keys, then you can run a remote script or command non-interactively by adding it in quotes. If your ssh command is:

ssh -i [key] yourmac

just use

ssh -i [key] yourmac "some scripts and commands on the macmac"

It will log in, run the commands and give you output, then log out.

ryan rodriguez

unread,
Sep 6, 2012, 2:00:56 PM9/6/12
to tas...@googlegroups.com
Good tip mike. Figures out the post login automation and I set up two profiles to run my scripts (because I'll need one for both of my classes). Now I just need to get tasker to launch these...

ryan rodriguez

unread,
Sep 6, 2012, 2:04:46 PM9/6/12
to tas...@googlegroups.com
Fubaya,
would I be able to do this from tasker via "Run Shell"?

I can already run the script remotely using ConnectBot, i just can't get tasker to do it after setting my phone on the nfc tag. 
Is there an way you know of to launch a profile within ConnectBot from Tasker? This is my only hangup at this point.

Many Thanks.

Wietse van Buitenen

unread,
Sep 6, 2012, 2:25:09 PM9/6/12
to tas...@googlegroups.com
you should be able to do the stuff fubaya says from Run Shell in Tasker..
this doesn't use ConnectBot but the ssh client that is available from the terminal..
in order to get this running you will have to set up public key authentication for this client..

a few lines of copy/paste I did in some thread (am a bit lazy today :) ):
I'm also using BTEP's ssh binary though I just call it from it's path instead of linking it
/data/data/com.magicandroidapps.bettertermpro/bin/ssh ro...@192.168.1.1

or generate a pair of keys and use public key authentication (line below is one line)
/data/data/com.magicandroidapps.bettertermpro/bin/ssh -i /data/data/com.magicandroidapps.bettertermpro/home/.ssh/id_rsa -l root 192.168.1.1

I use the above command from SL4A r4 in various scripts and it works fine :)

before I could do this I needed to chmod a+x /data/data/com.magicandroidapps.bettertermpro/home/.ssh

once this is done and you backup/restore BTEP with TitaniumBackup the permissions are kept this means if you flash a new rom you can just restore the apps and all your scripts will work again

here is a link and some info I gathered from that thread:

Tasker + ConnectBot can be used to execute arbitrary remote (or local, I guess, but Locale Execute is better for that) commands on a schedule.
Step 1: Set up your connection in ConnectBot.
  • You can have duplicate connections in ConnectBot as long as they have different aliases. You have to rename one first (away from user@host) in order to create the second. Long Press and select "Edit Host" to perform these changes.
  • You probably want to set up an ssh key without a password so that you can use this for automation.
  • Once the connection actually works, you can use "Post-login automation" to add the remote commands you would like to run. Make sure there is a blank line at the end so that enter is sent after your last command. Use enter or ; to separate commands. I suggest using something like "echo hello" as a test until you are sure things are working, and "exit" at the end if you don't want to leave the connection open.
  • Test this in isolation.
Step 2: Create a Tasker Task to call connectbot.
  • Create a new Task in Tasker.
  • Add an Action. From Misc, select "Action Intent"
  • The fields are:
    • Action: android.intent.action.VIEW
    • Cat: Default
    • Data: ssh url, in the form of "ssh://user@host/#alias" (without the quotes). The alias, user and host here must match the alias you set up in Step 1.
    • Target: Activity
    • Click Test. Connectbot should open and your commands should execute on the remote host.
Step 3: Use this Task in Tasker however you would normally.

ryan rodriguez

unread,
Sep 6, 2012, 3:41:47 PM9/6/12
to tas...@googlegroups.com
SUCCESS!

Got the script to execute for the first time from tasker- study workflow, classical music and all.
Many thanks Gents.

UncleMike

unread,
Sep 9, 2012, 10:35:13 AM9/9/12
to tas...@googlegroups.com
I'm glad to see it's working.  My ability to participate here has been more limited lately and I'm happy to see that my less-than-thorough post helped.

Vladimir Oz

unread,
Sep 10, 2012, 2:11:06 AM9/10/12
to tas...@googlegroups.com
Absolutely exhaustive explanation! It should be placed into the FAQ

Ryan

unread,
Apr 3, 2013, 2:16:42 PM4/3/13
to tas...@googlegroups.com

Hey aled,
This solution was a bit clunky with having to setup many profiles just to execute commands. The nfc part is straightforward, but what is your ssh plug in called?

On Apr 3, 2013 11:11 AM, "Aled Thomas" <aledth...@gmail.com> wrote:
you can use my nfc app to run your tasker task, and my tasker ssh plugin to run the script. much simpler :)

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/5xTLO_nP2pM/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages