3

I've been trying to do this simple script that I wrote where it runs an executable jar file that I made. The command of the script are as follows:

#!/bin/bash
msisdn=$1

java -cp /home/support/phuzca/Migration/PostpaidXMigration_lib/ -jar /home/support/phuzca/Migration/PostpaidXMigration.jar $msisdn /home/support/phuzca/Migration/config.properties /opt/tomcat9/webapps/axis2/WEB-INF/classes/META-INF/PlanID.xml

The jar file works as expected and I receive the expected results:

enter image description here

The idea that I've been trying to figure out is how to prevent those texts from appearing when I run my script, and instead, print them in a file so it can be reviewed later. I hope you could open up some ideas for me. Thank you very much.

3
  • run your script like this migrateToPstopaidX.sh>output.log Commented Dec 8, 2017 at 5:44
  • I already tried that but those logs and exceptions still appears after I ran the script Commented Dec 8, 2017 at 5:51
  • I have added explanations and redirection of both stderr and stdout in `Unix Commented Dec 8, 2017 at 5:57

2 Answers 2

4

Redirect the output to a file:

migrateToPstopaidX.sh > output.log

if you want to redirect stderr use this

  migrateToPstopaidX.sh &> output.log

you can use this >> to append the log instead of >

Sign up to request clarification or add additional context in comments.

3 Comments

I already tried that but those logs and exceptions still appears after I ran the script
I haven't tried this one. I'll try it right away. Thank you.
Can't believe I struggled with this for a day. It worked just like how I wanted to. Thank you very much.
1

Redirect both stdout and stderr to the output file.

migrateToPstopaidX.sh > output.log 2>&1

You can use >> to append instead of overwriting your file.

Bash executes the redirects from left to right as follows:

  • >: Open output.log in overwrite mode and redirect stdout there.
  • 2>&1: Redirect stderr to "where stdout is currently going". In this case, that is a file opened in append mode. In other words, the &1 reuses the file descriptor which stdout currently uses.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.