Automatic Input to a command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automatic Input to a command
# 1  
Old 04-27-2012
Automatic Input to a command

Hi,
I have an issue where i run an command in a shell script.

Code:
command >/dev/null
ret=$?
echo ret

If the command returns an error i'm redirecting it to /dev/null.
The prob is if an error comes it expects the user to press return to continue.
And hence the return is not echoed. and the end user is not aware of this.

Please help me provide an automatic input incase of error.
Cant use expect and spawn due to certain limitations.

Please help.

Last edited by Scrutinizer; 04-27-2012 at 04:55 PM.. Reason: code tags
# 2  
Old 04-27-2012
Is this what you mean?
Code:
command <<EOF > /dev/null

EOF

The here doc acts as stdin, it always gives a return (blank line).
# 3  
Old 04-27-2012
Does it take other inputs? You can try

Code:
yes | command

to pump it with lots of y\ns ...
# 4  
Old 04-27-2012
My `command` doesnt always expect an input.
Only if it fails it expects an "Enter".

Not sure how EOF helps and what does EOF contain.
tried your command and got the error, cannot find or open the file.Smilie
# 5  
Old 04-27-2012
Both methods would send enter no matter what. This is possibly OK since without error the command finishes, and you only send 1 enter if an error, yes?

You could try also:

Code:
echo | command
printf '\n' | command

Unless your command actually opens the terminal directly.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automatic input "yes" in a shell script

Hi All, I need a favour. I have a file called "redhat_servers.txt" containing some server names line by line. When I try to ssh to each server, and I have already done with ssh key-gen stuff. Now, for first time if I do ssh .. I need to type yes I have more than 400 servers...it will take... (4 Replies)
Discussion started by: kumar85shiv
4 Replies

2. Shell Programming and Scripting

[KSH] Creating automatic variable from read input

Hello there, I am posting to seek help with a KSH script, I am making a simple calculation program where the user can enter as many numbers as they like, I am getting their input using the read command, however I am not sure how to repeat doing this and storing the input in to new variables... (7 Replies)
Discussion started by: pandapowerbox
7 Replies

3. Shell Programming and Scripting

Giving automatic multiple Input to a tool from shell script

Hi, Please help me,its urgent. I have a tool that i want to run from a shell script. When we run the tool it will ask the user choice to add or delete. When user enter the choice it will then ask how many units he want to delete or add and will add or delete accordingly. Now I want to... (1 Reply)
Discussion started by: saket18@ymail.c
1 Replies

4. Shell Programming and Scripting

Help to write a script or program to automatic execute and link input file data

Output file template format <input_file_name>a</input_file_name> <total_length_size>b</total_length_size> <log_10_length_size>c</log_10_length_size> Input_file_1 (eg. sample.txt) SDFSDGDGSFGRTREREYWW Parameter: a is equal to the input file name b is equal to the total length of... (2 Replies)
Discussion started by: perl_beginner
2 Replies

5. Shell Programming and Scripting

Automatic file input to code

i have got many files like this in my folder temp(say) imp_02042008.txt for date 02-04-2008 imp_03092009.txt for date 03-09-2009 imp_25112009.txt for date 25-11-2009 ................... ........ in some folder. and one of my shell code uses one of the above files based on date.... (9 Replies)
Discussion started by: Maruti
9 Replies

6. Shell Programming and Scripting

[code] Automatic File Input

i have got many files like this in my folder temp(say) imp_02042008.txt for date 02-04-2008 imp_03092009.txt for date 03-09-2009 imp_25112009.txt for date 25-11-2009 ................... ........ in some folder. and one of my shell code uses one of the above files based on date.... (0 Replies)
Discussion started by: Maruti
0 Replies

7. Shell Programming and Scripting

Automatic command to Telnet

I'm trying to send a command automatically via Telnet, but without success. I can do this: > telnet 100.100.100.1 8080 Trying 100.100.100.1... Connected to 100.100.100.1. Escape character is '^]'. Whereby I enter "command" and everything works like a charm, but I'd like to do this... (3 Replies)
Discussion started by: Ilja
3 Replies

8. UNIX for Dummies Questions & Answers

problem with output of find command being input to basename command...

Hi, I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script. I am planning to do like this: if ; then... (2 Replies)
Discussion started by: new_learner
2 Replies

9. UNIX for Advanced & Expert Users

Automatic input to commands

Hi, In a shell script i am running a command which is asking for input. How can i give that automatically. I have done this before but for the time being can't recall. Was something like <| Thanks (6 Replies)
Discussion started by: vibhor_agarwali
6 Replies

10. UNIX for Dummies Questions & Answers

input to a command...

hi all.. I am running this command in linux from a shell script....gpg --output encrypted_file.gpg --encrypt --recipient santhosh@yahoo.com /home/test2/actectest/san.zip.....this is a command for encrypting a file using GnuPG tool.....and while the command is running it stops in between... (1 Reply)
Discussion started by: santy
1 Replies
Login or Register to Ask a Question