The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script(s) to Automate Tasks droppedonjapan Shell Programming and Scripting 2 05-21-2008 07:32 AM
automate sftp using unix script priyamurthy2005 Shell Programming and Scripting 32 04-17-2008 05:29 AM
script to automate mksysb via nim in AIX 5.3 barkath Shell Programming and Scripting 0 12-20-2007 02:46 PM
here document to automate perl script that call script hogger84 Shell Programming and Scripting 3 10-22-2007 07:15 AM
Script to automate file comparisons herman404 Shell Programming and Scripting 6 03-17-2005 04:52 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-29-2002
Registered User
 

Join Date: Jan 2002
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Question automate the input in a script

I have a program that i have to run by cron. The program needs user input. So i have to automate that in a littke script.

start of script program.sh:

result=program.log; export result
echo Program starting : `date` >> $result
/usr/local/program >> $result
echo Program running : `date` >> $result


The program normally asks for a string (a pass phrase).
How can i do this ?

I know i have to use something like :

/usr/local/program >> $result 2>&1 <<eof
blablablabla
eof

but i don't get it to work

Thanks in advance
Forum Sponsor
  #2 (permalink)  
Old 01-29-2002
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Try something like...

...
/usr/local/program <<EOF >> $result 2>&1
blah
...
blah
blah
EOF
...

Note the contents of your blahblahblah file
would be placed directly "inline" in your
script being run by cron.
  #3 (permalink)  
Old 01-29-2002
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
The code did not translate properly when
posted

Should be...

Quote:
/usr/local/program <<EOF >> $result 2>&1
  #4 (permalink)  
Old 01-29-2002
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
OK... I guess "quoting" doesn't work either.

Let's try...

/usr/local/program < < EOF > > $result 2>&1

...I tried an extra space between the "<"'s
and ">"'s
  #5 (permalink)  
Old 01-30-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Note:
Try using the HTML equivelent, like:
&lt;&lt;&lt;&lt;/sample_tag&gt;&gt;&gt;&gt;

ampersand, lt, then semicolon for less than, and
ampersand, gt, then semicolon for greater than.
  #6 (permalink)  
Old 01-30-2002
Registered User
 

Join Date: Jan 2002
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
automate the input



I tried a lot of things.

When i start quoting i always get messages of command not found. I treid normal single quote ', double quote " and single right quote ` and single left quote ´. Which one should i be using ? Do i have to quote the whole line ? I tried the whole line and parts of the line.

I tried to put the blahblah on the same line .
When i use :

program <> $result 2>&1 << blahblah
the output is coming to my screen

When using spaces between the < < then i get syntax errors near the unexpected token <

Most of the times it keeps waiting for the input. When i enter the string (stays invisible to me) the program starts without problem.
  #7 (permalink)  
Old 01-30-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Check out expect: http://expect.nist.gov
You can supply interactive data in a script...
  #8 (permalink)  
Old 01-30-2002
Registered User
 

Join Date: Jan 2002
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
automate input

I'm not sure that i really understand what you're talking about.
i tried

program &lt< eof &gt> $result 2>&1 << blahblah

but i'm getting that the string is not the correct phrase.
  #9 (permalink)  
Old 01-30-2002
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
I'm assuming that...

program << eof >> $result 2>&1

...is inside a shell script.
In this script, you would simply enter the
actual responses thar "program" reads...

program << eof >> $result 2>&1
answer1
answer2
...
answer5
eof

The "<< eof" creates a "here document" which
basically says, redirect the standard input
to "program" to everything between the "eof"'s
The ">> $result says append the standard
output of "program" to whatever file $result
points to.
  #10 (permalink)  
Old 01-31-2002
Registered User
 

Join Date: Jan 2002
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Question automate input

Hello, thanks for your time, but still no solution

when i try

program << eof >> $result 2>&1
answer1
eof

the program just sits waiting. When i type the answer1-string myself, everything goes well.

I installed expect (and tcl --> both latest versions)
and tried the following script :

#!/usr/local/bin/expect
send_user "start expect\r"
spawn PROGRAM
expect "pass phrase:"
send "answer1\r"
send_user "stop expect\r"

This doesn't work either --> the program gets started, but finishes after displaying the question to enter the pass phrase.
The start en stop expect doesn't appear on screen also.

Has the fact that when in normal mode (outside a script) the pass phrase is entered it doesn't appear on the screen (password-like) ?

Thanks in advance

Erwin
  #11 (permalink)  
Old 01-31-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Expect is very literal in what it expects...
A single space can ruin an entire script.

You might get lucky using wildcards, like so:

expect "*pass phrase:*"

Just be careful not to use too many, in case you match another line somewhere...

Also, make sure you are getting the case correct;
"Pass" does not equal "pass"
  #12 (permalink)  
Old 01-31-2002
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
May I ask what "program" actually is?
It seems from your post that it is some
sort of program that requires a user
authentication (or password). Many programs
like this woun't let you redirect the
standard input by default but many also
provide other options to allow this sort
of redirection. In general, this is done
for security reasons (like the passwd program
itself).
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes


The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
421 service not available, remote server has closed connection ^m automate ftp autosys awk trim bash eval bash for loop boot: cannot open kernel/sparcv9/unix command copy/move folder in unix couldn't set locale correctly curses.h cut command in unix find grep find mtime find null character in a unix file grep multiple lines grep or grep recursive hp-ux ifconfig inaddr_any inappropriate ioctl for device lynx javascript mailx attachment mget mtime ping port remove first character from string in k shell replace space by comma , perl script rsync ftp scp recursive segmentation fault(coredump) sftp script snoop unix solaris change ip address stale nfs file handle syn_sent tar exclude tar extract to folder test: argument expected unix unix .profile unix forum unix forums unix internals unix interview questions unix mtime unix simulator unix.com vi substitute while loop within while loop shell script


All times are GMT -7. The time now is 03:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101