0

I have to set in crontab an sh script that prompts user to answer before executing. But sometimes the question needs "Yes" or "No" answer and sometimes the same script waits for "Force" or "Abort". I can't modify this script, so i need to make my script to launch the first one, catch the prompt output text and check the prompt text to answer "Yes" or "Force" automatically. I've tested something like this but doesn't work :

if command.sh | grep 'Force' =0
then echo "Force"
else echo "Yes"
fi

Thank you for your advices or help :)

nicopoal
  • 11
  • 1
  • 5
  • Forgot to say Hi everyone and edit seems not working :-/ – nicopoal Nov 23 '21 at 12:05
  • The way to achieve that would be by using fifos. It might not even be possible at all, depending on how `command.sh` was written. – Fravadona Nov 23 '21 at 12:07
  • @Fravadona , i don't know, i don't have access to the code of this command.sh script, i juste need to launch it with a cron job and therefore answer "Yes" or "Force" automatically ... – nicopoal Nov 23 '21 at 13:29
  • Does this help you? https://stackoverflow.com/a/25541986/3387716 – Fravadona Nov 23 '21 at 14:46
  • @Fravadona I feel that there is an interesting clue there but I am not good enough in shell scripting to adapt to my precise needs :-/ – nicopoal Nov 24 '21 at 11:01
  • Can you add samples of what `command.sh` prompts when asking for a reply? – Fravadona Nov 24 '21 at 12:40

1 Answers1

0

Finally I tried a simpler solution and it seems working as expected

command.sh << EOF
Force

y

EOF

Thank for your help

nicopoal
  • 11
  • 1
  • 5