0

I tried to pass username and password to the command '/opt/splunk/bin/splunk reload deploy-server' but its throwing "stdin appears to be a pipe" error , help me in fixing this error.

[splunk@ip-10-15-32-172 ec2-user]$ echo 'statraju QKGK=#ZNmHc0ao' | /opt/splunk/bin/splunk reload deploy-server
Splunk username:
An error occurred: Cannot prompt for password, stdin appears to be a pipe.

Another way: But same error

[splunk@ip-10-15-32-172 ec2-user]$ /opt/splunk/bin/splunk reload deploy-server << EOT
> statraju
> QKGK=#ZNmHc0ao
> EOT
Splunk username:
An error occurred: Cannot prompt for password, stdin appears to be a pipe.

Note: I don't want to use expect also I can get my command work using below way but I don't want /opt/splunk/bin/splunk reload deploy-server -auth statraju:QKGK=#ZNmHc0ao

sudhir tataraju
  • 1,159
  • 1
  • 14
  • 30
  • 1
    Splunk must be testing whether its stdin is a terminal (probably with `[ -t 1 ]`) which would explain the error encountered with pipes and heredocs. Could you explain the reasoning behind avoiding `expect` and the `-auth` flag so that someone may propose an alternative solution that fits your needs? – Aaron Jun 03 '19 at 09:12
  • @Aaron "expect" is not a default command needs to be installed, so I want to achieve with default commands only, as my script needs to run in multiple servers some have internet some not so, -auth works but what if -auth support not there ! want to know whether any other way to achieve this, also helps to improve my shellscript knowledge. – sudhir tataraju Jun 04 '19 at 05:58
  • Then you need to trick Splunk into beleveing the stdin on which you've put your credentials is a terminal. `Expect` would have been the tool of choice but if it isn't available you might want to consider using `script` which is more widely available : `echo credentials | script --return -qfc /opt/splunk/bin/splunk reload deploy-server` – Aaron Jun 04 '19 at 08:58
  • More info [here](https://stackoverflow.com/questions/1401002/trick-an-application-into-thinking-its-stdout-is-a-terminal-not-a-pipe), and I'm thinking this question might be closed as a duplicate of this other if it does indeed solve your problem. – Aaron Jun 04 '19 at 09:02
  • @Aaron echo credentials | script --return -qfc /opt/splunk/bin/splunk reload deploy-server not working – sudhir tataraju Jun 05 '19 at 14:21
  • @tripleee no answer in that linked question not working – sudhir tataraju Jun 05 '19 at 14:23
  • Then how about this? https://answers.splunk.com/answers/205165/cli-command-to-login-is-there-a-way-to-add-the-aut.html – tripleee Jun 06 '19 at 04:31
  • @tripleee I already mentioned in my question description that it's working if I pass using --auth again same solution you provided, without reading my question why you marked my question as duplicate. – sudhir tataraju Jun 06 '19 at 05:41
  • If Splunk offers a solution and you don't want to use it and insist that you want a solution which Splunk apparently works actively against, I think you'll need to [edit] your question to explain in more detail why you find the workaround unacceptable. (Sorry for missing your final note, though.) – tripleee Jun 06 '19 at 05:58
  • @tripleee: 'Aaron' in his comment asked same question which I explained, this question is to improve my shell scripting knowledge that's all. If no solution without 'expect' its ok, as nothing we can do about. I don't mean Splunk perspective, splunk is just an example I shared. – sudhir tataraju Jun 06 '19 at 08:27
  • 1
    I think the linked question is a correct duplicate for the generic aspect of your question : try `echo foo | { [ -t 0 ] && echo stdin is a terminal || echo stdin is NOT a terminal; cat; }` vs `echo foo | script --return -qfc '{ [ -t 0 ] && echo stdin is a terminal || echo stdin is NOT a terminal; cat; }'` : you'll see the command run by `script` believes its stdin is a terminal. Splunk's error message lead me to believe that's what it tests, but I guess not if the solution doesn't work. If `/opt/splunk/bin/splunk` is a shell script try running it with `bash -x` to see what it's testing – Aaron Jun 06 '19 at 09:29

0 Answers0