LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Simple Bash Question (https://www.linuxquestions.org/questions/programming-9/simple-bash-question-256838/)

sio 11-19-2004 09:31 AM

Simple Bash Question
 
Im not sure what terms I should search for (which is making this painfully slow to find) but this is all i want to do.

Say I want to use ncftp (this is a generalization)

and the first line of the script issues a

ncftp ftp://me#here.com:mypass@here.com

and then the second and third lines say

put allsys
exit

but after it makes the initial connection it of course doesn't execute the next line, im simply in the ncftp prompt and its waiting for input from me. And of course after i exit ncftp the script continues but thats not very useful.

If anyone could direct me to the chapter this is discussed in-in the ABSG or provide an answer i would appreciate the time.

secesh 11-19-2004 09:36 AM

does this help:

http://www.aplawrence.com/SCOFAQ/FAQ...c6autoftp.html

??

secesh 11-19-2004 09:39 AM

or this:
Code:

ncftpput -u login -p password domain.com /remote/path allsys

sio 11-19-2004 11:00 AM

well yes those things will let me do a one liner or create a script file specific to the ftp command, but the ftp example was just a generalization.

I'll try and generalize more,

You execute a program, any console program, from the first line in your bash script. The program stops to ask the user for input. I want the bash script to enter the users input automatically which is taken from the second line, so on and so forth.

In the thought of trying to explain this better i thought of some better search terms. automate user input

dustu76 11-19-2004 11:59 PM

The kind of thing you are asking for can be largely done by "here document" in bash.

Say you have a program "prog" where you have to enter id, name and date of birth (say). E.g. "1", "joe smith", "01-01-1970"

Then you do:

Code:

prog <<END
1
joe smith
01-01-1970
END

"END" is just a single word (no spaces, tabs etc. allowed).

Read the bash documentation for more details.

HTH.

Tinkster 11-20-2004 12:28 AM

Quote:

Originally posted by sio
well yes those things will let me do a one liner or create a script file specific to the ftp command, but the ftp example was just a generalization.

I'll try and generalize more,

You execute a program, any console program, from the first line in your bash script. The program stops to ask the user for input. I want the bash script to enter the users input automatically which is taken from the second line, so on and so forth.

In the thought of trying to explain this better i thought of some better search terms. automate user input

If you know for SURE that the requested input will always
be the same you can indeed do something like
echo "username
password
time to live" | my_interactive_command

If you want to be able to do some sort of
sanity checks look at "man expect" ...


Cheers,
Tink

sio 11-22-2004 09:56 AM

Ah thanks for the tips, I'll look into those various items.


All times are GMT -5. The time now is 06:07 AM.