Automating an interactive process with EOF string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automating an interactive process with EOF string
# 1  
Old 02-08-2018
Ubuntu Automating an interactive process with EOF string

Hello,

I'm running Stockfish chess engine ( Home - Stockfish - Open Source Chess Engine ) CLI on Linux in interactive mode which is working fine.

Code:
root@ubuntu1950x:~# ./stockfish
Stockfish 080218 64 POPCNT by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
setoption name Debug Log File value /tmp/st_log
position fen r2r4/p4ppk/P5np/1p2pQ2/8/2P2P1P/4q1P1/R2R2BK w - - 0 36
setoption name Threads value 1
setoption name Hash value 128
setoption name multiPV value 2
go movetime 4000
info depth 1 seldepth 1 multipv 1 score cp 114 nodes 162 nps 81000 tbhits 0 time 2 pv d1d8 a8d8 g1a7
info depth 1 seldepth 1 multipv 2 score cp 97 nodes 162 nps 81000 tbhits 0 time 2 pv d1e1
...
...
info depth 23 seldepth 39 multipv 1 score cp 26 nodes 9052891 nps 2261526 hashfull 466 tbhits 0 time 4003 pv f5e4 d8d1 a1d1 e2d1 e4a8 d1f1 a8a7 b5b4 c3b4 g6f4 a7f2 f1a6 f2c2 h7g8 g1e3 a6f1 h1h2 g7g5 e3f4 e5f4 c2e4 f1f2 b4b5 g8g7 e4b4 f2b6 b4a4 f7f6 a4a6 b6f2 a6b7 g7g6 b5b6
info depth 22 seldepth 32 multipv 2 score cp 0 nodes 9052891 nps 2261526 hashfull 466 tbhits 0 time 4003 pv d1e1 e2b2 f5f7 d8d2 a1b1 b2c2 f7b7 a8f8 e1c1 c2a2 b1a1 a2b2 c1b1 b2c2 b1c1 c2b2
bestmove f5e4 ponder d8d1
^C
root@ubuntu1950x:~#

When the above is run, it displays so many lines but I included only first 2 and last 2 lines (to improve readability of the post). I mentioned whatever I type in "RED" letters so you are aware what we type and what to expect. The above process runs for 4 seconds (as I mentioned movetime as 4000 milliseconds) and in the end it gives bestmove.

In order to automate the above process (I will later keep all the required inputs as command-line parameters if this below shell script works fine) I've written below shell script:

Code:
root@ubuntu1950x:~# cat test.sh
#!/bin/bash
/root/stockfish <<EOF
setoption name Debug Log File value /tmp/st_log
position fen r2r4/p4ppk/P5np/1p2pQ2/8/2P2P1P/4q1P1/R2R2BK w - - 0 36
setoption name Threads value 1
setoption name Hash value 128
setoption name multiPV value 2
go movetime 4000
EOF

root@ubuntu1950x:~#

But it exits immediately as opposed to be run for 4 seconds (though shows bestmove which is NOT correct).

Code:
root@ubuntu1950x:~# date; ./test.sh ; date
Thu  8 Feb 22:40:51 GMT 2018
Stockfish 080218 64 POPCNT by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
bestmove g2g3
Thu  8 Feb 22:40:51 GMT 2018
root@ubuntu1950x:~#

I also tried a blank line before and after EOF string in my script and also with no blank lines but none of them helped. I'm totally puzzled on how to fix this Smilie

