Link to home
Start Free TrialLog in
Avatar of VMWARE
VMWARE

asked on

Shell script, for control of a process.

Hello,

I need a script to monitor that it's running only one instance of a process, and that if it's not running, then launch that process.


Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of sweetfa2
sweetfa2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VMWARE
VMWARE

ASKER

Hello sweetfa2,

Could you explain me a little of your shell script?..

The process is this: /usr/bin/php -q /var/www/AFMNew/serviceFtp.php

Thanks
SOLUTION
Avatar of tel2
tel2
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VMWARE

ASKER

Hello tel2,

"Only one instance" = Only one process. Means that's not necessary relaunch the process once again...



SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VMWARE

ASKER

what issues?, and how do i for avoid that issues?
I'd do it like this
#!/bin/bash
cmd="/usr/bin/php -q /var/www/AFMNnew/serviceFtp.php"

while true
do
  pgrep -f "$cmd" >/dev/null || $cmd
    sleep 60  # Adjust to whatever period you want to check
done

Open in new window

But since Tintin's script doesn't appear to be designed to be run as a cron job, if it every dies for any reason, then your FTP script no longer has life insurance.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VMWARE

ASKER

This code would be correct?.

 
#!/bin/bash
cnt=`pgrep $1 | wc -l`
if [ $cnt -eq 0 ]
then
   /usr/bin/php -q /var/www/AFMNnew/serviceFtp.php
fi

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VMWARE

ASKER

Hello tel2,

I want to check hourly...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial