LinuxQuestions.org
Visit Jeremy's Blog.
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 06-01-2005, 09:02 AM   #1
bnj
Member
 
Registered: Apr 2005
Location: Switzerland
Distribution: Ubuntu
Posts: 70

Rep: Reputation: 15
Specifying the output file for a gnu tool


Hello,

I have a little shell script that downloads a file from the web. My shell script:
Code:
...
curl -o file.tar.gz http://www.myserver.com/foo/bar/file.tar.gz
...
I run this script as a cronjob every day and, in order to be able to see what the script did, I log the output of the script:
Code:
myshellscript.sh > log.txt
I can see most of the output of the script in log.txt, but not the output of the curl statement. Is it possible to make the output of curl (the things you can see in a terminal when you use curl) appear in a log file? Can I change the stdout or stderr or something like that? How?

Any help very welcome. Thank you in advance.
 
Old 06-01-2005, 09:06 AM   #2
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Add "2>&1" after the output redirection to get stderr into the logfile as well. Or you could use "2>errs.log" to put them in a separate file. (Without the quotes, obviously.)
 
Old 06-01-2005, 09:18 AM   #3
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
To get the output from curl, you can just redirect the output using the same > operator. Just change the line to curl -o file.tar.gz http://www.myserver.com/foo/bar/file.tar.gz > curl.log

Alternatively, if you want the output going to the same log file as the script's, you could try using >> log.txt. The double > means that the output will be appended to the end of the file, whereas the single > will cause the file to be cleared before anything is written. I don't know if this approach of putting everything into one file will work as expected though. I've found that sometimes doing things like this will give "interesting" results
 
Old 06-02-2005, 04:46 AM   #4
bnj
Member
 
Registered: Apr 2005
Location: Switzerland
Distribution: Ubuntu
Posts: 70

Original Poster
Rep: Reputation: 15
Hello,

Thank you very much for your answers. Unfortunately, they do not work.
If I type
Code:
curl -o myfile.tar.gz http://www.myserver.com/path/myfile.tar.gz > log.txt
nothing gets written in log.txt, even if an error occurs (say if the given URL does not exist).

If I type
Code:
curl -o myfile.tar.gz http://www.myserver.com/path/myfile.tar.gz > log.txt 2>err.txt
I get the error message
Code:
Ambiguous output redirect.
If I type
Code:
curl -o myfile.tar.gz http://www.myserver.com/path/myfile.tar.gz 2>err.txt
I get the error message
Code:
 curl: (7) Failed to connect to 2 IP number 1: Invalid argument
And if I type
Code:
./myscript.sh > log.txt 2>err.txt
I also get the error message
Code:
Ambiguous output redirect.
curl allways writes to the terminal an output like:
Code:
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1476k  100 1476k    0     0  9462k      0 --:--:-- --:--:-- --:--:-- 11.0M
This is what I would like to see in my log file (or in a separate log file). Is that not possible?

Thank you again.

Last edited by bnj; 06-02-2005 at 04:49 AM.
 
Old 06-02-2005, 07:52 AM   #5
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
Quote:
If I type

Code:
curl -o myfile.tar.gz http://www.myserver.com/path/myfile.tar.gz 2>err.txt
I get the error message

Code:
curl: (7) Failed to connect to 2 IP number 1: Invalid argument
That syntax works fine for me, and puts the status output into err.txt
What shell are you using for the script? It's possible that it doesn't support output redirection in this way. You could try:

curl -o myfile.tar.gz --stderr err.txt http://www.myserver.com/path/myfile.tar.gz

which will make curl itself do the redirection, not the shell. Other than this, I'm out of ideas.
 
  


Reply


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
tool to format report output from mysql? alar Linux - General 0 08-03-2004 08:16 PM
where can I find grammar file and lex file of GNU c ? thinks Huiming Linux - Software 1 06-11-2004 07:38 AM
Anyone know of a live distro that has the GNU parted tool? sharpie Linux - General 11 04-21-2004 04:53 AM
the sound gives output when using mic but no output when run a music file medo Debian 0 04-19-2004 07:17 PM
output file size Linux GNU gcc vs. DJGPP wsimmons Programming 5 01-27-2002 10:20 PM


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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration