0

I am trying to create a bash script to operate another bash script through CRON without the need for human intervention.

The script needs to be able to interact with the other script so that it accomplishes:

Enter
Press a number..
Then takes you to another section of the script where you need to enter another number..
Then enter another number..
Press enter again..

I can't get the script to hit Enter correctly. What I have so far, "echo | ./module1.sh" flickers, even tried "echo "\n"" which doesn't work.

#!/bin/bash
cd /home/usernamehere/scripts
echo | ./module1.sh
echo "1"

This script requires a person to sit at the terminal while it finishes what it needs to or be run in a tmux session with the user safely exiting the session.

5
  • Be more specific "doesn't work" is not enough Commented Sep 13, 2020 at 5:01
  • 1
    Try linux.die.net/man/1/expect which could be a solution to your problem (whatever it is) Commented Sep 13, 2020 at 5:03
  • The use of "\n" doesn't work, not sure what else I could say? I did list other methods, the other being flickering when the script is ran. Commented Sep 13, 2020 at 5:14
  • How does the other script prompt the user for "Enter" - possible that it wait on terminal (e.g. /dev/tty, or /dev/stderr) ? Commented Sep 13, 2020 at 6:09
  • What I got from the other script, which I did not make, is "echo Press Enter To Continue... read upd" Commented Sep 13, 2020 at 6:36

1 Answer 1

1

If everything is read from stdin (as opposed to from the terminal device--which is what passwd and screen editors do), and the script requires you to enter ENTER, 1, 2 and 3, you can run it with

printf '\n1\n2\n\3\n' | ./module1.sh

An alternative is with a here-document (read your shell's manual page):

./module1.sh << EOF

1
2
3
EOF
Sign up to request clarification or add additional context in comments.

1 Comment

Hello, yes all input is interactive. I tried both of your suggestions, and with both options the numbers don't work with prompt, the field becomes empty, although when adding a hexadecimal value it does work. Using echo didn't help either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.