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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
02-05-2010, 08:02 AM
|
#1
|
Member
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707
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-15.0; -current
Posts: 248
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: Debian
Posts: 8,578
|
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-15.0; -current
Posts: 248
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: Debian
Posts: 8,578
|
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-15.0; -current
Posts: 248
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: 707
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
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
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
|
|
|
All times are GMT -5. The time now is 11:11 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
|
|