0

When my User logs in, I need to enter the following manually so I am trying to create a script to do it for me

. oraenv

The app asks me for input so I enter "M40" (same text every time)

Then I have to run a linux app to launch my work environment.

So how do I automatically enter M40 followed by an enter key

software is fun
  • 7,286
  • 18
  • 71
  • 129

2 Answers2

3

The oraenv script is prompting for a value for ORACLE_SID, so you can set that yourself in a .profile or elsewhere.

export ORACLE_SID=M40

It also has a flag you can set to make it non-interactive:

ORAENV_ASK=NO

Regarding piped input specifically, the script would have to be written to handle it, for example using read or commands such as cat without a filename. See Pipe input into a script for more details. However, this is not how the standard oraenv is coded (assuming that is the script you are using).

William Robertson
  • 15,273
  • 4
  • 38
  • 44
0

I am not sure if anyone of these operations helps you.

echo M40 | . oraenv

This one uses echo pipe.

printf M40 | . oraenv

This one uses printf for pipe. Using echo is different from using printf in some situations, however I don't know their actual difference.

. oraenv <<< M40

This one uses Here String (Sorry for using ABS as reference), a stripped-down form of Heredoc.

. oraenv < <(echo M40)

This one uses Process Substitution, you may see https://superuser.com/questions/1059781/what-exactly-is-in-bash-and-in-zsh for the difference between this one and the above one.

expect -c "spawn . oraenv; expect \"nput\"; send \"M40\r\n\"; interact"

This one uses expect to do automatic input, it has more extensibility in many situations. Note to change the expect \"nput\" part with your actual situation.

Geno Chen
  • 4,916
  • 6
  • 21
  • 39
  • `expect` won't work because `spawn` creates a new process and even if you could execute `.` (expect will try to execute your current directory) it cannot change the environment (which is what the script probably does) – Diego Torres Milano Jan 12 '19 at 07:12