Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6364195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:07:59+00:00 2026-05-25T00:07:59+00:00

I have a java application and I want to run a script whenever it

  • 0

I have a java application and I want to run a script whenever it experiences and OutOfMemoryException

This works great:

$ java -server -XX:OnOutOfMemoryError="./oom_script %p" TestOOMClass

Unfortunately my application is run by a bash script in production. The script boils down to this:

cmd='java -server  -XX:OnOutOfMemoryError="./oom_script %p"  TestOOMClass'
##does a lot of checking and cmd building here
exec -a app  ${cmd}

When run like this java never respects the double quotes and thinks %p is the class. how do I prevent this? I’ve tried double escaping but that doesn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:07:59+00:00Added an answer on May 25, 2026 at 12:07 am

    Since your program is run as a shell script, I would suggest putting this as the first line in your shell script after the shebang:

    set -xv
    

    Then, in the crontab, put 2>&1 at the end of the command line, so STDERR and STDOUT are merged. Crontab usually emails out the STDOUT of a command to root, so you can see what the output is. If not, then apend the following to the end of the command in your crontab:

    > /somedir/output.$$ 2>&1
    

    Make sure somedir exists, and after crontab runs your command, you’ll see the verbose and debug output. Each line in your shell script will be displayed before it is executed — both as written and as the shell actually interprets it.

    The set -xv becomes very useful in debugging any sell script. There could be all sorts of environmental issues involved between the cronjob and the script running under your login. You might even find a shell issue. For example, crontab usually executes shell scripts in Bourne shell and you probably have Bash or Kornshell as your default shell. Whatever it is, you’ll usually find out the issue very quickly when you turn on verbose/debug mode.

    You don’t even have to do this to the entire script. You can put set -xv anywhere in your script to turn on verbose/debug mode, and set +xv to turn it off.

    I could make several pious high minded recommendations (use quotes, don’t assume environment things, prefix your command line with “bash -c” to make sure you’re using the right shell, etc.), but this would be guessing what could be wrong. In order to really debug this issue, I would need to see the machine, know the OS, see your entire shell script, and understand the entire environment. And, the first thing I would do is add set -xv in your shell script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that passes in java.util.Date. I want to check whether this
i have a server - client application that runs on java 1.3; i want
I am using Orion server for my Java-based web application. I have a run
I have a Java application built with OSGi that I want to run in
I have created a Java desktop application and I want to run it from
I have Java desktop application that works with CSV files. And i want add
My Java application uses a .mdb database and i want to run this application
I have a Java Swing application that i want to run on Mac OS
I have a Java application which I want to shutdown 'nicely' when the user
I have a java-application using JDBC for database interaction. I want to do a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.