chat Utility

I am seeking a general utility that can communicate from a batch script with an interactive program such as smbclient. I want to invoke the shell script and have no further interaction.  Is chat the program?  Is another better?  Where can I find it? I'm running RedHat 6.5, Mandrake
RonJDAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

t2ppCommented:
For smbclient, use the -c option and seperate your commands with a semicolon. This works very well.
0
RonJDAuthor Commented:
This answer solves my immediate problem--thanks!  
But my question was more general.  Is is the norm in Linux for applications to have command-line options that can be operated in batch mode. If not, is there a keystroke emulation program out there that can automatically interact with programs that require a dialog with the user?
0
RonJDAuthor Commented:
Adjusted points to 75
0
crouchetCommented:
The answer is -- sometimes.

Many Linux programs and utilities do have command line options that will eliminate the need for interaction. To find out for a specific program, go to the command line and type:

man YOURCOMMAND <enter>

so if you wanted to find out about smbclient you would type:

man smbclient

Some also give you "useage" information. Type:

smbclient -?
or
smbclient -help
or
smbclient --help

If there is no command line option then you may be able to redirect the input of your responses from a second script, like this:

smbclient < myscript

Where myscript is a file with the responses you want to send. WHether this works is according to whether (and how) the program accepts it's input from standard in (stdin). You will probably just have to try it to find out.

Here is another way to redirect the input. This is called a "here document" as it eliminates the need for that second script file by letting you put your commands directly in the script file that contains the command itself.

smbclient << EOF
myservicename
mypassw0rd
EOF

EOF is not an eof character, but the letters E, O and F. That could be something else like END, but EOF if the standard most programmers will recognize.

Notice that EOF **MUST** be the first and only thing on a line all by itself to terminate the input. The <enter>s at the ends of the lines register just like hitting the enter key during interactive input. This method works reasonably well for many programs, but not all.

Generally, if there is a good reason to run a program from a script one or more of these methods will work. If the author forgot to include such capibility another programmer would add it through the magic of GPL, so by the time you get it the progam should have this capibility.

For more information on input redirection and shell scripts in general I recommend a book called "UNIX Shell Programming" by Stephen G. Kochan & Patrick H. Wood. ISBN 0-672-48448.  You might also find thier book "Exploring the UNIX System" , ISBN 0-672-48447-1 to be useful. I'll warn you that these are oldies, but they are easy to follow with clear examples and good indexes. They are also inexpensive.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.