Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to automate a Unix command script and pipe the output to mailx so I can know if I need to manually edit files before FTPing them. A lot of this is automated, but due to a bug I need to manually pause the automation process if a script detects certain data.

I'm trying to run the script display_orders. After you start the script, it asks for input and then returns output. I need to give the script a TargetSubID value and then redirect the output to mailx.

username@unix$ display_orders
TargetSubID: BROKERA
Size:
Side:
Symbol:

There were 3 trades found!

The TargetSubID, Size, Side, and Symbol are prompts for input. You can either type a value you'd like to search for or hit enter to continue to the next prompt. At the last prompt the script takes all the input and does it's magic, and returns the values based on the input.

I've tried doing things like:

display_orders << EOD
? BROKERA
?
?
?
?EOD

But the script does runs and seems like there is an input parsing issue (which I don't expect you to troubleshoot). Looking at the code for display_orders it looks fairly standard Perl, chomping the input and parsing it.

I'd like to just get a command line solution for this so I can add it to my cron jobs (plus I've always been curious how to automate input based console applications).

I've tried googling but my google fu is weak on this topic apparently. I think I just want to redirect input to the console application but I think I'm fundamentally not understanding how the << operator works.

In the end I'd like a solution that might look similar to this (I realize this doesn't work but this may help someone understand what I'm trying to do):

display_orders << BROKERA | mailx -s 'Daily OATS Check' some@email.com
share|improve this question
    
Maybe try expect? AFAIK it's designed for more complicated automation tasks than can be handled with piping to standard in. –  Daniel Beck Feb 8 '13 at 18:51
    
expect isn't on my system. I can't man expect and when I just type expect i get this: ld.so.1: expect: fatal: libtcl8.4.so: open failed: No such file or directory Killed –  ramonecung Feb 8 '13 at 18:54
    
also, adding packages and such is not a possibility as I have limited access in prod and any system changes would likely take 6+ months to go through approvals, ect. thanks for the suggestion! –  ramonecung Feb 8 '13 at 18:56
    
Tcl is a requirement for expect, true. –  Daniel Beck Feb 8 '13 at 18:57

1 Answer 1

I think the missing ingredient is how your display_orders script works (ie without specifics the problem can't be properly solved).

"expect" is definately the "best" solution.

I did, however, come up with a quick-and-nasty hack which might (but probably won't) work for you. If the problem is a slight delay in inputs confusing the display_orders script, and its not time sensitive, you could blindly wait a short period between responses -

(
echo $BROKERA
sleep 1
echo $Size
sleep 1
echo $Side
sleep 1
echo $Symbol
) | display_orders | mailx -s 'Daily OATS Check' some@email.com

of-course the sleep 1 can be changed to a longer value and $BROKERA, $SIZE, $Side and $Symbol are already set. Its a cludge because it has no feedback to check if it's answering the right question, and its slow and generally yuk, but it probably does not have any special software prerequisites over and above what is on most systems)

share|improve this answer
    
interesting. that does make sense. i know there's a get_input function in the display_orders script that seems to have the prompt text and wait for input terminated by the enter key. i'll take a look at this and see if it helps. thanks much! –  ramonecung Feb 11 '13 at 13:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.