{"id":185,"date":"2009-08-25T07:01:00","date_gmt":"2009-08-25T07:01:00","guid":{"rendered":"http:\/\/aldarias.es\/wordpress\/?p=185"},"modified":"2009-08-25T07:01:00","modified_gmt":"2009-08-25T07:01:00","slug":"parar-una-aplicacion-cuando-otras-se-ejecutan","status":"publish","type":"post","link":"http:\/\/aldarias.es\/wordpress\/?p=185","title":{"rendered":"Parar una aplicacion cuando otras se ejecutan"},"content":{"rendered":"<p>#!\/bin\/bash<br \/># Por Paco Aldarias.<br \/># 23.8.2009<br \/># idle.sh<br \/># Este scripts en bash permite activar<br \/># mldonkey cuando esta idle o inactivo<br \/># Siendo el estado activo, cuando se ejecuta firefox xql etc<\/p>\n<p>apli=\u00bbfirefox xql et.x86&#8243;<br \/>temp=\u00bb\/tmp\/idle.txt\u00bb<br \/>ml=\u00bb\/home\/paco\/mldonkey.sh\u00bb<br \/>flog=\u00bb\/tmp\/idle.log\u00bb<br \/>log=1<\/p>\n<p>[ -f $flog ] &amp;&amp; rm -f  $flog<br \/>[ $log -eq 1 ] &amp;&amp; echo \u00abArrancado: $(date +%H:%M:%S)  $flog\u00bb >> $flog<\/p>\n<p># tiempos en segundos<br \/>tini=3m<br \/>tidle=1m<br \/>tbusy=5m<\/p>\n<p># Limpiamos si esta en ejecuci\u00f3n el script.<br \/>if [ -f $temp ];then<br \/> kill $(cat $temp)<br \/> rm -f $temp<br \/>fi<\/p>\n<p># Si esta en marcha  paramos ml<br \/>proc=$(ps aux | grep mlnet | grep -v grep | wc -l)<br \/>[ $proc -gt 0 ] &amp;&amp; $ml stop<br \/>[ $1 ] &amp;&amp; [ $1 = \u00abstop\u00bb ] &amp;&amp;  exit<\/p>\n<p>sleep $tini<\/p>\n<p># Bucle infinito<br \/>while :<br \/>do<br \/>descargar=1<\/p>\n<p># Hacemos esto por cada aplicacion que queremos que para ml<br \/>for i in $(echo $apli)<br \/>do<br \/> if [ $descargar -eq 1 ];then<br \/> up=$(ps aux | grep \u00ab$i\u00bb | grep -v grep |  awk  &#8216;{print $11}&#8217;)<br \/>      if [ $up ];then<br \/>         descargar=0<br \/>         [ $log -eq 1 ] &amp;&amp; echo \u00abUP: $up $i\u00bb>> $flog<br \/>      fi<br \/> fi<br \/>done<\/p>\n<p># Descargamos. Ponemos en marcha mldonkey<br \/>if [ $descargar -eq 1 ]<br \/>then<br \/> [ $log -eq 1 ] &amp;&amp; echo \u00ab$(date +%H:%M:%S) Podemos descargar\u00bb >> $flog<br \/> if [ ! -f  $temp ];then<br \/>   echo $$ > $temp<br \/>   sh $ml start<br \/>   fi<br \/> sleep $tidle<br \/># Apagamos. Paramos mldonkey<br \/>else<br \/> [ $log -eq 1 ] &amp;&amp;  echo \u00ab$(date +%H:%M:%S) No podemos descargar\u00bb >> $flog<br \/> if [ -f  $temp ];then<br \/>   sh $ml stop<br \/>   rm -f $temp<br \/> fi<br \/> sleep $tbusy<br \/>fi<\/p>\n<p>done<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#!\/bin\/bash# Por Paco Aldarias.# 23.8.2009# idle.sh# Este scripts en bash permite activar# mldonkey cuando esta idle o inactivo# Siendo el estado activo, cuando se ejecuta firefox xql etc apli=\u00bbfirefox xql et.x86&#8243;temp=\u00bb\/tmp\/idle.txt\u00bbml=\u00bb\/home\/paco\/mldonkey.sh\u00bbflog=\u00bb\/tmp\/idle.log\u00bblog=1 [ -f $flog ] &amp;&amp; rm -f $flog[ $log &hellip; <a href=\"http:\/\/aldarias.es\/wordpress\/?p=185\">Sigue leyendo <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"episode_type":"","audio_file":"","podmotor_file_id":"","podmotor_episode_id":"","cover_image":"","cover_image_id":"","duration":"","filesize":"","filesize_raw":"","date_recorded":"","explicit":"","block":"","itunes_episode_number":"","itunes_title":"","itunes_season_number":"","itunes_episode_type":"","footnotes":""},"categories":[13,16],"tags":[],"class_list":["post-185","post","type-post","status-publish","format-standard","hentry","category-bash","category-linux"],"_links":{"self":[{"href":"http:\/\/aldarias.es\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/aldarias.es\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/aldarias.es\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/aldarias.es\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/aldarias.es\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=185"}],"version-history":[{"count":0,"href":"http:\/\/aldarias.es\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/185\/revisions"}],"wp:attachment":[{"href":"http:\/\/aldarias.es\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/aldarias.es\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=185"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/aldarias.es\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}