<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Linux Forum &mdash; Помогите написать bash скрипт]]></title>
	<link rel="self" href="https://linuxforum.ru/extern.php?action=feed&amp;tid=34381&amp;type=atom" />
	<updated>2014-04-09T18:19:24Z</updated>
	<generator>PunBB</generator>
	<id>https://linuxforum.ru/viewtopic.php?id=34381</id>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404222#p404222" />
			<content type="html"><![CDATA[<p>Так и пиши в лог<br /></p><div class="codebox"><pre><code>echo &quot;То, что хочешь записать&quot; &gt;&gt; /полный_путь/log.file</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Vascom]]></name>
				<uri>https://linuxforum.ru/profile.php?id=5339</uri>
			</author>
			<updated>2014-04-09T18:19:24Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404222#p404222</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404141#p404141" />
			<content type="html"><![CDATA[<p>а подскажите как теперь сделать запись в лог файл. в случае если веб сервер был перезапущен. Тоесть скрипт будет в кроне (каждые 5&nbsp; мин запускаться). если страничка доступна то мы ничего не делаем и ничего не пишем. а вот если она не доступна мы убиваем процесс глассфиша и запускаем его заного и пишем все действия в лог с датой и так далее<br />вот код <br /><div class="termtitle" style="font-family: sans-serif; position:relative; height:auto; width:auto; background:#3A4061; color:#FFFFFF; padding: 1px;"><b> Консоль:</b></div>
<div class="termcont" style="font-family: Terminus; position:relative; height:auto; width:auto; overflow-x:scroll; white-space: nowrap ; overflow-y:auto;background:#000000; color:#4EF44E; line-height:1.2; padding: 3px; font-size: 1rem; max-height: 60vh">#!/bin/bash<br />ADDRESS=&quot;my_url/index.jsp&quot;<br />function stop_domain {<br />&nbsp; &nbsp; PID=`ps -ef|grep java|grep glassfish|awk &#039;{print $2}&#039;`<br />&nbsp; &nbsp; if [[ &quot;$PID&quot; != &quot;&quot; ]]<br />&nbsp; &nbsp; &nbsp; &nbsp; then<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kill -9 $PID<br />&nbsp; &nbsp; fi<br />&nbsp; &nbsp; PID2=`ps -ef|grep java|grep glassfish|awk &#039;{print $2}&#039;`<br />&nbsp; &nbsp; return $PID2<br />}<br />curl --silent $ADDRESS|grep Hello<br />if [ &quot;$?&quot; -eq 0 ]<br />&nbsp; &nbsp; then<br />&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;Application server is alive.&quot;<br />&nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp; &nbsp; result=$(stop_domain)<br />&nbsp; &nbsp; &nbsp; &nbsp; if [[ &quot;$result&quot; == &quot;&quot; ]]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /home/glassfishUser/glassfish3/glassfish/bin/asadmin start-domain&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; fi</div></p>]]></content>
			<author>
				<name><![CDATA[bitmaster]]></name>
				<uri>https://linuxforum.ru/profile.php?id=33944</uri>
			</author>
			<updated>2014-04-09T03:03:17Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404141#p404141</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404118#p404118" />
			<content type="html"><![CDATA[<p><strong>XliN</strong>, имхо нормально все. Работает - не трогай <img src="https://linuxforum.ru/img/smilies/ab.gif" alt="ab" /></p>]]></content>
			<author>
				<name><![CDATA[yars]]></name>
				<uri>https://linuxforum.ru/profile.php?id=22799</uri>
			</author>
			<updated>2014-04-08T17:23:59Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404118#p404118</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404111#p404111" />
			<content type="html"><![CDATA[<p>Пользуясь случаем прошу потыкать носом и подсказать что сделал не так. Вот сегодня накатал скрипт<br /><div class="termtitle" style="font-family: sans-serif; position:relative; height:auto; width:auto; background:#3A4061; color:#FFFFFF; padding: 1px;"><b> Консоль:</b></div>
<div class="termcont" style="font-family: Terminus; position:relative; height:auto; width:auto; overflow-x:scroll; white-space: nowrap ; overflow-y:auto;background:#000000; color:#4EF44E; line-height:1.2; padding: 3px; font-size: 1rem; max-height: 60vh">#!/bin/sh </p><p>IP_WEB=192.168.1.108 # IP адрес шары<br />PID_TOM=&quot;/var/run/tomcat6.pid&quot;<br />WRITELOCK=&quot;/var/lib/tomcat6/solr_home/data/index/write.lock&quot;<br />DIR_IN=/var/Motiw/scripts<br />DIR_OUT=&quot;${IP_WEB}:/var/Motiw/scripts&quot;</p><p>filecount=`find $DIR_IN -type f | wc -l`</p><p>if [ $filecount -eq 0 ]; then<br />echo &quot;Error. Not mount script NFS&quot;<br />#Монтируем /var/Motiw/scripts для tomcat<br />/bin/mount $DIR_OUT $DIR_IN<br />&nbsp; &nbsp; &nbsp; &nbsp; if [ $? -ne 0 ]; then<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo ERROR<br />&nbsp; &nbsp; &nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sleep 3<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #Проверяем PID tomcat. Если запущен, рестаруем<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # и удаляем возможно подвисший write.lock<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if [ -e $PID_TOM ]; then<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if [ -e $WRITELOCK ]; then rm $WRITELOCK &amp;&amp; /etc/init.d/tomcat6 restart<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo &quot;${WRITELOCK} отсутствует&quot; &amp;&amp; /etc/init.d/tomcat6 restart<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fi<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if [ -e $WRITELOCK ]; then<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rm $WRITELOCK &amp;&amp; /etc/init.d/tomcat6 start<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo &quot;${WRITELOCK} отсутствует&quot; &amp;&amp; /etc/init.d/tomcat6 start<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fi<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fi<br />&nbsp; &nbsp; &nbsp; &nbsp; fi<br />echo &quot;mount OK&quot; &gt;&gt; /var/log/mountfix.log<br />else<br />#Если все смонтировано, ничего не делаем<br />echo &quot;mount OK&quot; &gt;&gt; /var/log/mountfix.log &amp;&amp; exit<br />fi<br /></div><br />Суть его в следующем. Каждые 15 минут в кроне проверяется примонтирован ли диск. Если да, то супер, если нет то монтирует его. Проверяет на наличие файла блокировки. Если он есть - удаляет. Затем перезапускает сервис tomcat. Через одно место реализовал? =)</p><p>З.Ы. Надо поработать с синтаксисом. Не осень красиво смотрится. =)</p>]]></content>
			<author>
				<name><![CDATA[XliN]]></name>
				<uri>https://linuxforum.ru/profile.php?id=6412</uri>
			</author>
			<updated>2014-04-08T16:26:17Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404111#p404111</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404108#p404108" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>bitmaster пишет:</cite><blockquote><div class="codebox"><pre><code>PID=`ps -ef|grep java|grep glassfish|awk &#039;{print $2}&#039;`</code></pre></div></blockquote></div><p>Эту конструкцию разве нельзя заменить на </p><div class="codebox"><pre><code>PID=$(/sbin/pidof /path/to/glassfish)</code></pre></div><p> ?<br /></p><div class="quotebox"><blockquote><p>и вопрос . почему в функции если разкоментить echo то он будет попадать сюда&nbsp; PID=.. какого хрена</p></blockquote></div><p>Пропущен CR/LF? Проверяется <em>cat -A your_mega_script.sh</em>.</p>]]></content>
			<author>
				<name><![CDATA[yars]]></name>
				<uri>https://linuxforum.ru/profile.php?id=22799</uri>
			</author>
			<updated>2014-04-08T14:40:25Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404108#p404108</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404107#p404107" />
			<content type="html"><![CDATA[<p>и вопрос . почему в функции если разкоментить echo то он будет попадать сюда&nbsp; PID=.. какого хрена</p>]]></content>
			<author>
				<name><![CDATA[bitmaster]]></name>
				<uri>https://linuxforum.ru/profile.php?id=33944</uri>
			</author>
			<updated>2014-04-08T14:16:03Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404107#p404107</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404106#p404106" />
			<content type="html"><![CDATA[<p>в общем скрипт мой готов, <br />что он делает? <br />проверяет слово hello на страничке, если такого слова нет то он убивает процесс glassfish а и запускает его заново. скрипт будет в кроне и будет запускаться раз в 5 мин. Так что подскажите если вдруг я что то не учел <br /><div class="termtitle" style="font-family: sans-serif; position:relative; height:auto; width:auto; background:#3A4061; color:#FFFFFF; padding: 1px;"><b> Консоль:</b></div>
<div class="termcont" style="font-family: Terminus; position:relative; height:auto; width:auto; overflow-x:scroll; white-space: nowrap ; overflow-y:auto;background:#000000; color:#4EF44E; line-height:1.2; padding: 3px; font-size: 1rem; max-height: 60vh">#!/bin/bash</p><p>ADDRESS=&quot;my_url/index.jsp&quot;</p><p>function stop_domain {<br />&nbsp; &nbsp; #echo &quot;stop_domain&quot;</p><p>&nbsp; &nbsp; PID=`ps -ef|grep java|grep glassfish|awk &#039;{print $2}&#039;`</p><p>&nbsp; &nbsp; #echo &quot;Glassfish PID = &#039;$PID&#039;. Trying to kill it...&quot;</p><p>&nbsp; &nbsp; if [[ &quot;$PID&quot; != &quot;&quot; ]]<br />&nbsp; &nbsp; &nbsp; &nbsp; then<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #echo &quot;No need to kill.&quot;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kill -9 $PID<br />&nbsp; &nbsp; fi</p><p>&nbsp; &nbsp; PID2=`ps -ef|grep java|grep glassfish|awk &#039;{print $2}&#039;`</p><p>&nbsp; &nbsp; #echo &quot;Glassfish PID after &#039;kill&#039; command = &#039;$PID2&#039;&quot;</p><p>&nbsp; &nbsp; return $PID2<br />}</p><p>#stop_domain</p><p>curl --silent $ADDRESS|grep Hello</p><p>if [ &quot;$?&quot; -eq 0 ]<br />&nbsp; &nbsp; then<br />&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;Application server is alive.&quot;<br />&nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp; &nbsp; result=$(stop_domain)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if [[ &quot;$result&quot; == &quot;&quot; ]]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #echo &quot;Executing start-domain command...&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /home/glassfishUser/glassfish3/glassfish/bin/asadmin start-domain<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #echo &quot;Application server was started successfully!&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; fi<br /></div></p>]]></content>
			<author>
				<name><![CDATA[bitmaster]]></name>
				<uri>https://linuxforum.ru/profile.php?id=33944</uri>
			</author>
			<updated>2014-04-08T14:13:28Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404106#p404106</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404105#p404105" />
			<content type="html"><![CDATA[<p>да все ок)</p>]]></content>
			<author>
				<name><![CDATA[i2ks]]></name>
				<uri>https://linuxforum.ru/profile.php?id=16</uri>
			</author>
			<updated>2014-04-08T14:06:42Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404105#p404105</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404104#p404104" />
			<content type="html"><![CDATA[<p><strong>i2ks</strong>, </p><div class="codebox"><pre><code>if [ $? -eq 0 ]; then whatewer; fi</code></pre></div><p>не работает? Или даже </p><div class="codebox"><pre><code>if program; then whatewer; fi</code></pre></div><p>?</p>]]></content>
			<author>
				<name><![CDATA[yars]]></name>
				<uri>https://linuxforum.ru/profile.php?id=22799</uri>
			</author>
			<updated>2014-04-08T13:53:19Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404104#p404104</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404103#p404103" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>yars пишет:</cite><blockquote><p> И echo там не нужно.</p></blockquote></div><p>о как, а как тогда?</p>]]></content>
			<author>
				<name><![CDATA[i2ks]]></name>
				<uri>https://linuxforum.ru/profile.php?id=16</uri>
			</author>
			<updated>2014-04-08T12:57:58Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404103#p404103</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404098#p404098" />
			<content type="html"><![CDATA[<p><strong>bitmaster</strong>, а поискать? <a href="http://www.opennet.ru/docs/RUS/bash_scripting_guide/">http://www.opennet.ru/docs/RUS/bash_scripting_guide/</a><br />Это условие, проверяющее код завершения последней выполненной команды. И echo там не нужно.</p>]]></content>
			<author>
				<name><![CDATA[yars]]></name>
				<uri>https://linuxforum.ru/profile.php?id=22799</uri>
			</author>
			<updated>2014-04-08T12:13:15Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404098#p404098</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404096#p404096" />
			<content type="html"><![CDATA[<p>а можете дать пояснение этой строке<br /></p><div class="codebox"><pre><code>if [ `echo $?` -eq 0 ]</code></pre></div>]]></content>
			<author>
				<name><![CDATA[bitmaster]]></name>
				<uri>https://linuxforum.ru/profile.php?id=33944</uri>
			</author>
			<updated>2014-04-08T11:59:37Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404096#p404096</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404092#p404092" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>i2ks пишет:</cite><blockquote><div class="quotebox"><cite>bitmaster пишет:</cite><blockquote><p>а вот вопрос если веб сервер упадет то по сути 404 мне выдаваться не будет.  у меня проблема с сервером glassfish , он как бы не падает ибо в процессах он висит, но веб веб сервер не доступен. (из за высоких нагрузок). думал определить &quot;упал он или нет&quot; пингом, но вариант не катит так как он частично работает и пингуется . а конкретно нужную мне страничку пингануть нельзя. в плане командой ping</p></blockquote></div><p>я же написал как это можно сделать, через curl дергать страницу.</p></blockquote></div><p>сейчас попробую. отпишу что получилось</p>]]></content>
			<author>
				<name><![CDATA[bitmaster]]></name>
				<uri>https://linuxforum.ru/profile.php?id=33944</uri>
			</author>
			<updated>2014-04-08T11:02:09Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404092#p404092</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404091#p404091" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>bitmaster пишет:</cite><blockquote><p>а вот вопрос если веб сервер упадет то по сути 404 мне выдаваться не будет.  у меня проблема с сервером glassfish , он как бы не падает ибо в процессах он висит, но веб веб сервер не доступен. (из за высоких нагрузок). думал определить &quot;упал он или нет&quot; пингом, но вариант не катит так как он частично работает и пингуется . а конкретно нужную мне страничку пингануть нельзя. в плане командой ping</p></blockquote></div><p>я же написал как это можно сделать, через curl дергать страницу.</p>]]></content>
			<author>
				<name><![CDATA[i2ks]]></name>
				<uri>https://linuxforum.ru/profile.php?id=16</uri>
			</author>
			<updated>2014-04-08T10:59:04Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404091#p404091</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Помогите написать bash скрипт]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=404090#p404090" />
			<content type="html"><![CDATA[<p>а вот вопрос если веб сервер упадет то по сути 404 мне выдаваться не будет.&nbsp; у меня проблема с сервером glassfish , он как бы не падает ибо в процессах он висит, но веб веб сервер не доступен. (из за высоких нагрузок). думал определить &quot;упал он или нет&quot; пингом, но вариант не катит так как он частично работает и пингуется . а конкретно нужную мне страничку пингануть нельзя. в плане командой ping</p>]]></content>
			<author>
				<name><![CDATA[bitmaster]]></name>
				<uri>https://linuxforum.ru/profile.php?id=33944</uri>
			</author>
			<updated>2014-04-08T10:51:18Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=404090#p404090</id>
		</entry>
</feed>
