Sending commands to a Tera Term via script file - scripting

I am testing some boards and the system used to test these is Tera Term. In Tera Term I use the Serial Port to send commands to the board in order to log in and run certain settings that I want.
Instead of typing these commands each time I test a board I want to create a program that sends these commands without the requirement to type them again and again each time.
Also I need to set a delay between each command as the system needs to to load between them.
Question
How can automate the typing of commands and delay between subsequent commands in teraterm?

I used the Tera Term Language (TTL) and created a macro which solved my problem. I used code to wait for a prompt from the system and then print out the command I wanted.
Here's a link to the TTL syntax:
http://ttssh2.osdn.jp/manual/en/macro/syntax/

Don't use Tera Term for that. It is not made for scripting, but rather for interactive use. Try to get a command line serial terminal emulator.
If you are on Linux you can use screen or there like.
If you are on Windows you can just write echo command > COM1 in a normal com.exe-window, according to this link: https://batchloaf.wordpress.com/2013/02/12/simple-trick-for-sending-characters-to-a-serial-port-in-windows/
(Replace COM1 with the name of your serial interface)
Make sure you don't have your Tera Term open while you use the echo-command, otherwise you'll get "Access Denied".

Related

Execute Unidata Process from the shell command lines?

Is it possible to execute the Unidata process from the Unix Command line??
If it's possible, can anyone please let me know how to??
I just want to add some Unidata Processes into the shell script and run it from the Unix
Cron job.
Unidata Process
Unix Command line
Yes! There are several approaches, depending on how your application is setup.
Just pipe the input to the udt process and let 'er rip
$cd /path/to/account
$echo "COUNT VOC" | udt
This will run synchronously, and you may have to also respond to any prompts your application puts up, unless it is checking to see if the session is connected to a tty. Check the LOGIN paragraph in VOC to see what runs at startup.
Same, but run async as a phantom
$cd /path/to/account
$udt PHANTOM COUNT VOC
This will return immediately, the commands will run in the background. Have to check the COMO/PH file for the output from the command. It's common for applications to skip or have a cut down startup process when run as a phantom (check for #USERTYPE)
If none of the above work because of the way your application is written, use something like expect to force the issue.
spawn udt
expect "ogin:"
send "rubbleb\r"
etc.
https://en.wikipedia.org/wiki/Expect for more info on expect

How do I send the same command to a subset of all windows in a screen session

In the answer to this post Corey Henderson explains how you can use the at and stuff commands in screen to send commands to all windows of a screen session at once. I would like to know how I can stuff the input buffers to some windows at the same time. In other words, I would like to use a filter to specify which windows should receive the input and which should not.
It would be great if I could filter on the window number instead of the user name or the window name because bash likes to change the window name sometimes and it is inconvenient to modify the .bashrc on multiple machines. Also, sometimes I don't have control over which user I am running the command as.
So far I have only been able to run a command on either the currently active window or all windows at once.
The only way I have found to do windows filtering when using the atcommand is by using windows names.
By default screen's windows names are set after the actual command name of the program created in the window, for me this is usually bash. But windows names can be changed to whatever you prefer with Ctrl+A. If your windows' names change dynamically, check you don't have Dynamic Titles enabled.
So in practice that means you can give related windows a common prefix and then use at "prefix#" stuff "command" to execute the command only on those windows whose names matches the filter.
Imagine we have the following windows opened in our screen session:
0$ front1 - 1$ front2 - 2$ back1 - 3$ back2 - 4$ back3 - 5$ db1 - 6$ db2
The next command would send the service ntpd stop command to windows starting by the string back, that is back1, back2, back3:
at "back#" stuff "service ntpd stop^M"

Extract userInfo from JSCH stream

I am trying to implement an online terminal UI with jsch as backend.
I need to display the userinfo ie [username#Machine ~]$ information in the UI.
Since the outputstream simply sends the bytes, it is difficult to distinguish the userinfo with the real command output. Is there any way to distinguish the same?
In general, no.
If you have a shell channel, all you see is the output from the user's remote shell, including the prompt and the actual command output. You can try to parse that. In simple cases this will work, but in general it is impossible, as every command could output a prompt-like string.
The username should be known to you (it should be the same as you used for login), the server name is a bit trickier.
An idea worth exploring might be to set a special prompt delimited by character sequences which are unlikely to occur in "normal" command output – set the PROMPT variable in your shell.
You could circumvent that problem by not using actually a shell channel, but an individual exec channel for each command – but then you'll have to interpret commands like cd yourself and keep track of the current directory, and add a cd command before the actual command in each exec channel. You might want to have an sftp channel open in parallel to keep track of the directories (and list files, and so on).

Gnu Emacs: tab-completion for psql running within sql.el process

I enjoy running Postgres client "psql" under psql.el while interacting with a .sql file in a separate window. Sometimes, I want to use tab-completion within the the buffer running the psql process to find the name of an appropriate table name. However, I can not figure out how to cause the desired result.
A very related question has been asked here: https://superuser.com/questions/236574/how-can-i-send-a-literal-tab-to-bash-in-emacs-shell-mode
without any successful suggestions.
Thanks in advance!
SetJmp
Usually programs that designed for interactive use (when they own terminal) disable interactive features (like history for UP/DOWN, completion for TAB) when used in pipe.
Emacs usually use pipes for external processes. So interactive features are disabled.
Even if you send TAB, your client program does not interpret it for you as you want.
You can read man/help for your program and try force interactive mode by providing command line switch (like --login for GNU Bash).
To send TAB eval:
(defun my-comint-send-string (string)
"Send string to comint buffers. Useful for *compilation* read-only buffer."
(interactive
(list (read-input "Type string: " nil 'my-comint-send-hist-list)))
(comint-send-string (get-buffer-process (current-buffer)) string))
(define-key XXX-mode-map [C-return] 'my-comint-send-string)
and use such key sequence: C-RET C-q TAB RET.
But this may not work if buffering is enabled for stdio of your program (to flush input you must send \n too)...
Mostly same problem discussed at Bash autocompletion in Emacs shell-mode
NOTE M-x term use pseudo terminal so all interactive program work as desired. But in this mode you lose any Emacs editing capabilities...

Running a Command that will run on every computer

I have this code which gives me all of the information I need regarding tasks, information etc. I have it all shelled into a VB program and I want to be able to run this from one computer and have it return the data from all computers on the domain.
I am lost as to what to add next.
Dim sCommand As String
'all processes here, ipconfig, java info, etc etc
sCommand = "java.exe -version2 > C:\Info.txt && ipconfig >> C:\INfo.txt"
Shell("cmd.exe /c" & sCommand)
I have script that will list all users on the domain, can I implement that or is there an easier way?
Edit: If I could search the entire domain for a specific file that would work too.
At the moment I just need all the data returned to a text file, I am not worried about it being sorted, or how long a process like this would take.
thanks a bunch
You could do one of two things.
1) You could use WMI to get both the network config off the remote machines and execute a process on the remote machine.
Or
2) You could use PsExec to kick off a command on a remote machine and pipe that out. I personally wouldn't use shell to execute a command as it's pretty poor really. If I was going to kick off a process locally I'd use this, and use StdOut to grab the output from the shell, parse it to give you something you can work with instead of piping the output to a file locally and then reading it later.
EDIT
So you want to do all this from one central location? If you don't want to use PSExec, you'll have to use WMI to create a process on a remote machine to run the java.exe, but you can't redirect the output, you'll have to pipe to a file and read the file in another step.