Friday, August 8, 2014

Gaia: how to cron binaries depending on shared libraries

I have recently came across an issue that scheduling custom scripts with cron may not work properly on Gaia for binaries that require shared libraries to run.

For example, sendmail uses libProdUtils.so and requires access to this lib file when scripted. Path is defined for your bash shell, but not for cron. So if you make a simple script like this one:


#!/bin/bash 
/opt/CPsuite-R77/fw1/bin/sendmail -t 1.1.1.1 -m /var/tmp/testmail.txt

to send an email on a particular even, it works perfectly from bash CLI but fails when running through cron job.

To fix it, you need the script to call shell parameters explicitly. To do it, add source /etc/bashrc before executing any other command:

#!/bin/bash 
source /etc/bashrc
/opt/CPsuite-R77/fw1/bin/sendmail -t 1.1.1.1 -m /var/tmp/testmail.txt

By the way, Check Point own sendmail sucks big time and can only run when using message file and not as just a CLI command, even with 100% correct syntax. But this is something for another post.

4 comments:

  1. Just checked on R76, there's nice sendmail in /usr/sbin/sendmail:
    # ls -l /usr/sbin/sendmail
    lrwxrwxrwx 1 admin root 14 Apr 22 14:10 /usr/sbin/sendmail -> /usr/bin/msmtp
    Looks like it is provided by msmtp package, that claims full compatibility with sendmail. From its SourceForge page:
    msmtp is an SMTP client with a sendmail compatible interface. It can be used with Mutt and other mail user agents.

    Why can't it be used?

    ReplyDelete
  2. Andrey, ask Check Point about that. There is an SK saying one has to use CP sendmail and not the Linux one.

    ReplyDelete
  3. I always put . /etc/profile.d/CP.sh in my scripts

    ReplyDelete
  4. ditto kriver; to have CP variables and and to avoid redoing the script for every version of fw.

    eg, for MDS do:

    . /etc/profile.d/CP.sh
    SENDMAIL="$MDS_TEMPLATE/bin/sendmail"

    and send mail with, this for example
    echo "text" | $SENDMAIL or cat file | $SENDMAIL

    use -t (RELAY) -s (Subject) -f (FROM) recipient(s)

    ReplyDelete