OpenWrt Forum Archive

Topic: Help with command XTERM

The content of this topic has been archived on 20 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi, I'm trying to run a bash script in openwrt but I have a problem executing the xterm command, because it can't be found. So, there is an alternative or a way to install xterm in openwrt?

Thanks in advance.

I guess you're confusing something...

xterm is a program that shows a terminal on a GUI desktop in a window. It is by no means required to run a bash script.
Since OpenWRT (in almost all cases) has no gui, there's no need for a xterm program. You just ssh into the box and there
you've got your console session.

The matter is this:

I have the main script which calls the second script with the following command:

for ROUTER in {1..10}
do
xterm -iconic -e $path/runscript $ROUTER &
done

and the runscript code is:

#!/bin/bash
#!/usr/bin/expect -f

set arg1 [lindex $argv 0]
spawn ssh root@192.168.$arg1.1 ; 
expect password ; 
send "12345\n" ; 
expect '~#' ; 
send "./script3.sh\n" ; 
interact

And the result is always:

- bash: xterm: command not found
- bash: spaw: command not found
- bash: expect: command not found
- bash: send: command not found
- bash: interact: command not found

Do you have any clue?

Thanks

ok, the first code pice would work this way:

for ROUTER in 1 2 3 4 5 6 7 8 9 10 ; do
  $path/runscript $ROUTER &
done

But the latter one is more tricky because you're using the 'expect' program there to enter the password on each host but there is no 'expect' package for OpenWRT.

I would suggest you to use a different (and more secure) approach which would avoid having to set the same root password on each host and storing that in plaintext on your router:
Use authentication by public/private key.

First you need to create a pulic+private key pair on your OpenWRT box:

root@openwrt:~# dropbearkey -t rsa -f master.key | grep "^ssh-rsa" >master.key.pub

then you copy the public key (master.key.pub) to each of your hosts that you want to ssh into and append the content of the file to the 'authorized_keys' file of root (or any other user you want to login as):

root@slavemachine:~$ cat master.key.pub >>/root/.ssh/authorized_keys

Now you should be able to ssh into your slave machines by using the private key file from the OpenWRT box, test it:

root@openwrt:~# ssh -y -i master.key root@192.168.xx.xx

And if that worked, you can use the technique in your script from above:

for ROUTER in 1 2 3 4 5 6 7 8 9 10 ; do
  ssh -y -i /root/master.key root@192.168.$ROUTER.1 /root/script3.sh
done

That should work. Guarantee is not included ;-)

Hi and thanks for this info, it was really helpful!

The problem is I don't have only 1 Master and 9 slaves, I want each router to execute the scripts and interact to each other so that means that I would need one master key for each router and put it into every router I would connect to?

And another offtopic question would be if there is any way to know when the router is transmitting or receiving so I can make a condition like:

if (routertx==1){
...}

I have done a lot of research but the only thing I've found it's related to the LEDs and triggers (http://wiki.openwrt.org/doc/uci/system in wify activity: phy0tx - flashes on transmission.) But I don't know if it's a variable neither if I can read from it how to do it.

Thanks in advance.

(Last edited by humid on 18 Sep 2012, 09:01)

The discussion might have continued from here.