How to pass input to interactive command using ansible? - unix

I have a command to execute on Unix server. The command expect user input at two points and then proceed further. The command is like follows:
$ abc_1.2_udate.bin /tmp/log
Do you want to proceed y/n?
y
Please provide the credentials:
1234
From ansible tried as follows:
- name: execute the cmnd
expect:
Command: abc_1.2_udate.bin /tmp/log
responses:
Do you want to proceed y/n? "y"
'Please provide the credentials:' "1234"
But the above piece does not work. Also I want to use expect module only for this.

Change Command to command (C is not caps)
Responses should be given in quotes with the format 'Enter': "y"
expect:
command: abc_1.2_udate.bin /tmp/log
responses:
'Do you want to proceed y/n?': "y"
'Please provide the credentials': "1234"

Related

interact with the sample CorDappVia the interactive shell

When i checked the output :run vaultQuery contractStateType: com.example.state.IOUState
it show :
Could not parse as a command: Cannot construct instance of java.lang.Class, problem: com.example.state.IOUState
at [Source: UNKNOWN; line: -1, column: -1]
I typed net.corda.samples.example.states.IOUState and it worked.
You see the package name in ExampleFlow.kt.
Nice #shok1122.
Paste & run: run vaultTrack contractStateType: net.corda.samples.example.states.IOUState

Read Until usage in robot framework with constant changing prompt

I'm new to robot framework. I'm trying to create a Keyword in my suite to login to DUT, run a command and fetch the output. but the prompt of the DUT is constantly changing. Following is the keyword and also the command output in DUT.
Keyword snippet:
Write show table sys ClassOfService
${output}= Read Until Regexp admin#0-9 .*\>
command output in DUT:
admin#0-9 19:36:44> show table sys ClassOfService
profileXml "<?xml version=\"1.0\" encoding=\"UTF-8\"?><cos version=\"1.0\"> <PublicIdentifiers>
</PublicIdentifiers> \t\t\t </cos>";
[ok][2020-04-11 19:36:45]
admin#0-9 19:36:45>
But it is always getting timeout. Please let me know if I'm missing something.
Thanks in Advance
Your regular expression looks good, but in Robot Framework the > must have the \ escaped with another \. Look at the example for Read Until Regexp. Your final command should be:
Write show table sys ClassOfService
${output}= Read Until Regexp admin#0-9 .*\\>

Prompt in zsh starts with ↑255 after an error command?

I'm new to zsh and am using the ZSH_THEME="jnrowe", which works great for a little while.
It starts out and I get a prompt that looks like this:
Ξ ~ →
but if I run a command like: ssh it becomes:
↑255 ~ →
I suspect something is messing up the character that was creating the triple bar in the first one, but have no clue really as to what's going on. I could just pick a different theme, but I've noticed most of them with a fancy character in the prompt do the same thing.
Is this a special error code or something? Or is something just borking out?
I don't know the prompt theme "jnrowe" (it's not part of the default zsh distribution afaics), but I suspect this prompt includes the error code of the last command in its output.
Try to run "ls" or "true" and the number will disapper. Run "false" and it will be 1, run ssh without arguments and it will be 255. zsh preserves this value until you run the next command, so pressing ENTER many times will not clear it.
(This will be the same value that is stored in the shell variable "$?")

R, passing variables to a system command

Using R, I am looking to create a QR code and embed it into an Excel spreadsheet (hundreds of codes and spreadsheets). The obvious way seems to be to create a QR code using the command line, and use the "system" command in R. Does anyone know how to pass R variables through the "system" command? Google is not too helpful as "system" is a bit generic, ?system does not contain any examples of this.
Note - I am actually using data matrices rather than QR codes, but using the term "data matrix" in an R question will lead to havoc, so let's talk QR codes instead. :-)
system("dmtxwrite my_r_variable -o image.png")
fails, as do the variants I have tried with "paste". Any suggestions gratefully received.
Let's say we have the variable x that we want to pass on to dmtxwrite, you can pass it on like:
x = 10
system(sprintf("dmtxwrite %s -o image.png", x))
or alternatively using paste:
system(paste("dmtxwrite", x, "-o image.png"))
but I prefer sprintf in this case.
Also making use of base::system2 may be worth considering as system2 provides args argument that can be used for that purpose. In your example:
my_r_variable <- "a"
system2(
'echo',
args = c(my_r_variable, '-o image.png')
)
would return:
a -o image.png
which is equivalent to running echo in the terminal. You may also want to redirect output to text files:
system2(
'echo',
args = c(my_r_variable, '-o image.png'),
stdout = 'stdout.txt',
stderr = 'stderr.txt'
)

OCaml: unexpected exception with Unix.getlogin when stdin redirected

I found out the next issue in this simple code:
let () =
print_endline "Hello";
print_endline (Unix.getlogin ())
Running in the normal case, with ./a.out gives:
Hello
ricardo
But running like ./a.out </dev/null makes Unix.getlogin fail:
Hello
Fatal error: exception Unix.Unix_error(20, "getlogin", "")
Any idea why this happens?
Redirecting the input of a program overrides its controlling terminal. Without a controlling terminal, there is no login to be found:
$ tty
/dev/pts/2
$ tty < /dev/null
not a tty
You can, however, still find a user's name (perhaps) by getting the user's id (getuid) and looking up his passwd entry (related docs) (getpwuid), then finding his username in it.
Depending on your application:
if you don't really care about the value returned by "getlogin", you can do something like:
try
Unix.getlogin ()
with _ -> Sys.getenv "USER"
you will probably get something better than getuid, since it will also work for programs with Set-User-ID flags (sudo/su).
if you really care about the value returned by "getlogin", i.e. you really want to know who is logged in, you should just fail when getlogin fails. Any other solution will give you only an approximation of the correct result.

Resources