Script calls command that requires input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script calls command that requires input
# 1  
Old 08-15-2008
Script calls command that requires input

Greetings,

Newbie here on the site. I have searched for a similar issue but am not finding one.
I have a script that invokes a command if text is found in a file.
The command asks for a y/n response, but is not an option on the command, i.e. `command -y`.
I am familiar with the <<EOF, but I am stuck at getting this response read to automate the task.
Please help.
Thanks

Code:
 
#!/bin/ksh
PATH=mypath
SERV=`uname -n`
OUT=/path/to/.$SERV.out
 
grep '^text'  /my/file
RC=`echo $?`
if [ $RC = 0 ] ; then
  command -filename=$OUT << here is where I need a yes response
  else echo "my text" > $OUT
fi

# 2  
Old 08-15-2008
try doing
Code:
echo yes | command -filename=$OUT

or
Code:
 echo -n yes | command -filename=$OUT

# 3  
Old 08-16-2008
That did the trick.
Code:
echo yes | command -filename=$OUT

Misleading on the command line, as the command sits there like it is waiting for a response and the echo does not write to stdout.
The command completes and my file has the expected results.
Thanks!
# 4  
Old 08-16-2008
As an aside, RC=`echo $?` is a prime example of Useless Use of Echo. You want simply RC=$? (Useless Use of Test notwithstanding).

This is just a comment on style and succinctness. If you don't really care, just ignore it. Otherwise, Google for "useless use of" for more on the topic.

Code:
#!/bin/ksh
PATH=mypath
SERV=`uname -n`
OUT=/path/to/.$SERV.out
 
if grep '^text' /my/file >/dev/null
then
  echo yes | command -filename=$OUT
else 
  echo "my text" > $OUT
fi

# 5  
Old 08-18-2008
Thanks era. I am a firm believer in "short and sweet".
# 6  
Old 08-18-2008
Just to reinvolve the EOF thing:
Code:
command -filename=$OUT <<EOF
yes
EOF

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Requires a script for incidents

Hi, I am associated with a project where we received multiple incident on daily basis for different support groups like(unix support,windows support,vms support). We use HP service centre as a ticketing tool where we gets all the incidents generated automatically when something went wrong on... (2 Replies)
Discussion started by: naman agarwal
2 Replies

2. Shell Programming and Scripting

Script output as input for next command

Hi All, Hoping you can help as im in desperate need... I'm very new to unix scripting so apoligies, I have setup an expect script in order to log into a node on our network, This will provide an output as per the below *********** information: *************: n/a TEST IP : n/a ... (18 Replies)
Discussion started by: mutley2202
18 Replies

3. Shell Programming and Scripting

Shell script to input as if from command line to the java program

Hi, We are having a java server which can run on command line and once initiated, it will prompt options to enter from 0 to 5. The java program kickoff respective operation once number is entered between 0 to 5. However i want to always enter "1" and write another shell program wrapper to start... (4 Replies)
Discussion started by: surya5kn
4 Replies

4. HP-UX

Command to trace System Calls on HP UX

All, Kindly let me know command which is used to trace the system calls on HP - UX server when an executable is run. On Solaris we have TRUSS which does the need. On HP UX we have TUSC command which is a third party software. Currently this is not installed on my HP Server. If there... (3 Replies)
Discussion started by: helper
3 Replies

5. Shell Programming and Scripting

Help with script or command to differentiate difference between two input file?

I got two file write now. Input file 1: >data_1 DSFDFDSGFDSGSGEGTRTRERPOYIORPGKKGDSPKFSDKFPSDKFSPFS >data_34 WEEREREWREWOIQOPIEPDSKLFNDSFNSKNCASKJHDAFHAOUDFEOWWIOUFEWIUEWIRUEWIRUEWIORUEWOREWR >data_21 ASDASDQWEQWRQERFWPOTGIUWEIPOFIOFDSNFKSJDNFSKDHFKDSJHFKDSJHF >data_4... (14 Replies)
Discussion started by: perl_beginner
14 Replies

6. Shell Programming and Scripting

Script check if ssh requires a password???

Thanks to the help from this forum i've learned a lot of good stuff but I still have questions :). I need to write a script that checks if ssh to a box requires a password. I need it will be an "if" statement, if ssh requires password, then do a key exchange(with i already have). Just need to... (5 Replies)
Discussion started by: elbombillo
5 Replies

7. Shell Programming and Scripting

Perl System command calls to variable

I am new to scripting in Perl so I have a dumb question. I know I can call system commands using system("date"); But I am not able to: 1. set its output to a variable 2. run in quiet mode(no output to the screen) The examples i have #!/usr/bin/perl print `date +\%y\%m\%d.\%H\%M`;... (5 Replies)
Discussion started by: 4scriptmoni
5 Replies

8. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies

9. Shell Programming and Scripting

Molecular biologist requires help re: search / replace script

Monday April 07, 2008 Hello - I was wondering if someone could help me? I have some basic knowledge of awk, etc., and can create simple scripts (e.g. a search_replace.awk file) that can be called from the command line: $ awk -f search_replace.awk <file to be searched> I have a... (11 Replies)
Discussion started by: gstuart
11 Replies

10. IP Networking

Identification of data calls & voice calls

Is there any facility to filter/identify the data calls and voice calls coming throug modem? OR Can we get the data or voice calls information through a script(preferably C Kermit)? (0 Replies)
Discussion started by: pcsaji
0 Replies
Login or Register to Ask a Question