Ammu
Ammu

Reputation: 5127

To read the output of a command in a shell script

I am running a unix command say ftp to a remote machine through a shell script.I have to pass the userid and password through the script accordingly.How can i do that?

Upvotes: 2

Views: 980

Answers (3)

mgiuca
mgiuca

Reputation: 21357

Do you mean you want to get the result that the command (say, ftp) wrote to the terminal as a value inside the script?

Use backticks. For example:

x=`ftp ...`

will run the ftp command, and take the text of its stdout and store it in the variable x.

Upvotes: 0

Nishan
Nishan

Reputation: 2871

Best way to supply username/passwords from scripts would be to use 'expect' scripting.

Here is a small example : http://www.linuxquestions.org/questions/linux-software-2/auto-ssh-login-expect-script-624047/ . It shows using expect to provide password for ssh, ftp should be very similar.

Upvotes: 1

Vijay
Vijay

Reputation: 67211

Redirect the ftp command inside your shell script

ftp .....   > ftp.log

Upvotes: 0

Related Questions