How to use expect to execute a jar and continuously hit enter? - jar

To start from the beginning, I'm using ansible to open a Jar file in a linux environment.
Basically I do: java -jar someJarFile.jar, and it opens in command line.
Now, it prompts me with several questions which can be passed by hitting Return multiple times.
Finally the jar will produce a WAR file...
Here's where I need your help.
I want to use ansible to call an expect script so that it can automatically execute the jar and continuously hit enter until the jar is successfully completed/installed.

try
yes "" | java -jar someJarFile.jar

If you know the number of times you need to press <Enter> you can use echo -e '\n'. For example, if you know you'll need three <Enter>s:
echo -e '\n\n\n' | java -jar someJarFile.jar
This is also helpful for times when you need to input specific and distinct values which yes doesn't allow. For example, answering a prompt like:
Enter value [default]: <enter>
Enter number: 30<enter>
Ok?: y<enter>
Do the dangerous: n<enter>
Could be simulated by
echo -e '\n30\ny\nn\n' | java -jar someJarFile.jar

Related

Nodes are not opening up properly after executing the runnodes script

I was exploring thIS cordapp example
https://github.com/corda/corda-training-template.git
There is a total of 4 nodes (Notary, A, B, and C) in this example. I am trying to open all the nodes in a single run using runnodes script from the terminal.
But all the nodes are not opening at a time. It's like alternatively they are opening, onetime only Notary and C nodes are opening and another time A and B nodes are opening.
Any specific reason?
And also I am getting this message in the webserver terminal. Please explain.
"The Corda specific webserver is deprecated and will be removed in future".
The runnodes script is not a very reliable way of starting up the nodes. Its mostly used for development purposes to make development faster.
It might sometimes not work as expected. The script works by opening up a terminal window and running the command to start the node in that particular terminal. Depending on the speed of the system, the command sometimes gets executed before the new terminal is opened up.
The reliable way to start a Corda node, however, is to use the java -jar corda.jar command. So just go into each individual nodes folder and run the command to start the node.
Here's the script :
#!/usr/bin/env bash
set -eo pipefail
# Allow the script to be run from outside the nodes directory.
basedir=$( dirname "$0" )
cd "$basedir"
if [ -z "$JAVA_HOME" ] && which osascript >/dev/null; then
# use default version of java installed on mac
/usr/libexec/java_home --exec java -jar runnodes.jar "$#"
else
"${JAVA_HOME:+$JAVA_HOME/bin/}java" -jar runnodes.jar "$#"
fi
Its the same one that you use to start the node, found in build/nodes folder

NPPExec Console in NotePad

