LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 02-05-2010, 08:02 AM   #1
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
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 ?
 
Old 02-05-2010, 08:09 AM   #2
JimBrewster
Member
 
Registered: Feb 2010
Location: usa:/dev/random
Distribution: Slackware-15.0; -current
Posts: 245

Rep: Reputation: 60
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...
 
Old 02-05-2010, 09:06 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by vinaytp View Post
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
 
Old 02-05-2010, 09:10 AM   #4
JimBrewster
Member
 
Registered: Feb 2010
Location: usa:/dev/random
Distribution: Slackware-15.0; -current
Posts: 245

Rep: Reputation: 60
N.B. '>' will overwrite log file, while '>>' will append.
 
Old 02-05-2010, 09:37 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by JimBrewster View Post
N.B. '>' will overwrite log file, while '>>' will append.
Thanks for pointing out the possible loss of data
 
Old 02-05-2010, 10:47 AM   #6
JimBrewster
Member
 
Registered: Feb 2010
Location: usa:/dev/random
Distribution: Slackware-15.0; -current
Posts: 245

Rep: Reputation: 60
Quote:
Originally Posted by catkin View Post
Thanks for pointing out the possible loss of data
NBD!
 
Old 02-06-2010, 12:58 AM   #7
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Original Poster
Rep: Reputation: 55
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...
 
Old 02-06-2010, 01:25 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by vinaytp View Post
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
 
  


Reply

Tags
bash, log, script, shell



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to upload files to ftp directory deibertine Linux - Software 7 12-19-2009 11:36 AM
how do I write a script for ftp to get *.mp3 files? trist007 Programming 4 03-29-2009 07:47 PM
Perl script to download the files from FTP server peddip Linux - Server 4 03-23-2009 09:49 AM
FTP script to manage unprocessed files suneeladdala AIX 8 12-13-2007 03:58 PM
FTP files to remote server with a shell script Pezzoni Linux - Software 2 06-27-2007 07:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration