<?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>topic Re: Creating a daemon using a shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027532#M909963</link>
    <description>The only thing I'm not sure about is whether perl comes installed on HP-UX by default.  This code will also need to run on AIX and Sun, so perl maybe the best option as long as I don't have to install it on every platform, rather it comes installed already.</description>
    <pubDate>Fri, 18 Jul 2003 16:06:40 GMT</pubDate>
    <dc:creator>unixdaddy</dc:creator>
    <dc:date>2003-07-18T16:06:40Z</dc:date>
    <item>
      <title>Creating a daemon using a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027528#M909959</link>
      <description>I'm having real trouble doing something that should be so simple. I need to create a daemon to run from boot time. I'm using the run control scripts to do this. So i've created a script called /sbin/rc3.d/S999testscript which reads:-&lt;BR /&gt;&lt;BR /&gt;case $1 in&lt;BR /&gt;start)&lt;BR /&gt;echo start&lt;BR /&gt;/usr/local/adm/testscript1 /usr/local/adm/pid.log 2&amp;gt;&amp;amp;1 &amp;amp;&lt;BR /&gt;;;&lt;BR /&gt;stop)&lt;BR /&gt;echo stop&lt;BR /&gt;touch /usr/local/adm/killdaemon&lt;BR /&gt;;;&lt;BR /&gt;esac&lt;BR /&gt;&lt;BR /&gt;This calls my daemon in the background so the boot can continue. My testscript1 reads:-&lt;BR /&gt;&lt;BR /&gt;export PATH=$PATH:/usr/sbin:/usr/bin&lt;BR /&gt;echo $PATH&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;echo "`date` - This is a test" &amp;gt;&amp;gt; /usr/local/adm/test.log  2&amp;gt;&amp;amp;1 &lt;BR /&gt;sleep 10 &lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;When I run this from the command line it works fine. HOWEVER when it is executed via a reboot only one loop of the while loop takes place and then it just disappears. It doesn't run in the background. What am I doing wrong?</description>
      <pubDate>Fri, 18 Jul 2003 13:57:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027528#M909959</guid>
      <dc:creator>unixdaddy</dc:creator>
      <dc:date>2003-07-18T13:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a daemon using a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027529#M909960</link>
      <description>Hi,&lt;BR /&gt;i don't see anything evident.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Try two things (if no better advice comes...)&lt;BR /&gt;&lt;BR /&gt;- specify the shell at the beginning&lt;BR /&gt;&lt;BR /&gt;#!/sbin/sh&lt;BR /&gt;&lt;BR /&gt;- start it with the nohup&lt;BR /&gt;&lt;BR /&gt;nohup /usr/local/adm/testscript1 /usr/local/adm/pid.log 2&amp;gt;&amp;amp;1 &amp;amp; &lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt; Massimo</description>
      <pubDate>Fri, 18 Jul 2003 14:06:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027529#M909960</guid>
      <dc:creator>Massimo Bianchi</dc:creator>
      <dc:date>2003-07-18T14:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a daemon using a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027530#M909961</link>
      <description>Nohup will help but the shell is really a lousy choice to create a daemon. The fundamental problem is detaching a process from its controlling terminal -- this is essntial to 'daemonize' a process. Normally, you fork, let the parent exit, run setsid() to detach the controlling terminal, ignore or trap signals, especially SIGINT, SIGHUP, SIGPIPE, and SIGTERM. Typically, you want a SIGTERM to kill the daemon. For this reason, most daemons are done in C but you can do daemons very nicely in Perl -- and do them the right way. &lt;BR /&gt;&lt;BR /&gt;See the attached daemon which is equivalent to your shell attempt. It took me longer to type this responce than it did to rip apart and paste together one of my existing daemons.&lt;BR /&gt;&lt;BR /&gt;Regards, Clay&lt;BR /&gt;</description>
      <pubDate>Fri, 18 Jul 2003 14:58:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027530#M909961</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2003-07-18T14:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a daemon using a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027531#M909962</link>
      <description>The nohup seems to have done it and it is working now. Sometimes the simplest problems are the most fustrating to solve.  Thanks for the perl idea, I've been meaning to learn perl for a long time, maybe now is the time to pick it up. The code for perl looks pretty straight forward so I think I'll look into using that long term.</description>
      <pubDate>Fri, 18 Jul 2003 15:57:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027531#M909962</guid>
      <dc:creator>unixdaddy</dc:creator>
      <dc:date>2003-07-18T15:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a daemon using a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027532#M909963</link>
      <description>The only thing I'm not sure about is whether perl comes installed on HP-UX by default.  This code will also need to run on AIX and Sun, so perl maybe the best option as long as I don't have to install it on every platform, rather it comes installed already.</description>
      <pubDate>Fri, 18 Jul 2003 16:06:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027532#M909963</guid>
      <dc:creator>unixdaddy</dc:creator>
      <dc:date>2003-07-18T16:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a daemon using a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027533#M909964</link>
      <description>Perl is installed by default on every Unix I know of currently.&lt;BR /&gt;&lt;BR /&gt;Be very cautious though, as different OS's ship with different versions of Perl.&lt;BR /&gt;&lt;BR /&gt;Sincerely,&lt;BR /&gt;Shannon</description>
      <pubDate>Fri, 18 Jul 2003 16:15:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027533#M909964</guid>
      <dc:creator>Shannon Petry</dc:creator>
      <dc:date>2003-07-18T16:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a daemon using a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027534#M909965</link>
      <description>After you determine the version and location of perl you have two options to make the code cross platform compatible.&lt;BR /&gt;&lt;BR /&gt;lets say in HP-UX perl is at /usr/local/bin/perl&lt;BR /&gt;&lt;BR /&gt;and in AIX its at /usr/local/perl&lt;BR /&gt;&lt;BR /&gt;You can change the first line of your program to reflect that:&lt;BR /&gt;&lt;BR /&gt;#!/usr/local/bin/perl&lt;BR /&gt;&lt;BR /&gt;to&lt;BR /&gt;&lt;BR /&gt;#!/usr/local/perl&lt;BR /&gt;&lt;BR /&gt;Lets say you want the HP-UX script to work on all platforms unmodified.&lt;BR /&gt;&lt;BR /&gt;Then on the AIX box, do this:&lt;BR /&gt;&lt;BR /&gt;ln -s /usr/local/perl /usr/local/bin/perl&lt;BR /&gt;&lt;BR /&gt;I use this kind of soft linking to avoid having to change perl scripts that run on many different OS's for my websites.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Fri, 18 Jul 2003 16:20:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027534#M909965</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2003-07-18T16:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a daemon using a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027535#M909966</link>
      <description>Avoiding Perl because it wasn't available on all platforms might have made sense as late as 5 or 6 years ago but now it's available on every flavor of UNIX. It's normally part of the default installation. Moreover, using the freely available Perls, your scripts will also run on Windows and if well-written will run without changes.&lt;BR /&gt;</description>
      <pubDate>Fri, 18 Jul 2003 16:45:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/creating-a-daemon-using-a-shell-script/m-p/3027535#M909966</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2003-07-18T16:45:30Z</dc:date>
    </item>
  </channel>
</rss>

