- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to write shell script for interact with binary...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2009 07:08 AM
04-16-2009 07:08 AM
Solved! Go to Solution.
- Tags:
- tty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2009 07:30 AM
04-16-2009 07:30 AM
SolutionElse the more easy way to interact with a program is to use coprocess
example:
#!/usr/bin/ksh
telnet localhost |&
exec 3>&p 4<&p
sleep 1
echo laurent >&3
sleep 1
echo mypasswd >&3
echo echo debut>&3
while read a
do
if [ "$a" = "begin" ]
then
echo ls >&3
echo exit >&3
cat &
break
fi
done
done <&4
but if your application is using /dev/tty
- like more- , then you can't do that, but you must use
a telnet localhost to have a tty, then being able to echo and read from it.
#!/usr/bin/ksh
telnet localhost |&
exec 3>&p 4<&p
sleep 1
echo laurent >&3
sleep 1
echo mypasswd >&3
echo echo debut>&3
while read a
do
if [ "$a" = "begin" ]
then
echo more /var/adm/syslog/syslog.log >&3
cat &
sleep 2
echo >&3
echo >&3
echo >&3
break
fi
done
done <&4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2009 09:13 PM
04-16-2009 09:13 PM
Re: How to write shell script for interact with binary application(tty problem)?
Where are you getting it? From /etc/profile or ~/.profile? If so, you need to fix them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2009 10:19 PM
04-16-2009 10:19 PM
Re: How to write shell script for interact with binary application(tty problem)?
But yes, you can use expect if you have it installed in your environment. Actually Expect somehow a component or extension of TCL language;
http://en.wikipedia.org/wiki/Expect
you can use Expect it is very suitable for interact and most cases it is similar to TCL and user friendly.
http://en.wikipedia.org/wiki/Tcl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2009 06:47 AM
04-17-2009 06:47 AM
Re: How to write shell script for interact with binary application(tty problem)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2009 07:05 AM
04-17-2009 07:05 AM
Re: How to write shell script for interact with binary application(tty problem)?
are you starting your script from a console, a telnet session? a ssh session a rlogin session?
or a ssh remote command remsh remote command?
else if the application need to run in a pty with a pty as stdin/stdout/stderr, the more easy to do it is using telnet coprocess
because you can pipe to/from telnet process and it will be transmitted to your application through a pty.
so
#!/usr/bin/ksh
telnet localhost |&
exec 3>&p 4<&p
sleep 1
echo myuser >&3
sleep 1
echo mypass >&3
sleep 2
echo mycmd >&3
=======
then when you read from 4 ( read -p 4 a )
and and pass answers using echo "answers" >&3
- Tags:
- tusc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2009 06:16 PM
04-17-2009 06:16 PM
Re: How to write shell script for interact with binary application(tty problem)?
for z in `cat terminate_list.txt`
do
VENDER_tool << EOT
logoff user=$z
quit
EOT
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2009 12:07 AM
04-18-2009 12:07 AM
Re: How to write shell script for interact with binary application(tty problem)?
What happens when you use your script? You get that "Not a tty" every time through the loop?
Can your VENDER_tool take multiple lines with:
logoff user=User1
logoff user=User2
If so, you should at least batch them up so you only invoke it once:
(
for z in $(< terminate_list.txt); do
echo "logoff user=$z"
done
echo quit
) > tool_input
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2009 10:19 AM
04-18-2009 10:19 AM
Re: How to write shell script for interact with binary application(tty problem)?
#!/usr/bin/ksh
telnet localhost |&
exec 3>&p 4<&p
sleep 1
echo username >&3
sleep 1
echo password >&3
sleep 2
echo >&3
sleep 1
echo >&3
sleep 1
echo >&3
while read a
do
(
for z in $(< terminate_list.txt); do
echo "logoff user=$z"
done
echo quit
) > VENDER_tool
cat &
sleep 2
echo >&3
echo >&3
echo >&3
break
done <&4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2009 05:25 PM
04-18-2009 05:25 PM
Re: How to write shell script for interact with binary application(tty problem)?
Not exactly. ;-)
Before your while:
# here you should read all of the input from your login. This decades old trick may work:
echo "echo EOF1" >&3
while read A; do
if [ "$A" = EOF1 ]; then break; fi
echo "$A"
done <&4
echo VENDER_tool >&3
Replace your while:
(
for z in $(< terminate_list.txt); do
echo "logoff user=$z"
done
echo quit
) >&3
# I'm assuming the buffers are large enough so you don't have to read each reply?
# Here you should read all of those replies. except you don't have an idea when to quit.
echo "echo EOF2" >&3
while read A; do
if [ "$A" = EOF2 ]; then break; fi
echo "$A"
done <&4
# now logoff
echo "exit" >&3
# terminate telnet (You'll need control V to enter that control char.)
echo "^]" > &3
echo "quit" >&3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2009 12:54 AM
04-19-2009 12:54 AM
Re: How to write shell script for interact with binary application(tty problem)?
echo "echo EOF1" >&3
while read A; do
if [ "$A" = EOF1 ]; then break; fi
echo "$A"
done <&4
It struck at EOF1 and not going to run into next step.
> echo EOF1
EOF1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2009 03:39 AM
04-19-2009 03:39 AM
Re: How to write shell script for interact with binary application(tty problem)?
(I tossed your while out.)
echo "echo EOF1" >&3
while read A; do
if [ "$A" = EOF1 ]; then break; fi
echo "LOOP1: $A"
done <&4
I just added "LOOP1:" above so you know which is which.
>It's struck at EOF1 and not going to run into next step.
Hmm. What stuff is echoed there? The intention is that the "remote" shell is going to see that echo and echo EOF1. Then the script will break out of the loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2009 09:44 PM
04-22-2009 09:44 PM
Re: How to write shell script for interact with binary application(tty problem)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2009 10:26 PM
04-22-2009 10:26 PM
Re: How to write shell script for interact with binary application(tty problem)?
What was it you fixed that made it work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2009 10:06 PM
04-23-2009 10:06 PM
Re: How to write shell script for interact with binary application(tty problem)?
echo "echo EOT2" >&3
while read a
do
case $a in
*EOT2*) break ;;
esac
echo "$a"
done <&4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2009 10:28 PM
04-23-2009 10:28 PM
Re: How to write shell script for interact with binary application(tty problem)?
I was wondering if there were extra stuff on the lines. If you actually echo $a, you might find out what's extra. The prompt?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2009 11:05 PM
04-23-2009 11:05 PM
Re: How to write shell script for interact with binary application(tty problem)?
#!/bin/ksh
telnet localhost |&
exec 3>&p 4<&p
sleep 1
echo myuser >&3
sleep 1
echo mypass >&3
sleep 3
echo >&3
sleep 1
echo >&3
sleep 1
echo >&3
sleep 1
echo VENDER_tool >&3
sleep 1
(
for z in $(< terminate_list.txt); do
echo "logoff user=$z"
done
sleep 2
echo quit
) >&3
cat &
sleep 2
echo >&3
echo >&3
echo >&3
echo "echo EOT2" >&3
while read a
do
case $a in
*EOT2*) break ;;
esac
echo "$a"
done <&4
echo "exit" >&3
It seems after script terminated by got EOT2 and break. It will not process on echo "exit" >&3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2009 12:26 AM
04-24-2009 12:26 AM
Re: How to write shell script for interact with binary application(tty problem)?
You didn't put all of this at the end of your script:
# now logoff
echo "exit" >&3
# terminate telnet (You'll need control V to enter that control char.)
echo "^]" > &3
echo "quit" >&3
>It will not process on echo "exit" >&3
Do you ever get to this echo?
What happened to my EOF1 loop before you start VENDER_tool?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2009 07:50 PM
04-28-2009 07:50 PM
Re: How to write shell script for interact with binary application(tty problem)?
#!/bin/ksh
telnet localhost |&
exec 3>&p 4<&p
sleep 1
echo myuser >&3
sleep 1
echo mypass >&3
sleep 3
echo >&3
sleep 1
echo >&3
sleep 1
echo >&3
sleep 1
echo "echo EOF1" >&3
while read a
do
case $a in
*EOF1*) break ;;
esac
echo "$a"
done <&4
echo VENDER_tool >&3
sleep 1
(
for z in $(< terminate_list.txt); do
echo "logoff user=$z"
done
sleep 2
echo quit
) >&3
cat &
sleep 2
echo >&3
echo >&3
echo >&3
echo "echo EOT2" >&3
while read a
do
case $a in
*EOT2*) break ;;
esac
echo "$a"
done <&4
echo "exit" >&3
echo "^]"&3
echo "quit" >&3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2009 09:39 PM
04-28-2009 09:39 PM
Re: How to write shell script for interact with binary application(tty problem)?
I was never sure what this did?
cat &
It seems like it hangs waiting for input?
Some typos here:
echo "exit" >&3 # this should exit the remote shell and not be seen
# Need to use control-] on the next line:
echo "^]" >&3 # this should escape from telnet
echo "quit" >&3 # this should quit telnet
I'm assuming we don't have to read from 4 here and the buffer is large enough?
You might want to remove the VENDER_tool loop to make sure the rest work.