Results 1 to 8 of 8
Hi all,
I am working on a bash script in which I have to check for some command & want the output of that command to be saved in a ...
- 10-13-2010 #1Just Joined!
- Join Date
- Sep 2010
- Posts
- 7
Problem Generating Log
Hi all,
I am working on a bash script in which I have to check for some command & want the output of that command to be saved in a file.
suppose if I fire a command wget w3.google.com (I am not allowed to post URL in forum) then i ll get some log printed on console .. I want to save that log in my log file.
Please help me solve this issue
Thanks in advance.
- 10-13-2010 #2
Just direct standard out to a file.
wget wwww.google.de > /tmp/logfile
or the standard error
wget wwww.google.de 2> /tmp/logfile
or both
wget wwww.google.de > /tmp/logfile 2>&1You must always face the curtain with a bow.
- 10-13-2010 #3
You could also utilize the existing syslog.
Have a look at
Code:man logger
You must always face the curtain with a bow.
- 10-14-2010 #4Just Joined!
- Join Date
- Feb 2008
- Posts
- 7
try use the tee command..
- 10-14-2010 #5Just Joined!
- Join Date
- Aug 2008
- Posts
- 7
put set -x in the script and then direct the output to a file
myprog > log
Peter
- 10-15-2010 #6Just Joined!
- Join Date
- Sep 2010
- Posts
- 7
thnx for you support..
I have tried out standard output to my file & but the problem is something else
my command (I have written wget here instead ) shows full loading process, i mean 0% to 100% task completion & at the end it shows done successfully or failed..
I just want that status to be appended in the file ..
Can you please help me bit more as I am totally new to shell scripts.
Thanks again
- 10-19-2010 #7Just Joined!
- Join Date
- Aug 2008
- Posts
- 7
When a job completes in a shell there is a variable that stores a 1 or 0 depending on pass or failure. I think it is the '?'
if [ "?" == 1 ]
then
echo "task failed"
fi
something like the above. I write so few scripts these days and forget the exact format. Hope this helps.
You will have to read man bash to find the correct variable.
Peter
- 10-19-2010 #8Just Joined!
- Join Date
- Oct 2010
- Posts
- 5
Expanding on pdk said, $? is the variable that holds the exit code of the last command. 0 means okay, anything else means failed.
Code:if [ $? -eq 0 ] then echo "task completed" > log.log else echo "task failed" > log.log fi


Reply With Quote