LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   grab FTP output in bash script (https://www.linuxquestions.org/questions/linux-general-1/grab-ftp-output-in-bash-script-399836/)

bokini 01-05-2006 09:53 AM

grab FTP output in bash script
 
script:

#!/bin/sh
HOST='80.172.10.255'
USER='ahahahah'
PASSWD='eheheheh'
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put file <--------- i want to grab the command result into a bash variable to hadle it #here
quit
END_SCRIPT

#here

exit 0

druuna 01-05-2006 10:52 AM

Hi,

This 'solution' will grab all the output the ftp session creates, not only the line specified (put file). So this could not be what you are looking for.......

Code:

#!/bin/sh
HOST='80.172.10.255'
USER='ahahahah'
PASSWD='eheheheh'

OUT="$(ftp -n $HOST 2>&1 <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put file
quit
END_SCRIPT
)"

echo "Output is: $OUT"

exit 0

Hope this helps.

WilliamsJD 02-03-2006 02:11 PM

You may want to look at using lftp instead... it has a simpler syntax for scripting FTP sessions than the standard ftp client and will produce a lot less output (more relevant output).

output=$(lftp -c "put file" -u$USER,$PASSWD)

WilliamsJD


All times are GMT -5. The time now is 10:16 PM.