Jump to content
C4 Forums | Control4

Any driver to execute shell command?


Recommended Posts

Hi,

I need to SSH to a device in my home network to issue a command. Is there a driver that will allow me to execute / run a shell command? I've already tested the SSH command that I want to use from the C4 command line (after logging in with the 'secret' password) and it works. Just need to figure out how to use it programmatically from within C4.

I tried the Chowmain Generic TCP driver but I think that only allows HTTP commands to be sent.

Any help would be most appreciated.

Link to comment
Share on other sites


Thanks, can you explain why it must be run from a C4 controller which is essentially just a Linux box. You could certainly run this programatically from the Linux side of things e.g. using a scheduled crontab entry. However, I would be leery of doing too much "vanilla" Linux work on a box like a C4 controller which has a highly specialized form of Linux.

 

Could you run the command? Putty has a form of SSH command line capability, if I recall correctly from some time ago.

 

Or run it from OS X on a Mac (BSD).

Link to comment
Share on other sites

I need the command to run when I switch to a particular video source on C4. It's to basically fire-up an application on my home media server (Mac Mini). For certain reasons, I can't have the app running all the time. So I plan to start the app when I switch to that source, and quit the app (via ssh) when I turn off the room or switch to another source. I'm open to alternatives but can't think of one ...

Link to comment
Share on other sites

Hmm, I can't think of a way to do this from C4 itself - although it wouldn't surprise me if tech support or development at Contol4 has an undocumented capability in this area.

 

Could you use the TCP driver to send a TCP or HTTP message to your Mac which in turn executes the SSH? You'll of cpurse need a program or web server running on your Mac to receive the command and act accordingly.

Link to comment
Share on other sites

  • 1 year later...
Unfortunately not. I run the scripts off a Mac mini that is my media server.

I would be greatly interested in beta testing / purchasing your ssh driver if go ahead and write it.

Can't do it right now. No way. Research was a dead end

Sent from my Nexus 6P using Tapatalk

Link to comment
Share on other sites

  • 1 year later...

I would suggest using a separate computer running Apache to accomplish this in conjunction with the Generic TCP driver.  Have the generic TCP drive hit a URL that you create on a Linux web server, a Raspberry Pi will do for this.  Have that execute the ssh command that you need when that URL gets hit.  I do similar stuff today with my C4 system - I have it launch Python scripts to do various things, including allowing me to interface with my Tesla, like starting/stopping chargin, turnin on the clmiate system, etc.

Link to comment
Share on other sites

  • 2 years later...

Here is a PHP file I created to help in converting a tcp request to run ssh command on a computer or other device.  

<?php
$connection = ssh2_connect($_GET['ip'], 22);
ssh2_auth_password($connection, $_GET['user'], $_GET['pass']);
$stream = ssh2_exec($connection, $_GET['cmd']);
?>

I have it running on my Synology's Web Station app with SSH2 PHP extension enabled.

Type the URL of the hosted file , for this example I'll use cmd.php as the filename and include example parameters for IP, USER, PASS, and the CMD.

Ex: http://192.168.1.2/cmd.php?ip=192.168.1.3&user=username&pass=password&cmd=say hello this is a test

Open a web browser (like chrome) and paste this in so you can test if the command worked properly and if it did.

http://192.168.1.2/cmd.php?ip=192.168.1.3&user=username&pass=password&cmd=say%20hello%20this%20is%20a%20test

copy this encoded url from chrome's address bar and put this in the TCP driver in control4. 

synology settings.jpg

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.