Usernamehere
Usernamehere

Reputation: 1

Bash script to operate another script

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.

Upvotes: 0

Views: 60

Answers (1)

Jens
Jens

Reputation: 72619

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

Upvotes: 1

Related Questions