User(s) browsing this thread: 1 Guest(s)
|
Executing a script on the server from the NMT?
|
|
02-20-2011, 04:46 AM
|
|||
|
|||
|
The problem: sleep is enabled on my media server (it's only in use a few hours a day), but obviously I want sleep disabled while I'm viewing. There's a nice applet called Caffeine which is a one-click toggle to achieve this on the (Linux) server.
I wanted to try to automate the process by using a script from the NMT. I'm already using this great script to wake my server (using WOL). Caffeine has a few command-line options which would be enough to get the job done if I could execute the script remotely. But despite several hours of trying, I'm getting nowhere. I'm fairly new to Linux, so I'm feeling my way around. From reading here the obvious solution seemed to be using SSH (DropBear), but I just cannot get this to work, and there's actually very little on this forum about using SSH from the Popcorn to a server, it's all the other way around. I've gone through several attempts at setting up keys, and I can SSH into my server from my Windows box (using Putty), but DropBear on the Popcorn just gives me errors. Apologies for the long intro. My question: is SSH my only option? (I can't find an RSH client for the Popcorn). Is there another way to execute scripts remotely from the Popcorn (it's a very simple one-line script, e.g. "caffeine -a")? Any advice appreciated. For the record, the standard error message I get when I try to SSH from DropBear is: "No auth methods could be used", which suggests no matching authentication methods. But a quick Google suggests this is a common DropBear error and it seems to have many causes. |
|||
|
02-20-2011, 04:49 AM
|
|||
|
|||
|
RE: Executing a script on the server from the NMT?
there is no reason to isntall dropbear pch has telnet enabled by default use putty select telnet and enter pch ip and you are in.
|
|||
|
02-20-2011, 04:54 AM
(This post was last modified: 02-20-2011 04:54 AM by johnk.)
|
|||
|
|||
RE: Executing a script on the server from the NMT?
(02-20-2011 04:49 AM)halfelite Wrote: there is no reason to isntall dropbear pch has telnet enabled by default use putty select telnet and enter pch ip and you are in. Thanks for the quick response. As far as I understand Telnet, it won't allow me to automate the process. With SSH (using key authentication) my plan to was have a one-line script, e.g.: SSH 192.168.x.x caffeine -a which I could set up as a web service and execute from the remote. Can Telnet do this? |
|||
|
02-21-2011, 04:35 AM
(This post was last modified: 02-21-2011 06:13 PM by johnk.)
|
|||
|
|||
|
RE: Executing a script on the server from the NMT?
Okay, so I've put in a few more hours on this and I've got ssh to the server working. I can send commands on the command line (telnet) using ssh.
So now I'm trying to adapt the script I mentioned in the first post to include a command to disable sleep. I know nothing about scripting in Linux, so I'm learning as I go. The relevant bit of the script now looks like this: echo -n "Sending MP to NAS" /bin/busybox ether-wake -b [Mac address] echo "Magic Packet Send..." /bin sleep 20 echo sleeping.... /opt/sybhttpd/localhost.drives/HARD_DISK/Apps/DropBear/bin ssh -i [key] -l [user] 192.168.x.x 'echo $DISPLAY; export DISPLAY=:0.0; caffeine -a' echo Caffeine The first line (wake on lan) still works, as it does in the original script. My second (sleep) command is designed to give the WOL command time to do its job, and the third command activates the Caffeine applet on the server to disable sleep. These commands all work well on the command line (ssh via Telnet). When I run the CGI script as a web service, however, with the Sleep and SSH commands I'm getting an error: "126: Permission denied". I don't know what would be causing this. Do I need to run those commands as root (although I am already using :8883)? Any suggestions appreciated. |
|||
|
02-21-2011, 05:01 AM
|
|||
|
|||
|
RE: Executing a script on the server from the NMT?
does your script have execute permissions? a+x?
|
|||
|
02-21-2011, 03:24 PM
|
|||
|
|||
| RE: Executing a script on the server from the NMT? | |||
|
02-21-2011, 10:59 PM
(This post was last modified: 02-21-2011 11:02 PM by johnk.)
|
|||
|
|||
|
RE: Executing a script on the server from the NMT?
Well, I've sorted this out, so just in case anyone is interested, here's a working version of the script. This wakes the server (WOL) and activates Caffeine (i.e. prevents sleep -- see first post) for four hours.
The two problems above ("Permission denied") were caused by bad paths. Firstly, the Sleep function on the Popcorn is a Busybox function, so I had to change /bin sleep 20 to /bin/busybox sleep 20 The second one was more complicated. It seems that the script did not like having dots in the path (localhost.drives). So I had to add the DropBear apps folder to PATH: PATH=/share/Apps/DropBear/bin:$PATH and then just use the ssh command in the script without a path. So the full working script is: Code: #!/bin/shBe patient, this will takes 45 seconds or so to run. So you'll be staring at the "rotating wheel" for that long before the html page appears confirming the script has run. One thing to add: however Caffeine is written, it doesn't return the script to a prompt, so it just hangs. This means that, on the NMT, the script would hang the machine. The neatest way to deal with this is to terminate the ssh session promptly on the server. Add these lines to the server's sshd config: ClientAliveInterval {time interval in seconds} ClientAliveCountMax 0 I set ClientAliveInterval to 15 seconds, so the session closes rapidly. I won't be using ssh for anything else, so this solves the problem. Remember to restart sshd. Any questions, I'll do my best to answer. |
|||
|
« Next Oldest | Next Newest »
|

Twitter
Facebook
NMT Wiki
Search
Member List
Help
A-400 [13 May 2013]




![[+]](images/collapse_collapsed.gif)

