LinuxQuestions.org
Visit the LQ Articles and Editorials section
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: 704

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, Salix
Posts: 237

Rep: Reputation: 59
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: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,541
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
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, Salix
Posts: 237

Rep: Reputation: 59
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: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,541
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
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, Salix
Posts: 237

Rep: Reputation: 59
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: 704

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
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,489

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


All times are GMT -5. The time now is 06:56 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration