Search code examples
javalinuxshellloggingnohup

Recreating nohup.out


I'm a new to a Linux, I've encountered an issue. What I've done: i have created the shell script which runs jar file that inside have the System.out.println - prints. Then I ran the sh using: "nohup myScript.sh". It started to produce nohup.out file that appends my output from jar file. Then after hours I found that file very large and just ran a command: "rm nohup.out".

Is there a way to tell nohup to continue to write the output? Without killing currently running process and re-run "nohup myScript.sh"? Because what jar does, it migrating the data between two different environments. So I won't to kill it and start all process again.

Please, provide me some useful information or if u had been in the same issue, how did u solve it?

Cheers


Solution

  • The right way to redirect a process' log into the nohup.out is by running the process in background, like so:

    nohup java -jar your-jar.jar &
    

    You can also customize the name of your output file

    nohup java -jar your-jar.jar &> your_name.out &