Teraterm Sendln issue, it cannot send the full command - teraterm

I need help when debugging teraterm script. The simple codes shown below:
connect "/c=20 /baud=115200"
pause(8)
cmd = 'r 10314 1'
sendln cmd
pause(3)
closet
Actually only send command of "r 10314 1". What I saw that this command is issued successfully, but in Teraterm window, only the command shows: r 1 . Why sendln doesn't send all the commands? Appreciate.

Have you checked that both devices can handle that fast of a baud rate? Instead of 115200, have you tried a slower speed?
The code looks good (as in you are only sending one string with the same apostrophe on both sides, this can also be achieved with two double quotes) and waiting 3 seconds after, there should be no problem; I would try with lower baud rates to see if you aren't trying to send the data faster than capable.
Here's some things to look at that can maybe help:
https://ttssh2.osdn.jp/manual/en/macro/syntax/formats.html
https://learn.sparkfun.com/tutorials/serial-communication/all

Related

Cannot enter long commands in terminal

I am using putty (0.64.0.0 2015) to access the terminal on an AIX server. Normally typing long commands works just fine but somehow something weird happened and when I type long commands Linux cursor goes back on the same line even behind the 'bash' word.
In order to explain the problem I have a picture. Just to explain in the picture I start with capital 'ABC' then '1-10' and then small 'abc' and then repeat this sequence to simulate a long command.
Can anybody please explain why this is happening (it has also happened before) and how to solve it without restarting putty? Does it have to do with a buffer of some kind since the command runs just fine it is only that it looks like this in the picture.
It looks like your shell is no longer aware of its terminal's dimensions. Perhaps you've resized the PuTTY window after logging in?
Sometimes resize will fix such issues.

Automate installation of binary in linux

I have a Bourne-Again shell script text executable named engine.bin that I want to install.
If I install the executable manually ./engine.bin I get a screen with the EULA I have to accept (by pushing space), then accept it by writing yes and then enter the installation path by typing /usr/local/engine.
Now I want to do the installation automatically through provisioning scripts without manual interaction. Is there a way to do this? I do not know if the installer accepts any parameters, unfortunately the thing is undocumented.
Based on the suggestion of bill-agee and jgr208 I wrote the following which is working for me:
#!/usr/bin/expect -f
set timeout -1
spawn /tmp/engine.bin
expect {
-gl "*Press SPACE or PAGE DOWN key to continue, U or PAGE UP key to scroll back*" { send -- " "; exp_continue }
-gl "*yes/no*"
}
send -- "yes\r"
expect -gl "*press ENTER to accept the default*"
send -- "/tmp/tce\r"
expect eof
If the executable allows you to spam input at it without waiting for each separate prompt to appear, you might be able to accomplish this with bash.
For example, this script will run program_that_takes_several_lines_of_input.py and send it four lines of input - three with text and one blank line:
#!/bin/bash -eux
./program_that_takes_several_lines_of_input.py <<EOD
first line
one enter keypress later
yet another line of input after the empty line above
EOD
If you need to stop and wait for each prompt to appear, the cram Python package may be a good fit for this scenario - I find it useful for tasks like this where you only need to send a few lines of input, but each line of input is different.
See:
https://bitheap.org/cram/
https://pypi.python.org/pypi/cram
Expect would also work, but I find that I reach working solutions a bit faster when using cram than with Expect.
pexpect is a great choice as well! See:
https://pexpect.readthedocs.org/en/stable/

Sending keystroke to a process

I want to write a seperate program that can receive commands from network and replay these commands to omxplayer. omxplayer is the video player on raspberry pi, we can control omxplayer via the keystroke. May anyone please suggest some approaches that we can send keystroke event to a running process?
Any suggestions are appreciated. Thanks!
You can use FIFO to send keystrokes to omxplayer.
We'll show you a basic example of how you do it.
In Shell (Terminal 1),
mkfifo /path/to/dir/fifo
omxplayer /path/to/movie/dir/movie.ext < /path/to/dir/fifo
after you execute these commands, the terminal 1 will hold.
Now in terminal 2
echo -n . > /path/to/dir/fifo
now it will start play.
This was the basic example. You can create a php file to write to the fifo file. So from that you can send commands.
p will pause
q will quit
also, when using non-letter commands (like up arrow, and down arrow), you should send the correct key code.
Hope this helps.

Specifying the Telnet window size

I'm trying to use say a command on a remote system that I'm connected to. A command like "top" where it it uses the full screen to display output, but telnet seems to have a default window size. Does anybody know how to change it?
Thanks in advance.
After you've telneted to the system you can set the terminal size with
stty rows 25 columns 80
No, telnet is likely not smart enough to somehow transfer these values to the destination system.
It seems I found out myself how to do it...
I needed to set the evioronment variables LINES and COLUMNS on the system that I was telneted too, it didn't really have anything to do with telnet itself. I did it in the following way:
I first ran "resize" to get the amount of lines and columns my current terminal was it gave me the following:
COLUMNS=157
LINES=53
export COLUMNS LINES
I then pasted this in to the system I was telneted to.
TADA! :)
Have you tried the debugging steps outlined here?

What does the command "cat /tmp/dir/:0" do?

When I did the command above, X11 opened. I am perplexed. Did I run it? How can I be sure that I do not run any program when looking at things? I really hate the idea that reading a text file may execute a program. How is it programmable possible to make programs that executes when running a simple cat-command, or similar command?
If you run
file /tmp/:0
you should see that this is not a normal 'text' file but a socket. Aliasing ls thus
ls -F
will help identify such files automatically in your shell.
This sounds like OSX 10.5 behaviour.
launchd listens on a socket '/tmp/launch-xxxxxx/:0'. The DISPLAY variable is set to tell X applications to write to that socket. When an X application opens the socket, launchd automatically starts 'X11.app' to provide the application with a display.
cat'ing the socket opens it and triggers X11.app. I don't think there are any other instances of that behaviour configured by default.
machine:0 is an X display (the first display on 'machine')
I have never seen /tmp/:0 but it might be that your machine is configured so that all unmatched machine names map onto localhost.
You haven't executed anything, the X server will simply try and interpret any commands sent by cat as X instructions. It's like doing cat to an http address
The :0 thing is a socket refering to the X server. Programs use this socket to communicate with the X server (for example to draw a window). Reading from this socket somehow caused the server to activate. The X server must have been already running before you did this command.

Resources