<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Unable to successfully launch beeline script from linux shell script with nohup in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Unable-to-successfully-launch-beeline-script-from-linux/m-p/199294#M161334</link>
    <description>&lt;P&gt;The answer to your problem is simple, before coming to solution let me break my answers into steps:&lt;/P&gt;&lt;P&gt;I think you want the output of your code in one file and change the permission of that log file, which you also want to be read in some other script or might be some automation you want to do. So, I assume that you are trying to use exec command for same. &lt;/P&gt;&lt;P&gt;Let's try to understand why your script is misbehaving in this manner. Well, it's not it is just following the protocol and command mentioned in your script.&lt;/P&gt;&lt;P&gt;Exec is the way of running the command in Linux which doesn't spawn a new pid and utilize the same pid of the current shell. So, ideally when you run a command mentioned below in a Linux shell, you will notice that it stops listening and goes in hanging state, but it's not!!&lt;/P&gt;&lt;PRE&gt; exec &amp;gt;1.log 2&amp;gt;&amp;amp;1&lt;/PRE&gt;&lt;P&gt;We have closed the doors with our own hands, i.e., pointing standard error and output to a log file. So, inside your script when this command is executed your child-process goes in the same state.&lt;/P&gt;&lt;P&gt;Now, let's understand how nohup and background process works. When you try executing your script using&lt;/P&gt;&lt;PRE&gt;nohup ./x.sh &amp;amp;&lt;/PRE&gt;&lt;P&gt;nohup takes terminal as standard out and error and point your .sh output to "nohup.out" which is quite expected &lt;STRONG&gt;(&lt;/STRONG&gt;To understand this I would recommend having a look at &lt;STRONG&gt;man page&lt;/STRONG&gt; for &lt;STRONG&gt;nohup&lt;/STRONG&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;. And this is the reason you are getting below the line on your terminal:&lt;/P&gt;&lt;PRE&gt;nohup ./run_beeline_hql.sh &amp;amp;
[1]     58486
[xxxx/home/xxxx/xxx/xxx]$ nohup: ignoring input and appending output to `nohup.out'
[1] + Stopped (SIGTTOU)        nohup ./run_beeline_hql.sh &amp;amp;
&lt;/PRE&gt;&lt;P&gt;Now, we know when your script start running it goes into that state and doesn't do much unless you send a kill command which is when the process tries to kill itself gracefully and complete the task and exit out. The solution to ignore your nohup errors use the below-mentioned piece of code which will help you achieve the same with very little code changes :&lt;/P&gt;&lt;PRE&gt;#!/bin/sh

#Declaring Variables
THISFILE='run_beeline_hql'
EXT1=$(date +%y%m%d)
EXT2=$(date +%H%M%S)
. $(dirname $0)/srv.env

# Close STDOUT file descriptor
exec 1&amp;lt;&amp;amp;-
# Close STDERR FD
exec 2&amp;lt;&amp;amp;-
# Open STDOUT as $THISFILE file for read and write.
exec 1&amp;lt;&amp;gt;$THISFILE

# Redirect STDERR to STDOUT
exec 2&amp;gt;&amp;amp;1

chmod 666 $output_dir/${THISFILE}_$EXT1.$EXT2.log
beeline -f simple_query.hql
exit


&lt;/PRE&gt;&lt;P&gt;In case, you also don't want nohup error than running the script like below would be a better idea:&lt;/P&gt;&lt;PRE&gt;nohup ./run_beeline_hql.sh 1&amp;gt;Temp.log 2&amp;gt;&amp;amp;1 &amp;amp;&lt;/PRE&gt;&lt;P&gt;Do let me know if this worked out or not?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;SKS&lt;/P&gt;</description>
    <pubDate>Mon, 20 Nov 2017 04:12:41 GMT</pubDate>
    <dc:creator>sandeepksaini</dc:creator>
    <dc:date>2017-11-20T04:12:41Z</dc:date>
  </channel>
</rss>

