Beginner, help, script - Aix

This is a discussion on Beginner, help, script - Aix ; Hi! I'm not working in AIX at all but I have the need to make a script that would kill all the processes that have "ftp" in their name. The system is AIX 5.2, shell - ksh. I know how ...

+ Reply to Thread
Results 1 to 10 of 10

Thread: Beginner, help, script

  1. Beginner, help, script

    Hi!
    I'm not working in AIX at all but I have the need to make a script that
    would kill all the processes that have "ftp" in their name.
    The system is AIX 5.2, shell - ksh.

    I know how to list the processes and kill them manually:
    # ps -ef | grep ftp
    root 54758 6966 0 10:00:36 - 0:00 ftpd
    root 60452 41750 0 10:15:25 pts/61 0:00 grep ftp
    informix 67210 48028 0 02:53:10 - 0:01 ftp -n
    informix 70494 21584 0 02:13:45 - 0:00 ftp -n
    #

    I need to kill all the processes that are running under the "informix"
    account and have "ftp -n" in their name (not the ftpd daemon)

    I tried it like this:

    ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    if "$uname" = "informix" && "$srcstr" = "ftp -n"
    then
    kill pid
    fi


    but this results in an error: ./killFTP[2]: root: not found.

    Can anyone help me with this, please?

    Thanks in advance!
    --
    Pozdrav

    Jednom su izmislili papir po imenu Chuck Norris, ali papir nije dopuštao da
    itko sere po njemu !
    --
    Pozdrav

    Jednom su izmislili papir po imenu Chuck Norris, ali papir nije dopuštao da
    itko sere po njemu !

  2. Re: Beginner, help, script

    On 15 Jul, 09:39, Revenger wrote:

    > ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    > if "$uname" = "informix" && "$srcstr" = "ftp -n"
    > then
    > kill pid
    > fi
    >
    > but this results in an error: ./killFTP[2]: root: not found.


    First, never write a script that takes action until you know it works.
    Instead, say what the action would be:

    ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    if "$uname" = "informix" && "$srcstr" = "ftp -n"
    then
    echo kill pid
    fi


    Second, all shell variables need a '$':

    ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    if "$uname" = "informix" && "$srcstr" = "ftp -n"
    then
    echo kill $pid
    fi

    Third, "if" needs a "test", usually written as one or two square
    brackets. I will leave the choice between the two as an exercise for
    the reader.

    ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    if [[ "$uname" = "informix" && "$srcstr" = "ftp -n" ]]
    then
    echo kill $pid
    fi

    Lastly as a matter of style on AIX, I would recommend "ps -F" to avoid
    parsing errors but this is unfortunately not portable.

  3. Re: Beginner, help, script

    On Tue, 15 Jul 2008 03:01:58 -0700 (PDT), sjm wrote:

    > First, never write a script that takes action until you know it works.
    > Instead, say what the action would be:


    First, thank you very much for the explanation and the script itself.
    I did write the "echo" first, but as I said, I don't know how it works so I
    removed the "echo" command from my script not to confuse you with my
    code...

    Thanks again for the code, you explained it really good. I do some Win32
    programming and batch programming so I can see where my mistakes were.

    This post is going in my "knowledge base" :-)

    --
    Pozdrav

    Jednom su izmislili papir po imenu Chuck Norris, ali papir nije dopuštao da
    itko sere po njemu !

  4. Re: Beginner, help, script

    On Jul 15, 3:01*pm, sjm wrote:
    > On 15 Jul, 09:39, Revenger wrote:
    >
    > > ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    > > if "$uname" = "informix" && "$srcstr" = "ftp -n"
    > > * * * * then
    > > * * * * * * * * kill pid
    > > fi

    >
    > > but this results in an error: *./killFTP[2]: root: *not found.

    >
    > First, never write a script that takes action until you know it works.
    > Instead, say what the action would be:
    >
    > ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    > if "$uname" = "informix" && "$srcstr" = "ftp -n"
    > * * * * then
    > * * * * * * * * echo kill pid
    > fi
    >
    > Second, all shell variables need a '$':
    >
    > ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    > if "$uname" = "informix" && "$srcstr" = "ftp -n"
    > * * * * then
    > * * * * * * * * echo kill $pid
    > fi
    >
    > Third, "if" needs a "test", usually written as one or two square
    > brackets. I will leave the choice between the two as an exercise for
    > the reader.
    >
    > ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    > if [[ "$uname" = "informix" && "$srcstr" = "ftp -n" ]]
    > * * * * then
    > * * * * * * * * echo kill $pid
    > fi
    >
    > Lastly as a matter of style on AIX, I would recommend "ps -F" to avoid
    > parsing errors but this is unfortunately not portable.


    Does the command "read uname pid c3 c4 c5 c6 srcstr" runs for all the
    lines returned by "grep ftp"? I suppose, No, it will just read the
    values from the first returned line. Using awk would be more
    appropriate as it will find required lines and perform appropriate
    actions on them.

  5. Re: Beginner, help, script

    On se souviendra toujours du Tue, 15 Jul 2008 10:39:37 +0200 quand Revenger
    (Revenger) prit sa plume electronique pour nous ecrire :

    >Hi!
    >I'm not working in AIX at all but I have the need to make a script that
    >would kill all the processes that have "ftp" in their name.
    >The system is AIX 5.2, shell - ksh.
    >
    >I know how to list the processes and kill them manually:
    ># ps -ef | grep ftp
    > root 54758 6966 0 10:00:36 - 0:00 ftpd
    > root 60452 41750 0 10:15:25 pts/61 0:00 grep ftp
    >informix 67210 48028 0 02:53:10 - 0:01 ftp -n
    >informix 70494 21584 0 02:13:45 - 0:00 ftp -n
    >#
    >
    >I need to kill all the processes that are running under the "informix"
    >account and have "ftp -n" in their name (not the ftpd daemon)
    >
    >I tried it like this:
    >
    >ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    >if "$uname" = "informix" && "$srcstr" = "ftp -n"
    > then
    > kill pid
    >fi
    >
    >
    >but this results in an error: ./killFTP[2]: root: not found.
    >
    >Can anyone help me with this, please?
    >
    >Thanks in advance!
    >--
    >Pozdrav
    >
    >Jednom su izmislili papir po imenu Chuck Norris, ali papir nije dopu¨tao da
    >itko sere po njemu !



    ps -u informix | grep "ftp -n" |awk '{print $2} | while read pid
    do
    kill $pid
    done



  6. Re: Beginner, help, script

    >
    >ps -u informix | grep "ftp -n" |awk '{print $2} | while read pid
    >do
    > kill $pid
    >done


    ps -u informix | grep "ftp -n" |awk '{print $2}' | while read pid
    do
    kill $pid
    done

    is more correct.

  7. Re: Beginner, help, script

    On se souviendra toujours du Fri, 18 Jul 2008 02:30:44 -0700 (PDT) quand Ashok Sangra
    (Ashok Sangra) prit sa plume electronique pour nous ecrire :

    >On Jul 15, 3:01*pm, sjm wrote:
    >> On 15 Jul, 09:39, Revenger wrote:
    >>
    >> > ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    >> > if "$uname" = "informix" && "$srcstr" = "ftp -n"
    >> > * * * * then
    >> > * * * * * * * * kill pid
    >> > fi

    >>
    >> > but this results in an error: *./killFTP[2]: root: *not found.

    >>
    >> First, never write a script that takes action until you know it works.
    >> Instead, say what the action would be:
    >>
    >> ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    >> if "$uname" = "informix" && "$srcstr" = "ftp -n"
    >> * * * * then
    >> * * * * * * * * echo kill pid
    >> fi
    >>
    >> Second, all shell variables need a '$':
    >>
    >> ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    >> if "$uname" = "informix" && "$srcstr" = "ftp -n"
    >> * * * * then
    >> * * * * * * * * echo kill $pid
    >> fi
    >>
    >> Third, "if" needs a "test", usually written as one or two square
    >> brackets. I will leave the choice between the two as an exercise for
    >> the reader.
    >>
    >> ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    >> if [[ "$uname" = "informix" && "$srcstr" = "ftp -n" ]]
    >> * * * * then
    >> * * * * * * * * echo kill $pid
    >> fi
    >>
    >> Lastly as a matter of style on AIX, I would recommend "ps -F" to avoid
    >> parsing errors but this is unfortunately not portable.

    >
    >Does the command "read uname pid c3 c4 c5 c6 srcstr" runs for all the
    >lines returned by "grep ftp"? I suppose, No, it will just read the
    >values from the first returned line. Using awk would be more
    >appropriate as it will find required lines and perform appropriate
    >actions on them.



    ps -u informix | grep "ftp -n" |awk '{print $2}' | while read pid
    do
    kill $pid
    done

  8. Re: Beginner, help, script

    On se souviendra toujours du Tue, 15 Jul 2008 10:39:37 +0200 quand Revenger
    (Revenger) prit sa plume electronique pour nous ecrire :

    >Hi!
    >I'm not working in AIX at all but I have the need to make a script that
    >would kill all the processes that have "ftp" in their name.
    >The system is AIX 5.2, shell - ksh.
    >
    >I know how to list the processes and kill them manually:
    ># ps -ef | grep ftp
    > root 54758 6966 0 10:00:36 - 0:00 ftpd
    > root 60452 41750 0 10:15:25 pts/61 0:00 grep ftp
    >informix 67210 48028 0 02:53:10 - 0:01 ftp -n
    >informix 70494 21584 0 02:13:45 - 0:00 ftp -n
    >#
    >
    >I need to kill all the processes that are running under the "informix"
    >account and have "ftp -n" in their name (not the ftpd daemon)
    >
    >I tried it like this:
    >
    >ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    >if "$uname" = "informix" && "$srcstr" = "ftp -n"
    > then
    > kill pid
    >fi
    >
    >
    >but this results in an error: ./killFTP[2]: root: not found.
    >
    >Can anyone help me with this, please?
    >
    >Thanks in advance!
    >--
    >Pozdrav
    >
    >Jednom su izmislili papir po imenu Chuck Norris, ali papir nije dopu¨tao da
    >itko sere po njemu !


    ps -u informix | grep "ftp -n" |awk '{print $2}' | while read pid
    do
    kill $pid
    done

  9. Re: Beginner, help, script

    On Jul 18, 5:01 pm, Denis Fournier wrote:
    > On se souviendra toujours du Tue, 15 Jul 2008 10:39:37 +0200 quand Revenger
    > (Revenger) prit sa plume electronique pour nous ecrire :
    >
    >
    >
    > >Hi!
    > >I'm not working in AIX at all but I have the need to make a script that
    > >would kill all the processes that have "ftp" in their name.
    > >The system is AIX 5.2, shell - ksh.

    >
    > >I know how to list the processes and kill them manually:
    > ># ps -ef | grep ftp
    > > root 54758 6966 0 10:00:36 - 0:00 ftpd
    > > root 60452 41750 0 10:15:25 pts/61 0:00 grep ftp
    > >informix 67210 48028 0 02:53:10 - 0:01 ftp -n
    > >informix 70494 21584 0 02:13:45 - 0:00 ftp -n
    > >#

    >
    > >I need to kill all the processes that are running under the "informix"
    > >account and have "ftp -n" in their name (not the ftpd daemon)

    >
    > >I tried it like this:

    >
    > >ps -ef | grep ftp | read uname pid c3 c4 c5 c6 srcstr
    > >if "$uname" = "informix" && "$srcstr" = "ftp -n"
    > > then
    > > kill pid
    > >fi

    >
    > >but this results in an error: ./killFTP[2]: root: not found.

    >
    > >Can anyone help me with this, please?

    >
    > >Thanks in advance!
    > >--
    > >Pozdrav

    >
    > >Jednom su izmislili papir po imenu Chuck Norris, ali papir nije dopu¨tao da
    > >itko sere po njemu !

    >
    > ps -u informix | grep "ftp -n" |awk '{print $2}' | while read pid
    > do
    > kill $pid
    > done


    If this truly is an informix process then i wouldn't suggest killing
    it.... should use "onmode -z" on it's PID otherwise you have a chance
    on killing the engine abruptly... and with informix, that's not a good
    practice...

    Pete

  10. Re: Beginner, help, script

    On Sun, 20 Jul 2008 17:56:41 -0700 (PDT), old-racefan wrote:

    > If this truly is an informix process then i wouldn't suggest killing
    > it.... should use "onmode -z" on it's PID otherwise you have a chance
    > on killing the engine abruptly... and with informix, that's not a good
    > practice...


    That is true, but, the process isn't attached to the database ...
    "informix" is just a username (account) under wich the ftp session was
    started, so there's no fear of killing the RDBMS engine and making all hell
    break loose on database consistency ...

    I never kill processes that are working with DBMS with kill, and if I have
    to do that I use onmode ...

    --
    Pozdrav

    Jednom su izmislili papir po imenu Chuck Norris, ali papir nije dopuštao da
    itko sere po njemu !

+ Reply to Thread