<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux Programming &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/linux-programming/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Wed, 31 May 2017 03:50:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>Linux: Importance of first line comment &#8220;#!/bin/sh&#8221; in a shell script</title>
		<link>https://www.dbrnd.com/2017/06/linux-importance-of-first-line-comment-binsh-in-a-shell-script/</link>
					<comments>https://www.dbrnd.com/2017/06/linux-importance-of-first-line-comment-binsh-in-a-shell-script/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 11 Jun 2017 16:16:43 +0000</pubDate>
				<category><![CDATA[Bash Shell Script]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Bash shell script]]></category>
		<category><![CDATA[Crontab]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Linux Error]]></category>
		<category><![CDATA[Linux Programming]]></category>
		<category><![CDATA[Linux shell script]]></category>
		<category><![CDATA[Linux Tips and Tricks]]></category>
		<category><![CDATA[Unix shell]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4635</guid>

					<description><![CDATA[Recently, I started to configure few of my DBA shell scripts in Linux Crontab. Yesterday, I shared an important article on skip the execution of your shell script if it is running already. If you forget to put the first line of your shell script something like &#8220;#!/bin/sh&#8221; and bash shell script something like &#8220;#!/bin/bash&#8221;, [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-importance-of-first-line-comment-binsh-in-a-shell-script%2F&amp;linkname=Linux%3A%20Importance%20of%20first%20line%20comment%20%E2%80%9C%23%21%2Fbin%2Fsh%E2%80%9D%20in%20a%20shell%20script" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-importance-of-first-line-comment-binsh-in-a-shell-script%2F&amp;linkname=Linux%3A%20Importance%20of%20first%20line%20comment%20%E2%80%9C%23%21%2Fbin%2Fsh%E2%80%9D%20in%20a%20shell%20script" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-importance-of-first-line-comment-binsh-in-a-shell-script%2F&amp;linkname=Linux%3A%20Importance%20of%20first%20line%20comment%20%E2%80%9C%23%21%2Fbin%2Fsh%E2%80%9D%20in%20a%20shell%20script" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-importance-of-first-line-comment-binsh-in-a-shell-script%2F&amp;linkname=Linux%3A%20Importance%20of%20first%20line%20comment%20%E2%80%9C%23%21%2Fbin%2Fsh%E2%80%9D%20in%20a%20shell%20script" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-importance-of-first-line-comment-binsh-in-a-shell-script%2F&amp;linkname=Linux%3A%20Importance%20of%20first%20line%20comment%20%E2%80%9C%23%21%2Fbin%2Fsh%E2%80%9D%20in%20a%20shell%20script" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-importance-of-first-line-comment-binsh-in-a-shell-script%2F&amp;linkname=Linux%3A%20Importance%20of%20first%20line%20comment%20%E2%80%9C%23%21%2Fbin%2Fsh%E2%80%9D%20in%20a%20shell%20script" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-importance-of-first-line-comment-binsh-in-a-shell-script%2F&#038;title=Linux%3A%20Importance%20of%20first%20line%20comment%20%E2%80%9C%23%21%2Fbin%2Fsh%E2%80%9D%20in%20a%20shell%20script" data-a2a-url="https://www.dbrnd.com/2017/06/linux-importance-of-first-line-comment-binsh-in-a-shell-script/" data-a2a-title="Linux: Importance of first line comment “#!/bin/sh” in a shell script"></a></p><p>Recently, I started to configure few of my DBA shell scripts in Linux Crontab.</p>
<p>Yesterday, I shared an important article on skip the execution of your shell script if it is running already.</p>
<blockquote><p>If you forget to put the first line of your shell script something like &#8220;#!/bin/sh&#8221; and bash shell script something like &#8220;#!/bin/bash&#8221;, you cannot get the name of your running shell script.</p></blockquote>
<p>It&#8217;s called a shebang and tells the parent shell which interpreter should be used to execute the script.</p>
<blockquote><p>When you are running shell script in Linux, the operating system will look at the first few bytes of the file to decide the format of the program and how to execute it.</p></blockquote>
<blockquote><p>If you don&#8217;t use &#8220;#!/bin/sh&#8221; or &#8220;#!/bin/bash&#8221; on the first line, then the system will treat all the commands in that script as different commands.</p></blockquote>
<p>So I would suggest please start to add it.</p>
<p><strong>Check below screenshots without #!/bin/bash:</strong></p>
<p>I created sample running.bash file to explain the importance &#8220;#!/bin/sh&#8221; or &#8220;#!/bin/bash&#8221;.</p>
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-4647" src="https://www.dbrnd.com/wp-content/uploads/2017/02/LinuxProcessWithoutFilenameShellScript.png" alt="" width="389" height="174" srcset="https://www.dbrnd.com/wp-content/uploads/2017/02/LinuxProcessWithoutFilenameShellScript.png 389w, https://www.dbrnd.com/wp-content/uploads/2017/02/LinuxProcessWithoutFilenameShellScript-300x134.png 300w, https://www.dbrnd.com/wp-content/uploads/2017/02/LinuxProcessWithoutFilenameShellScript-150x67.png 150w" sizes="(max-width: 389px) 100vw, 389px" /></p>
<p><img decoding="async" class="alignnone size-full wp-image-4646" src="https://www.dbrnd.com/wp-content/uploads/2017/02/LinuxProcessWithoutFilename.png" alt="" width="545" height="97" srcset="https://www.dbrnd.com/wp-content/uploads/2017/02/LinuxProcessWithoutFilename.png 545w, https://www.dbrnd.com/wp-content/uploads/2017/02/LinuxProcessWithoutFilename-300x53.png 300w, https://www.dbrnd.com/wp-content/uploads/2017/02/LinuxProcessWithoutFilename-150x27.png 150w" sizes="(max-width: 545px) 100vw, 545px" /></p>
<p><strong>Check below screenshots with #!/bin/bash:</strong></p>
<p><strong><img decoding="async" class="alignnone wp-image-4639" src="https://www.dbrnd.com/wp-content/uploads/2017/02/LinuxProcessWithFilenameShellScript.png" alt="Linux Process With Filename Shell Script" width="386" height="166" /></strong></p>
<p><strong><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4644" src="https://www.dbrnd.com/wp-content/uploads/2017/02/LinuxProcessWithFilename.png" alt="" width="587" height="80" srcset="https://www.dbrnd.com/wp-content/uploads/2017/02/LinuxProcessWithFilename.png 587w, https://www.dbrnd.com/wp-content/uploads/2017/02/LinuxProcessWithFilename-300x41.png 300w, https://www.dbrnd.com/wp-content/uploads/2017/02/LinuxProcessWithFilename-150x20.png 150w" sizes="auto, (max-width: 587px) 100vw, 587px" /></strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/06/linux-importance-of-first-line-comment-binsh-in-a-shell-script/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Linux: If your shell script is running, skip the next execution and exit it</title>
		<link>https://www.dbrnd.com/2017/06/linux-if-your-shell-script-is-running-skip-the-next-execution-and-exit-it-cron-job/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 10 Jun 2017 16:16:05 +0000</pubDate>
				<category><![CDATA[Bash Shell Script]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[basename]]></category>
		<category><![CDATA[Bash shell script]]></category>
		<category><![CDATA[cron job]]></category>
		<category><![CDATA[Crontab]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Linux Error]]></category>
		<category><![CDATA[Linux Programming]]></category>
		<category><![CDATA[Linux shell script]]></category>
		<category><![CDATA[Linux Tips and Tricks]]></category>
		<category><![CDATA[pidof]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[Unix shell]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4631</guid>

					<description><![CDATA[We configured lots of cron job in our production Linux &#8211; PostgreSQL Server. Different schedules like monitor the database performance, monitor the backup process, take a database backup, replicate a database copy. We set few monitor cron jobs at every 5 minutes. Now the situation is, few monitoring scripts are running even more than 5 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-if-your-shell-script-is-running-skip-the-next-execution-and-exit-it-cron-job%2F&amp;linkname=Linux%3A%20If%20your%20shell%20script%20is%20running%2C%20skip%20the%20next%20execution%20and%20exit%20it" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-if-your-shell-script-is-running-skip-the-next-execution-and-exit-it-cron-job%2F&amp;linkname=Linux%3A%20If%20your%20shell%20script%20is%20running%2C%20skip%20the%20next%20execution%20and%20exit%20it" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-if-your-shell-script-is-running-skip-the-next-execution-and-exit-it-cron-job%2F&amp;linkname=Linux%3A%20If%20your%20shell%20script%20is%20running%2C%20skip%20the%20next%20execution%20and%20exit%20it" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-if-your-shell-script-is-running-skip-the-next-execution-and-exit-it-cron-job%2F&amp;linkname=Linux%3A%20If%20your%20shell%20script%20is%20running%2C%20skip%20the%20next%20execution%20and%20exit%20it" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-if-your-shell-script-is-running-skip-the-next-execution-and-exit-it-cron-job%2F&amp;linkname=Linux%3A%20If%20your%20shell%20script%20is%20running%2C%20skip%20the%20next%20execution%20and%20exit%20it" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-if-your-shell-script-is-running-skip-the-next-execution-and-exit-it-cron-job%2F&amp;linkname=Linux%3A%20If%20your%20shell%20script%20is%20running%2C%20skip%20the%20next%20execution%20and%20exit%20it" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Flinux-if-your-shell-script-is-running-skip-the-next-execution-and-exit-it-cron-job%2F&#038;title=Linux%3A%20If%20your%20shell%20script%20is%20running%2C%20skip%20the%20next%20execution%20and%20exit%20it" data-a2a-url="https://www.dbrnd.com/2017/06/linux-if-your-shell-script-is-running-skip-the-next-execution-and-exit-it-cron-job/" data-a2a-title="Linux: If your shell script is running, skip the next execution and exit it"></a></p><p>We configured lots of cron job in our production Linux &#8211; PostgreSQL Server. Different schedules like monitor the database performance, monitor the backup process, take a database backup, replicate a database copy. </p>
<blockquote><p>We set few monitor cron jobs at every 5 minutes. Now the situation is, few monitoring scripts are running even more than 5 minutes, and as per the scheduled, same script could start the execution after 5 minutes. </p>
<p>Now, the same script is running more than one time. </p></blockquote>
<blockquote><p>We should monitor this kind of situation, and we should prevent the next execution of the same script if it is already in running state. It also helps us to reduce an unnecessary load on the database server.</p></blockquote>
<p>I prepared below two options; you can embed any one of it in your shell script.</p>
<p><strong>Option script 1:</strong></p>
<pre class="crayon-plain-tag">if pidof -x $(basename $0) &gt; /dev/null; then
  for p in $(pidof -x $(basename $0)); do
    if [ $p -ne $$ ]; then
	echo "*****************************************************************"
	echo "  ***Warning*** Script $0 is already running...So existing...    "
	echo "*****************************************************************"
	exit 1
    fi
  done
fi</pre> </p>
<p><strong>Option script 2:</strong></p>
<pre class="crayon-plain-tag">isrunning=`ps -ef | grep $(basename $0) | grep -v $$ | grep -v grep | wc -l`
 
if [ "$isrunning" -ne 0 ]; then
   echo "**************************************************************"
   echo "  ***Warning*** Script $0 is already running... So exiting... "
   echo "**************************************************************"
   exit 1
fi</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
