Process management in linux-shell?

Discussion in 'Programming/Scripts' started by shamuk80, Mar 11, 2008.

  1. shamuk80

    shamuk80 New Member

    Hi all,

    I am facing a problem that may be handeled by a single command. There are lots of stale ftp processes running on servers that have nothing to do.

    These processes are run for the time but didnt kill themselves and i have to delete them manually.

    do have any idea to fix this problem?I mean the process should be run for a define period of time or we can set something upon its status so that it should be killed automatically.

    Many thanks.

    Sam
     
  2. falko

    falko Super Moderator ISPConfig Developer

    Which FTP server and Linux distribution are you using?
     
  3. shamuk80

    shamuk80 New Member

    I am using RHEL4 and RHEL5. Actually, we are running a script for tomcat, which is being called after 4 mins in cron job

    the entry in the crontab is as

    0,4,8,12,16,20,24,28,32,36,40,44,48,52,56 * * * * /opt/tomcat/batch/newAutoFtp/newAutoFtp.sh >/dev/null 2>&1

    the actuall script is
    # cat /opt/tomcat/batch/newAutoFtp/newAutoFtp.sh
    /usr/java/java/bin/java -classpath /newAutoFtp/:$CLASSPATH:/usr/java/java/jre/lib/ext/mssqlserver.jar:/usr/java/java/jre/lib/ext/msutil.jar:/usr/java/java/jre/lib/ext/msbase.jar::/opt/tomcat/shared/lib/destiny.jar:/opt/tomcat/shared/lib/mail.jar:/opt/tomcat/shared/lib/log4j.jar:/opt/tomcat/shared/lib/activation.jar:/opt/tomcat/shared/lib/commons-net.jar:/opt/tomcat/shared/lib/commons-httpclient.jar:/opt/tomcat/batch/classes com.destiny.bin.FTPUploader 0

    when its called after performing jobs (an sometimes not) it is not being killed automatically and I have to kill this process manually. Each day i have to kill this manually.

    # ps ax | grep /bin/baash

    19717 ? S 0:00 /bin/bash -c /opt/tomcat/batch/newAutoFtp/newAutoFtp.sh >/dev/null 2>&1

    hundreds of above stale processes are needed to be killed automatically.

    then i made some changes in the above script with thinking that to get this child process and killed it manually after an hour.

    # cat /opt/tomcat/batch/newAutoFtp/newAutoFtp.sh
    runtime=${1:-1h}
    mypid=$$
    /usr/java/java/bin/java -classpath /newAutoFtp/:$CLASSPATH:/usr/java/java/jre/lib/ext/mssqlserver.jar:/usr/java/java/jre/lib/ext/msutil.jar:/usr/java/java/jre/lib/ext/msbase.jar::/opt/tomcat/shared/lib/destiny.jar:/opt/tomcat/shared/lib/mail.jar:/opt/tomcat/shared/lib/log4j.jar:/opt/tomcat/shared/lib/activation.jar:/opt/tomcat/shared/lib/commons-net.jar:/opt/tomcat/shared/lib/commons-httpclient.jar:/opt/tomcat/batch/classes com.destiny.bin.FTPUploader 0 &
    commandpid=$!
    sleep $runtime
    kill -s SIGTERM $commandpid

    I am not good in scripting but a bit programming knowledge. its working fine but i think there must be some good way to handle this. Is there any way we can get status that the ( /usr/java/java/bin/java -classpath /newAutoFtp/:$CLASSPATH:/usr/java/java/jre/lib/ext/mssqlserver.jar:/usr/java/java/jre/lib/ext/msutil.jar:/usr/java/java/jre/lib/ext/msbase.jar::/opt/tomcat/shared/lib/destiny.jar:/opt/tomcat/shared/lib/mail.jar:/opt/tomcat/shared/lib/log4j.jar:/opt/tomcat/shared/lib/activation.jar:/opt/tomcat/shared/lib/commons-net.jar:/opt/tomcat/shared/lib/commons-httpclient.jar:/opt/tomcat/batch/classes com.destiny.bin.FTPUploader 0 ) can give us the status that its working or not? I am killing this after 1 hour time but normally it takes 3-4 mins to run properly.

    can you suggest any thing?

    Many thanks and sory my english is not so good :)

    Cheers
     
  4. falko

    falko Super Moderator ISPConfig Developer

    You can check the output of
    Code:
    ps aux
    if the script is still running, maybe combined with grep:
    Code:
    ps aux | grep [I]process[/I]
     

Share This Page