LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   script to ftp files (http://www.linuxquestions.org/questions/linux-newbie-8/script-to-ftp-files-787227/)

vinaytp 02-05-2010 08:02 AM

script to ftp files
 
Hi all..

I am using below script to ftp a file to remote machien
Code:

#!/bin/bash

ftp -nv <<EOF
open ${SERVER}
user ${USER} ${PASS}
ascii
put test.txt
bye
EOF

When I execute the above file its working fine and displaying output on to the screen. How can I log the output to a file ?

JimBrewster 02-05-2010 08:09 AM

run:

Code:

{yourscript} >> output.log
I know there's a way to build that into your script, but can't recall off the top of my head...

catkin 02-05-2010 09:06 AM

Quote:

Originally Posted by vinaytp (Post 3853792)
When I execute the above file its working fine and displaying output on to the screen. How can I log the output to a file ?

For output to screen and log use the tee command
Code:

myscript.sh | tee log.txt
For output to log only
Code:

myscript.sh > log.txt 2>&1

JimBrewster 02-05-2010 09:10 AM

N.B. '>' will overwrite log file, while '>>' will append.

catkin 02-05-2010 09:37 AM

Quote:

Originally Posted by JimBrewster (Post 3853863)
N.B. '>' will overwrite log file, while '>>' will append.

Thanks for pointing out the possible loss of data :redface:

JimBrewster 02-05-2010 10:47 AM

Quote:

Originally Posted by catkin (Post 3853892)
Thanks for pointing out the possible loss of data :redface:

NBD!;)

vinaytp 02-06-2010 12:58 AM

Thanks for all of your reply...

But the script that I have shown here is just a part of my script. There are lot of lines that are above and below the script. So I cannot try

./script.sh >> logfiles OR
./script.sh | tee -a logfile

Is it possible to log the output by writing some code inside the script itself ?

Thanks once again...

colucix 02-06-2010 01:25 AM

Quote:

Originally Posted by vinaytp (Post 3854518)
Is it possible to log the output by writing some code inside the script itself ?

Yes. You can apply the suggested redirection only to the ftp command line, as in:
Code:

ftp -nv << EOF >> ftp.log 2>&1
  open ${SERVER}
  user ${USER} ${PASS}
  ascii
  put test.txt
  bye
EOF



All times are GMT -5. The time now is 12:17 AM.