I did ask this question before but that thread was closed as the question was vague. So here is try #2:
I wish to have a simple script that connects to a remote machine via telnet, then executes the command ZAHO, and then stores the output in a file cat.txt on my local machine. Here is the code I tried:
(echo "PPATIL"; sleep 1 ; echo "IDEA#2010" ; sleep 1;) |telnet 10.110.3.132 23<< EOF
ZAHO; > cat.txt
EOF
The following thing happens when I run the script:
Trying 10.110.3.132...
Connected to 10.110.3.132.
Escape character is '^]'
After this, I come back to my shell prompt without anything happening.
Now, even when I supply a wrong a password, I still get the same error.
P.S.: spawn/expect/send are not present and only option to login is through telnet.
I also tried this
(echo "PPATIL"; sleep 1 ; echo "IDEA#2010" ; sleep 1;echo "ZAHO;";) |telnet 10.110.3.132 23
In this case however, the remote machine gets connected, it shows me the username prompt, enters the username, then shows password prompt, then enters password, sleeps for a second and then appends "ZAHO;" to the password, and gets disconnected.
If I remove echo ZAHO; then also it gets disconnected after entering username and password.
In general:
cmd | cmd2 << EOF
EOF
is ill defined. (I'm not sure if the shell grammar clarifies this as undefined, or implementation defined, or what, but it certainly is not going to do what you want.) cmd2 can only have one input source, but you are trying to give it input both from the pipe and the heredoc. You need to pick one. Perhaps you can try:
{ cmd1; cat << EOF; } | cmd2
input
EOF
but that is pretty obfuscated, and you would be better off writing a script to generate the desired input.
If you are not restricted to shell script. Python has a
telnet interface in its standard library. Actually the example given on the library documentation page, is very close to what you want.
Python is perhaps not as ubiquitous as shell, but it is widely deployed and used.
Related
I started a local server and want to add some simple commands with python, the server is running with forge 1.12 and a couple of mods.
My idea was it to catch wrong commands and send the right result instead.
An easy test command would be /echo Hello World with the result in the chat Hello World.
To get the command I am using the last line of the latest console log file, which is equal to the current console content. But in the console I cant read wrong commands. So if I run the echo command I get an message in the chat Unknown command. Try /help for a list of commands.
I think there could be two solutions:
Add in any register the command to get it in the console, prevent on this way the server to response and get the command in the console to use it.
Find a config to print also wrong commands in the console.
Thanks for helping
There is no way to 'cancel' commands through API, but there is a trick to effectively cancel commands anyways. You want to be listening to the Forge CommandEvent, modifying the command to another existing command that does nothing (you can create one yourself). This gives you a place to handle all commands (you'll have to filter for unexisting commands, otherwise you'd cancel all commands), and it will prevent the Unknown Command message from showing.
Is there a way to capture information logs ( session or workflow ) and grep only ERROR or FAIL messages and send to email distro
using mailx or sendmail option.
I have around 200 sessions running on daily basis and this script has to run every day , and capture only error information .
Thanks
Should be simple, so long as you configure the session to write backwards compatible logfiles then it'll lose all the encoded junk and you can grep for $ERROR or $FAIL
Can anyone show me an example of script that can be run from sqoop2 client in batch mode?
I refered http://sqoop.apache.org/docs/1.99.2/Sqoop5MinutesDemo.html
and it says we can run sqoop2 client in batch mode using the following command
sqoop.sh client /path/to/your/script.sqoop
but that script.sqoop isn't like sqoop1 script, so how should it be?
Batch file is nothing but a list of the same commands you would otherwise type in interactive mode (plus comment lines starting with pound sign).
However! Some commands require manual input, thus cannot be easily fully automated (e.g., 'create link' command). See this thread for details.
My program runs(exec..) an external program.
While running, the external program asks user [Yes/No] to proceed next step.
Instead of typing [yes] in command line, how can I pass [Yes] to the external program from my program.
Unless the external program supports a respective flag (see #Jonathan Leffler's answer), your you have control over that program's source and can add it, you have to simulate the "yes" input.
Options:
Try launching the external program by piping the output of the yes helper application to it's stdin: yes | external_program. yes is a simple tool, should you not have it, that just writes "y" to it's stdout continually.
Manually write "yes" to to stdin of the external program.
Both options require your to use pipes in one way or the other. See this for more information on how to do that.
The classic way to provide a 'yes' response on the command line is a -y option (usually with a parallel -n option to indicate a 'no' — see fsck(1)).
There's also room to argue that running the program should be a 'yes, I mean to do it' operation. However, there are times when it makes sense to specify 'yes, I really mean to do it' (such as one-time initialization of an instance of a DBMS).
I have a java program, let's say Test.class.
When I execute java Test the program ask for a Password and then continute.
The problem is that the stdout is redirected to a log and the program is launched with the & ( we are on UNIX).
How can i interact with this program launched java Test & with the stdin and stdout?
One possible solution is to start the program in foreground and then after a condition run it in background from java.
Thanks!
If the program can read the password from stdin, you can have a Unix script prompt for the password, then start the Java application and pass the password to it, e.g.:
echo $PASSWORD | java Test >log.out &
Or you can consider to split your Java application in two parts; there could be one interactive "front-end" part that validates the password, and then once the password is validated this could launch a "back-end" part as a background process and exit.
One option is to pipe the input to your program using echos as:
(echo input1
echo input2
....
) | java Test >& logfile &
Alternatively if the number of inputs are large you can also put your inputs in a file and redirect the file contents as:
< input_file java Test >& logfile &
I don't see anything Java specific in this question, if you want to drive the stdin based on the application output, you can use the Expect utility: http://en.wikipedia.org/wiki/Expect
Beware though, Expect is notoriously fragile, you'd do wise to refrain from using it in production scenarios.
Actually if you only want to be able to enter the password, perhaps you can try launching your app in foreground (without the trailing &).
Then, after you have entered the password, press Ctrl+Z or in another shell do kill -SIGSTP <pid> in order to suspend your program. Finally, type bg to put it in background.
Read the docs about your shell's job-control functionality for details.