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).
Related
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
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".
Just found that SQLPLUS would parse the first line of a sql script as connect string if I do not include the credentials when invoke sqlplus in the terminal, details are listed below:
I have a sql script named runme.sql:
scott/tiger#//localhost:1522/orcl
select * from dual;
exit;
If I invoke sqlplus as sqlplus #runme.sql , sqlplus could parse the first line and connect to database and run the sql. Can anyone point me to the documentation for this if there is any ? Also what are the advantages for supporting this syntax ?
The documentation is usually a good place to start. Note the warning if you supply the username/password on the command line; providing at least the password when prompted is more secure, and particularly in Unix-type environments means the credentials don't appear in the output of a ps command.
Putting either the password or both the username and password in a script automates that, but of course you have to then ensure that the script can't be viewed by anyone who shouldn't know the credentials.
As LalitKumarB notes in a comment, hardcoding the password anywhere is a security risk. If you're running scripts interactively then allow the slight inconveince of being prompted each time. (Which isn't really inconvenient when compared to the damage that could be done from the credentials being misused, and subsequent inconvenience of recovering, and/or finding a new job). If the script isn't being run interactively then use the scheduler rather than, say, cron. You can also use Oracle Wallets for greater security without so much inconvenience.
Specifically for your query about it parsing the first line, the documentation says:
If you do not specify logon but do specify start, SQL*Plus assumes that the first line of the script contains a valid logon.
In this context 'start' is the same as using # on the command line to supply the script name.
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...
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.