Link to home
Start Free TrialLog in
Avatar of Sathish David  Kumar N
Sathish David Kumar NFlag for India

asked on

shell script output to log file

Hi ,

I have shell which is execute the mvn build . I want the execuation log into log file . log file description should be define in script itself

eg:
my sh file is

svn update
mvn clean install


i want the log to print in console will in txt file how to define in script itself
ASKER CERTIFIED SOLUTION
Avatar of Alex [***Alex140181***]
Alex [***Alex140181***]
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Member_2_406981
Member_2_406981

if you want it to go to syslog, you can use logger

svn update | logger

will do the trick.
You need to be careful as some utilities use stderr too, so

logfile=~/build.log
svn update  >$logfile 2>&1
mvn clean install   >>$logfile 2>&1

Open in new window

Avatar of Sathish David  Kumar N

ASKER

what is difference   between  > and >>
(svn update
mvn clean install ) >> a.txt

is that possible ??
One appends (>>) The other erases then appends

is that possible ??
What does that mean? What's your intention?
>> means "append", whereas > means "new/overwrite"
The statement above won't work, maybe you meant something like this:

svn update > a.txt && mvn clean install >> a.txt

Open in new window

Yes, the && is certainly a good idea as there presumably would be no point running mvn if the svn command failed ..?
An alternative would be to write:
   exec > a.txt 2>&1
in your script.  Everything that would have gone to stdout or stderr will instead go to a.txt, from that point in the script up to the end of the script  This avoids having to redirect every command separately.