<?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: ESXi 5.5 Check if custom script is running in ESXi Discussions</title>
    <link>https://communities.vmware.com/t5/ESXi-Discussions/ESXi-5-5-Check-if-custom-script-is-running/m-p/933340#M79946</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what about creating some sort of a log file - let's say script.log where you would update it with "running" while still in the cycle and "done" when it has completed? Via simple &lt;STRONG&gt;echo script_status &amp;gt; /tmp/sh.log&lt;/STRONG&gt;, then a simple &lt;STRONG&gt;cat /tmp/script.log&lt;/STRONG&gt; should do the trick.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This the easiest solution I can think of.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 04 Mar 2015 06:38:39 GMT</pubDate>
    <dc:creator>Alistar</dc:creator>
    <dc:date>2015-03-04T06:38:39Z</dc:date>
    <item>
      <title>ESXi 5.5 Check if custom script is running</title>
      <link>https://communities.vmware.com/t5/ESXi-Discussions/ESXi-5-5-Check-if-custom-script-is-running/m-p/933339#M79945</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am working on a custom remote office shutdown solution for ESXi environments.&amp;nbsp; The one area I have run into a problem is I need to check if my shutdown script (running locally on the ESXi host) is actually running or still running (to avoid running duplicate processes).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know in regular Linux systems I can do stuff like (ps aux | grep "test.sh" | grep -v "grep") or (stat -c %X /proc/pgdump).&amp;nbsp; This does not seem to work on ESXi.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Recommendations:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;This has to be run locally from the remote site&lt;UL&gt;&lt;LI&gt;no access to vCenter or Orchestrator&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;No Windows&lt;UL&gt;&lt;LI&gt;The main system that will be controlling the overall process is Debian&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Do not want to install any 3rd party software onto the ESXi hosts&lt;/LI&gt;&lt;LI&gt;Do not recommend N.U.T.S or APCUPSD&lt;/LI&gt;&lt;LI&gt;Have to be able to see if the script is running not the commands within the script&lt;UL&gt;&lt;LI&gt;The real script is running multiple commands at different times&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Test setup:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a loop file in /tmp/test.sh&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;#!/bin/sh&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #007800;"&gt;i=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-weight: bold;"&gt;while&lt;/SPAN&gt; &lt;SPAN style="color: #7a0874; font-weight: bold;"&gt;[&lt;/SPAN&gt;&lt;SPAN style="color: #7a0874; font-weight: bold;"&gt;[&lt;/SPAN&gt; &lt;SPAN style="color: #007800;"&gt;$i&lt;/SPAN&gt; -le 1000000&lt;SPAN style="color: #7a0874; font-weight: bold;"&gt;]&lt;/SPAN&gt;&lt;SPAN style="color: #7a0874; font-weight: bold;"&gt;]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-weight: bold;"&gt;do&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #7a0874; font-weight: bold;"&gt;echo&lt;/SPAN&gt; &lt;SPAN style="color: #ff0000;"&gt;"Still running.&amp;nbsp; Step $i"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #7a0874; font-weight: bold;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #7a0874; font-weight: bold;"&gt;(&lt;/SPAN&gt;i = i + &lt;SPAN style="color: #000000;"&gt;1&lt;/SPAN&gt;&lt;SPAN style="color: #7a0874; font-weight: bold;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="color: #7a0874; font-weight: bold;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-weight: bold;"&gt;done&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-weight: bold;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN style="color: #575757;"&gt;Make the file executable&lt;/SPAN&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN style="color: #575757;"&gt;chmod +x /tmp/test.sh&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;run the test script&lt;/LI&gt;&lt;LI&gt;What can you run to verify the script is still running?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any assistance is appreciated.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 05:03:43 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/ESXi-Discussions/ESXi-5-5-Check-if-custom-script-is-running/m-p/933339#M79945</guid>
      <dc:creator>BWinchell</dc:creator>
      <dc:date>2015-03-04T05:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: ESXi 5.5 Check if custom script is running</title>
      <link>https://communities.vmware.com/t5/ESXi-Discussions/ESXi-5-5-Check-if-custom-script-is-running/m-p/933340#M79946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what about creating some sort of a log file - let's say script.log where you would update it with "running" while still in the cycle and "done" when it has completed? Via simple &lt;STRONG&gt;echo script_status &amp;gt; /tmp/sh.log&lt;/STRONG&gt;, then a simple &lt;STRONG&gt;cat /tmp/script.log&lt;/STRONG&gt; should do the trick.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This the easiest solution I can think of.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 06:38:39 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/ESXi-Discussions/ESXi-5-5-Check-if-custom-script-is-running/m-p/933340#M79946</guid>
      <dc:creator>Alistar</dc:creator>
      <dc:date>2015-03-04T06:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: ESXi 5.5 Check if custom script is running</title>
      <link>https://communities.vmware.com/t5/ESXi-Discussions/ESXi-5-5-Check-if-custom-script-is-running/m-p/933341#M79947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Alistar,&lt;/P&gt;&lt;P&gt;The script does log everything to a log file for troubleshooting and audit purposes.&amp;nbsp; That is one way of doing it.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I cannot find another way (something where I can ensure the script is running via a running process) this might be my only solution.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 15:06:32 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/ESXi-Discussions/ESXi-5-5-Check-if-custom-script-is-running/m-p/933341#M79947</guid>
      <dc:creator>BWinchell</dc:creator>
      <dc:date>2015-03-04T15:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: ESXi 5.5 Check if custom script is running</title>
      <link>https://communities.vmware.com/t5/ESXi-Discussions/ESXi-5-5-Check-if-custom-script-is-running/m-p/933342#M79948</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok.&amp;nbsp; After spending many hours looking for a way to see which "sh" process is running my script, I gave up and continued down the path of what Alistar suggested.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Solution: (&lt;A href="http://stackoverflow.com/questions/185451/quick-and-dirty-way-to-ensure-only-one-instance-of-a-shell-script-is-running-at" title="http://stackoverflow.com/questions/185451/quick-and-dirty-way-to-ensure-only-one-instance-of-a-shell-script-is-running-at"&gt;linux - Quick-and-dirty way to ensure only one instance of a shell script is running at a time - Stack Overflow&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;Basically we create a lockfile with the PID inside of it.&amp;nbsp; If simultaneous processes try to kick of, they are stopped.&amp;nbsp; You can also look into the lockfile to find the PID if you want to force exit, log, etc....&lt;/P&gt;&lt;P&gt;E.g.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14255159180644055" jivemacro_uid="_14255159180644055"&gt;
&lt;P&gt;#!/bin/sh&lt;/P&gt;
&lt;P&gt;LOCKFILE=/tmp/lock.txt&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;if [ -e ${LOCKFILE} ] &amp;amp;&amp;amp; kill -0 `cat ${LOCKFILE}`; then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo "already running"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit&lt;/P&gt;
&lt;P&gt;fi&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Remove the lockfile when process is exited&lt;/P&gt;
&lt;P&gt;trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo $$ &amp;gt; ${LOCKFILE}&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;#do stuff&lt;/P&gt;
&lt;P&gt;i=1&lt;/P&gt;
&lt;P&gt;while [[ $i -le 1000000 ]]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo "Still running.&amp;nbsp; Step $i"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; let i=i+1&lt;/P&gt;
&lt;P&gt;done&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;rm -f ${LOCKFILE}&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Mar 2015 00:40:02 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/ESXi-Discussions/ESXi-5-5-Check-if-custom-script-is-running/m-p/933342#M79948</guid>
      <dc:creator>BWinchell</dc:creator>
      <dc:date>2015-03-05T00:40:02Z</dc:date>
    </item>
  </channel>
</rss>