Thanks in advance:
I'm attempting to use Notepad++ to log-in to a UNIX system. I am using the NPPExec console to do this, and the login process works... kind of. I use NPPExec to execute this script, named "sasunix.sh":
"C:\userblah\username\Desktop\plink.exe" -load "SUN4" -l myloginname -pw mypassword
As you can see I am using Putty's command line program "plink.exe" to send the command; "SUN4" is the session profile I am using. The problem is, the next screen logs me in (successfully), but proceeds to ask me for my password an additional time (which is part of the login procedure), followed by a request for my my terminal emulation setting (for me, this is 'xterm').
THE QUESTION: What additional lines would I add to my script to execute this sequence of inputs on the UNIX system (i.e. typing them in individually and pressing "ENTER" each time):
1.) thepassword 2.) xterm 3.) sas -nodms -nonews
I think this boils down to a misunderstanding of how commands are passed between NotePad++ and the NPPExec console window. At any point, if I press "F6", a prompt pops up, saying "WARNING: Console process still running...". This messagebox prompt allows me to type in a line which is then sent to the console... but how do I put a series of these inputs into the script?
You prob have this solved by now,
but i have done the following
a windows batch script that creates a file with unix commands, based on the a directory path
#ECHO OFF
:: store input variable
set str=%1
:: remove C:\ or Z:\ etc
set str=%str:~3%
:: replace \ with /
set str=%str:\=/%
:: append cd command
set str1=cd
set str=%str1% %str%
echo.%str%
:: make
echo make clean
echo make all
Install the NppExec plugin to Notepad++
Place the *.bat scripts and plink.exe in the Notepad++ program directory
Create the NppExec commands
// This line calls the bat file and creates a file tempcmd.sh with unix commands in it
"$(NPP_DIRECTORY)\unix_make_all.bat" $(CURRENT_DIRECTORY) >tempcmd.sh`
// This line connects to a remote machine and runs all the commands stored in tempcmd.sh
"$(NPP_DIRECTORY)\plink.exe" -ssh -2 -l username -pw password 192.168.000.000 -m "$(NPP_DIRECTORY)\tempcmd.sh"
Using the NppExec options i save the above commands and place a shortcut in the macros menu

QProcess limitations assistance

Hello all I have come around a limitation of QProcess. If I use '|' then it skips the process but I need that '|' character in my process
Suppose I have a exe and I need '|' in its arguments list then it doesn't work because command prompt takes '|' as OR. and therefore it skips the preceding part.
e.g: myfile.exe arguments1 | arguments2
Now in above code you can see the '|' the arguments which separates the two arguments and is required by myfile.exe to perform the operation but due to '|' character it skips the part before that and it gives me output as
'arguments2' is not recognized as internal or external, operable program or batch file
How do I overcome this weird situation? I need '|' in my arguments list but process recognizes it as a OR.
Let me tell you guys the actual sitation. I am trying to extract a .cpio.gz archive using
gzip -d -c myarchive.cpio.gz | cpio -i
but due to | in the arguments I get output as
'cpio' is not recognized as internal or external, operable program or batch file
but if I run the ported linux binary of gzip in ubuntu then it works exactly as i wanted because the linux terminal doesn't recognizes | as OR
Please I need help
Thank you
QProcess is doing what you want it to do: pass the whole line of command to the shell. The problem is you either don't have the second program cpio installed or it's not in the PATH environment of your Qt executable.
Does that line of command work when you enter it in (I assume) Windows command prompt?
BTW. The vertical bar character is a pipeline, not an argument to the .exe. That line of command actually invokes 2 separate programs.

Crontab : Running a jar file

I have a jar file that generates reports and i want to schedule to run it on every sunday,
For this purpose, i am using the crontab functionality on linux,
i have created the crontab entry using
crontab -e
45 15 * * 1 /usr/java/default/bin/java -jar /home/name/example/withouttimer.jar
but the job does not run as it should, Can you please help me find the issue with it,
Is there a way to check crontab logs?, thanks
Probably the profile used when running cron jobs does not have some variables set (JAVA_HOME? CLASSPATH?)
Do a crontab that does printenv > myfile.txt and check what is defined.
As a last test, create a .sh file and run it, that does
echo 'hello'
printenv
echo 'goodbye'
and see if redirecting the execution of your script to a log shows something.
That job runs at 3:45 pm on every monday (0 is for sunday)Are you sure you are checking it at right time?
Try running a dummy program at lesser interval to check whether its working.
Finally got the solution,
There was a couple of things that i was doing incorrectly,
The timezone of the server was different, so i had to set it accordingly.
The jar was not able to locate the input file(bad location), had to fix it.
Works gr8 now, thanks for the suggestion on adding MAILTO= , helped in debugging.

Ksh Script automatically calling another script in /usr/bin

I am executing a ksh script named abs.ksh located at /app/fao.... which connects to a server,
But the server is receiving a script named "ksh" which is present in /usr/bin...
I am not calling any script called ksh in abs.ksh(sorry cannot paste the code).
Also this happens only when the script is run in debug mode.
In non debug mode it works fine.
Can anyone give me a hint of what might be happening here.
In a standard "classic" Unix environment there may be multiple shells. E.g. 'sh' the original Bourne shell, 'ksh' - the Korn shell, csh - the C shell, bash, tcsh etc. etc.. A user login will have the default shell set per login.
The #! at the start of an executable script is an instruction to interpret & run the subsequent text with the name of the program following the '#!'.
E.g. run this with perl
#!/bin/perl
<.. perl stuff ..>
So yes #!/usr/bin/ksh - will run the script with the command interpreter (shell) at that location.
Need more info. wrt how you run in debug mode. I.e. are you typing 'ksh -x ...' or 'sh -x' - if so where is that on your search path. E.g. 'whence ksh' - maybe you're running with a different shell in debug mode.
Also which os is this ?

Resources