Loading ...
Sorry, an error occurred while loading the content.

script to start process automatically

Expand Messages
  • Agnello George
    i am trying to write a script on my *test machine *to check if the process are running , and if they are not need to start them any idea why this is not
    Message 1 of 4 , Mar 15, 2008
    • 0 Attachment
      i am trying to write a script on my *test machine *to check if the process
      are running , and if they are not need to start them
      any idea why this is not working ??


      #!/bin/sh -x
      SERVICES= `ls -la /etc/init.d/ |awk '{print $9 }' |sed -e
      's/[^[:alnum:]]//g'`

      for i in $SERVICES
      do
      if [ $(ps -aux|grep -v grep |grep $i |wc -l) != 0 ];
      then
      . /etc/init.d/$i start
      else
      echo " the service $i is running "
      fi
      done


      --
      Regards
      Agnello Dsouza


      [Non-text portions of this message have been removed]
    • Godwin Stewart
      ... Hash: SHA1 On Sat, 15 Mar 2008 16:51:03 +0530, Agnello George ... Because the scripts in your startup directory don t find their way to the process
      Message 2 of 4 , Mar 15, 2008
      • 0 Attachment
        -----BEGIN PGP SIGNED MESSAGE-----
        Hash: SHA1

        On Sat, 15 Mar 2008 16:51:03 +0530, "Agnello George"
        <agnello.dsouza@...> wrote:

        > i am trying to write a script on my *test machine *to check if the
        > process are running , and if they are not need to start them
        > any idea why this is not working ??

        Because the scripts in your startup directory don't find their way to the
        process table. They start *other* processes that do.

        Note that many of these startup scripts can be interrogated by passing
        'status' as an argument.

        - --
        G. Stewart - gstewart@...

        Sign spotted outside a second hand shop:
        WE EXCHANGE ANYTHING - BICYCLES, WASHING MACHINES, ETC.
        WHY NOT BRING YOUR WIFE ALONG AND GET A WONDERFUL BARGAIN?
        -----BEGIN PGP SIGNATURE-----
        Version: GnuPG v1.4.7 (GNU/Linux)

        iD8DBQFH27XlK5oiGLo9AcYRAhFLAJ0VRAWLqCvm3mIG2hl/Q8Idc6HahgCgg42W
        U+hWSxqxDOYR/pftqJdLA00=
        =FTkE
        -----END PGP SIGNATURE-----
      • ed
        ... Rather than doing this hard work, why not use a superserver (a service that keeps other services running). One that I am fond of is in DJB s daemontools.
        Message 3 of 4 , Mar 15, 2008
        • 0 Attachment
          Agnello George wrote:
          >
          > i am trying to write a script on my *test machine *to check if the process
          > are running , and if they are not need to start them
          > any idea why this is not working ??
          >
          > #!/bin/sh -x
          > SERVICES= `ls -la /etc/init.d/ |awk '{print $9 }' |sed -e
          > 's/[^[:alnum:]]//g'`
          >
          > for i in $SERVICES
          > do
          > if [ $(ps -aux|grep -v grep |grep $i |wc -l) != 0 ];
          > then
          > . /etc/init.d/$i start
          > else
          > echo " the service $i is running "
          > fi
          > done

          Rather than doing this hard work, why not use a superserver (a service
          that keeps other services running).

          One that I am fond of is in DJB's daemontools. You can make something
          similar by adding lines to /etc/inittab, but I think the superserver is
          better since it's got command tools to start, stop and hup services.

          http://cr.yp.to/daemontools.html

          --
          The DSL to the moon pop is bombing like a macintosh because of the evil
          spock with a goatee.
          The Cult of the Dead Cow is going down like a whore in a room full of
          sailors.
          :: http://www.s5h.net/ :: http://www.s5h.net/gpg.html



          [Non-text portions of this message have been removed]
        • Mario Chamorro
          There a few things wrong the script and the goal you re trying to achieve: 1: the SERVICES line does not work because: 1.a. bug: the alnum sed call modifies
          Message 4 of 4 , Mar 15, 2008
          • 0 Attachment
            There a few things wrong the script and the goal you're trying to achieve:

            1: the SERVICES line does not work because:
            1.a. bug: the 'alnum' sed call modifies the script names from
            'yum-updatesd' to 'yumupdatesd' ( which is wrong ), for example
            1.b. ok: you use awk instead of gawk which is the true name of the GNU
            utility. awk is just a link to gawk .
            1.c. bug: when you gawk $9 , you get empty space. You should gawk $8 .
            1.d. ok: there is no reason to us -a , ls -l delivers the goods.
            1.e. ok: you should use the correct directory ( /etc/rc.d/init.d/ ).

            2: the PS line is inefficient because it uses grep and other things
            instead of using '--no-heading -C' which you can find using 'ps --help'

            3: ths script assumes that everything in the /etc/rc.d/init.d/ is
            supposed to run, including 'halt' . You should use 'chkconfig' to
            verify that ( use chkconfig --help ).

            Other than that, it's great! ( ho ho ). You might use a superserver as
            someone suggested like the DJB program ( he wrote Qmail ), or the
            Xinetd program which should already be on your server. Follow the
            other examples in /etc/xinetd.d/ . Also, you could use the
            /sbin/service DAEMON status ( or /etc/rc.d/init.d/DAEMON status )
            functionality that someone else mentioned. I think that covers the bases.

            -- Mario

            --- In linux@yahoogroups.com, "Agnello George" <agnello.dsouza@...> wrote:
            >
            > i am trying to write a script on my *test machine *to check if the
            process
            > are running , and if they are not need to start them
            > any idea why this is not working ??
            >
            >
            > #!/bin/sh -x
            > SERVICES= `ls -la /etc/init.d/ |awk '{print $9 }' |sed -e
            > 's/[^[:alnum:]]//g'`
            >
            > for i in $SERVICES
            > do
            > if [ $(ps -aux|grep -v grep |grep $i |wc -l) != 0 ];
            > then
            > . /etc/init.d/$i start
            > else
            > echo " the service $i is running "
            > fi
            > done
            > --
            > Regards Agnello Dsouza
          Your message has been successfully submitted and would be delivered to recipients shortly.