How to find out if a service is running with bash script

  • 0
I wrote a simple bash script which checks for a service or process whether is running or not and does specific actions (reload, send E-Mail) if there is no such process running.
I have tried the script on Ubuntu server but it should work for all Linux distributions as well as Unix (e.g Mac OS X, FreeBSD etc).
Here is the script:
#!/bin/bash
SERVICE='listener.py'
if [ "$(ps ax|grep -v grep|grep $SERVICE)" ] ; then
  echo "Running"
  exit 0
else
  echo "Not Running"
  /usr/bin/python  /var/www/listener.py &
  exit 0
fi

How to add jQuery in certain pages on Drupal

  • 0
Sometimes we need to attach a js script on specific pages on Drupal, in this post i will show you how to do that. Firstly we need to know the query string so we can check it against the URL you could use this $_GET['q'] == 'path_to_your_page' see the following example :

if ($_GET['q'] == 'node/add/vacation' 
|| $_GET['q'] == 'node/add/time-record' 
|| $_GET['q'] == 'node/add/mission' ) {
  drupal_add_js(drupal_get_path('module', 'my_module') . '/auto_titles.js');
}

Now you need to get the path of the current URL by using Java script -> "var url = window.location" Putting it all together:

$(document).ready(function(){
  comingUrl = window.location; // get the URL
  host = window.location.host; // get the host
  drupalPath = Drupal.settings.basePath; 
  
  desiredUrl = 'http://' + host + drupalPath;
  vacation = desiredUrl + 'en/node/add/vacation';
  timeRecord = desiredUrl + 'en/node/add/time-record';
  mission = desiredUrl + 'en/node/add/mission';
  
  //alert(vacation);

  if (comingUrl == vacation) { // if true the following line will be executed only in "en/node/add/vacation" page
    $(".breadcrumb").append("something");
  } else if (comingUrl == timeRecord){
    $(".breadcrumb").append("something");
  } else if (comingUrl == mission){
    $(".breadcrumb").append("something");
  }
  
});
I hope you find this as useful as I have.

Ahmed Samir's blog

  • 0
Finally, I decided to start writing in my blog :)
First off all let me introduce myself  to you my name is Ahmed Samir I am a Software Developer and Web Master who loves to work with web technologies.
I am a challenging guy, I like to share useful things with you, things which make me knowledgeable and This is why i created this blog.
Another thing you'll find my writings about technical, personal ...etc
Feel free to contact me any time with questions, comments or requests! 
Your feedback will be greatly appreciated.