Aug 9, 2011
tom

Monitoring script in bash for perl script fails

Question

I have been sent a simple monitoring script by the author of ASSP, but I am not sure how to fix the PROC= line that causes an error.

#!/bin/bash
# ASSP watchdog process.#
# Start in the correct directory.
BASE=/usr/share/assp/
cd $BASE# Check for a running ASSP process.
PROC=`ps -axvO ucomm | grep Schedule::Cron | grep perl | awk '{print $1}'`FILES=`lsof -p "${PROC}" | grep /usr/share/assp | grep perl`# If ASSP is not running, start it.
if [ "${FILES}" ]
then {
echo "ASSP is already running."
}
else {
echo "Restarting ASSP."
perl assp.pl
} fi

It gives the following error.

ERROR: Must set personality to get -x option.

I am not sure if this line is remotely close to working. I was thinking of a write script that simply checks if there is a perl assp.pl script active and if not, start it manually. This server runs Debian and has ASSP/Postfix installed.

Answer

Part of the issue with ps is that there are some dozen versions of it and Linux’s ps tries to be compatible with all of them by figuring out what version’s options you’re trying to use. Options starting with - are BSD-style, but -v and -O are conflicting BSD options.

Try ps ax to get the command column of all of the processes currently running. Since you’re using it in a pipe it should use the whole command name, but if for some reason it truncates the commandline, use axww for unlimited width.

Related posts:

  1. How Do I Make A Bash Script for Git Checkin/Checkout?
  2. Bash script normal user to Root
  3. problem executing a bash script with utf8 encoding
  4. Bash commands not working after SFTP script
  5. Too complex password for a FTP bash script?

Leave a comment