I assure you that this engine is the best and most reliable chess engine (available under GPL license) and is 100% safe to run on any computer. In order to reproduce this issue, please download the binaries from Stockfish Development Versions (linux version runs only on Ubuntu type OS's not RHEL/CentOS type). You can also compile your own version by getting source from github ( GitHub - official-stockfish/Stockfish: UCI chess engine )

My Server OS config:
Code:
root@ubuntu1950x:~# uname -a
Linux ubuntu1950x 4.13.0-16-generic #19-Ubuntu SMP Wed Oct 11 18:35:14 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
root@ubuntu1950x:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 17.10
Release:        17.10
Codename:       artful
root@ubuntu1950x:~# bash --version
GNU bash, version 4.4.12(1)-release (x86_64-pc-linux-gnu)
Copyright © 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
root@ubuntu1950x:~#

Appreciate any help, thanks!
# 2  
Old 02-08-2018
Perhaps stockfish is closing as it's input pipe has closed.

Try something like this:

Code:
#!/bin/bash
(cat <<EOF
setoption name Debug Log File value /tmp/st_log
position fen r2r4/p4ppk/P5np/1p2pQ2/8/2P2P1P/4q1P1/R2R2BK w - - 0 36
setoption name Threads value 1
setoption name Hash value 128
setoption name multiPV value 2
go movetime 4000
EOF
sleep 4.1 ) | /root/stockfish

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 02-08-2018
Many thanks Chubler_XL Smilie It worked like a charm Smilie

I've been trying to solve it for many days and you solved it in no time, I'm speechless SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automating Mail Process

Hi i had written one script,it sends email from terminal and mine script is as: #!/bin/bash SUBJECT="linux mail send attachment example" BODY_FILE="/home/sreenivasa/Desktop/Testing.txt" #ATTACHMENT_FILE="/home/sreenivasa/Desktop/Dataset.zip"... (23 Replies)
Discussion started by: rajnikant
23 Replies

2. UNIX for Dummies Questions & Answers

Automating a process

Could any one tell me , how to start a thread here, i just searching for so long. sorry to post in irrelavent here ---------- Post updated at 08:19 AM ---------- Previous update was at 08:00 AM ---------- Hi, I got a requirement to automate the process. We have SLA files, there are... (1 Reply)
Discussion started by: afahmed
1 Replies

3. UNIX for Advanced & Expert Users

Automating Interactive password change

I have written the below scripts . ldap_pwd_prompt.ksh #!/usr/bin/ksh passwd -r ldap interactive_pwd_change.exp #!/usr/local/bin/expect set timeout 10 set curpass set newpass spawn ./ldap_pwd_prompt.ksh expect "Enter existing login password:" send "$curpass\r" expect "New... (6 Replies)
Discussion started by: dr46014
6 Replies

4. Shell Programming and Scripting

Automating The process

Hi Guru's, I am trying to write a scripts that will automate my image provisoining process. Scenario: I have Linux Image Hosted on cloud which needs to be provisoned before it can be used. Currently we log onto the image through the putty on windows and connect to linux instance. I... (3 Replies)
Discussion started by: taqvia
3 Replies

5. Shell Programming and Scripting

automating daily monitoring process

Hi there, I have to automate daily monitoring process and then the result of these process should be sent to a log file, then this log file should be mailed . ps -ef | grep aa In this atleast one process should run. If the process is running it should mention Success in the log file... (3 Replies)
Discussion started by: NehaKrish
3 Replies

6. Shell Programming and Scripting

Automating Interactive script

I have a script that will install software on all remote host. At the end of the script it starts the install.sh part and goes into a interactive mode asking Yes or No questions and prompting to add a username and password. My question is how can I script this so that these questions are... (7 Replies)
Discussion started by: soupbone38
7 Replies

7. Linux

Automating build and test process

Hey ppl, I've been asked to automate the build and test process for my team at office.we work on Linux and use Perforce for SCM. I've just joined this company and dont have much knowledge on unix scripts. Could someone tell me how to go about doing this?:confused: (8 Replies)
Discussion started by: laxmi
8 Replies

8. Shell Programming and Scripting

Automating build and test process

Hey ppl, I've been asked to automate the build and test process for my team at office.we work on Linux and use Perforce for SCM. I've just joined this company and dont have much knowledge on unix scripts. Could someone tell me how to go about doing this? (0 Replies)
Discussion started by: laxmi
0 Replies

9. Shell Programming and Scripting

find eof, then process

Newbie question. I want to create a shell script that will only move/copy a file if it's determined that the eof string exists. This is to control files being uploaded via FTP. I don't want to move incomplete files, so my only thought is to check for eof, or compare file size every 15-30 seconds on... (12 Replies)
Discussion started by: mfilby
12 Replies

10. Shell Programming and Scripting

Automating interactive scripts

Hi all, I am trying to write a program that will automate interactive scripts that use 'pkgadd'. Easily enough I can use 'pkgask' and a response file for most of what I want to do, but unfortunately there are parts of some pkg installations that are configured to only take input from /dev/tty!!... (2 Replies)
Discussion started by: bookoo
2 Replies
Login or Register to Ask a Question