Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
02-05-2010, 08:02 AM
#1
Member
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704
Rep:
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 ?
02-05-2010, 08:09 AM
#2
Member
Registered: Feb 2010
Location: usa:/dev/random
Distribution: Slackware, Salix
Posts: 237
Rep:
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...
02-05-2010, 09:06 AM
#3
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Slackware 13.37, Debian Squeeze
Posts: 7,985
Quote:
Originally Posted by
vinaytp
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
02-05-2010, 09:10 AM
#4
Member
Registered: Feb 2010
Location: usa:/dev/random
Distribution: Slackware, Salix
Posts: 237
Rep:
N.B. '>' will overwrite log file, while '>>' will append.
02-05-2010, 09:37 AM
#5
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Slackware 13.37, Debian Squeeze
Posts: 7,985
Quote:
Originally Posted by
JimBrewster
N.B. '>' will overwrite log file, while '>>' will append.
Thanks for pointing out the possible loss of data
02-05-2010, 10:47 AM
#6
Member
Registered: Feb 2010
Location: usa:/dev/random
Distribution: Slackware, Salix
Posts: 237
Rep:
Quote:
Originally Posted by
catkin
Thanks for pointing out the possible loss of data
NBD!
02-06-2010, 12:58 AM
#7
Member
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704
Original Poster
Rep:
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...
02-06-2010, 01:25 AM
#8
Moderator
Registered: Sep 2003
Location: Bologna
Distribution: OpenSUSE 12.1 CentOS 6.2
Posts: 8,998
Quote:
Originally Posted by
vinaytp
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
Thread Tools
Search this Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT -5. The time now is 03:48 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News