1Date: Fri, 21 Sep 2001 14:50:29 -0400 2From: "Jason M. Felice" <jfelice@cronosys.com> 3To: bash-maintainers@gnu.org, chet@po.cwru.edu 4Subject: Bash co-processes functions 5Message-ID: <20010921145029.A6093@argo.eraserhead.net> 6Mime-Version: 1.0 7 8Attached to this message you will find coprocess.bash and coshell.bash. 9Here's a brief synopsis of use: 10 11coprocess open telnet localhost 12while coprocess read il ; do 13 echo "$il" 14 case "$il" in 15 *ogin:*) 16 coprocess print 'user' 17 ;; 18 *ord:*) 19 echo 'pass' |coprocess print --stdin 20 ;; 21 *$ *) 22 coprocess print 'exit' 23 break 24 ;; 25 esac 26done 27coprocess close 28 29And here's an example of the coshell function: 30 31coshell open ssh -l root otherbox 32coshell eval hostname 33coshell ls -l 34if coshell test -d /tmp ; then echo 'otherbox has a /tmp!' ; fi 35 36coshell sendfile /var/lib/upgrade.rpm /tmp/test.rpm || exit $? 37coshell eval rpm -ivh /tmp/test.rpm || exit $? 38coshell eval rm -f /tmp/test.rpm || exit $? 39coshell close 40exit 0 41 42There are a few minor issues that I'd like to work out, but it works well 43enough for me ;-) The issues are: 44 45- Shell quoting issue with 'coshell eval' commands - need to somehow 46 re-quote words. 47- Interactive commands hang 'coshell eval', tried redirecting in </dev/null 48 to executed command, but it caused strange shell exit problems. 49- Some way to copy stdin from local coshell eval to remote shell. Probably 50 logically impossible, but would be wonderfully useful. 51 52I'm using it for writing scripts to publish websites and other scripts to 53co-located servers. 54