LF_SCRIPT_ACTION

Post Reply
jcats
Junior Member
Posts: 29
Joined: 03 Jan 2015, 14:36

LF_SCRIPT_ACTION

Post by jcats »

Hello,

I was just wondering how I can pass the actual contents of the LF_SCRIPT_ALERT to the bash script for LF_SCRIPT_ACTION, example my LF_SCRIPT_ACTION is set to

"/etc/csf/csf.lf_script_perm_action"

which contains

#!/bin/bash

# email subject
SUBJECT="$HOSTNAME - Possible Spam Script"

# Email To
EMAIL="email"

# Email text/message
# EMAILMESSAGE="/tmp/emailmessage.txt"
EMAILMESSAGE="TEST"
echo "info from CSF should go here"> $EMAILMESSAGE

# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
ForumAdmin
Moderator
Posts: 1523
Joined: 01 Oct 2008, 09:24

Re: LF_SCRIPT_ACTION

Post by ForumAdmin »

You have to use BASH programming to store the values passed to the script. BASH stores command line arguments passed to it in $1, $2, $3 etc, so:

Code: Select all

#!/bin/bash
HOSTNAME=`hostname`
SPATH=$1
COUNT=$2
SAMPLE=$3
SCRIPTS=$4

# email subject
SUBJECT="$HOSTNAME - Possible Spam Script"

# Email To
EMAIL="email"

# Email text/message
# EMAILMESSAGE="/tmp/emailmessage.txt"
EMAILMESSAGE="TEST"
echo -e "A script in $SPATH has sent at least $COUNT emails.\n\nHere is a sample from the exim log:\n$SAMPLE\n\nHere are some of the likely scripts:\n$SCRIPTS\n"> $EMAILMESSAGE

# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
jcats
Junior Member
Posts: 29
Joined: 03 Jan 2015, 14:36

Re: LF_SCRIPT_ACTION

Post by jcats »

Your awesome thank you!
jcats
Junior Member
Posts: 29
Joined: 03 Jan 2015, 14:36

Re: LF_SCRIPT_ACTION

Post by jcats »

Would you be able to provide a template for RT_ACTION as well like below?

ForumAdmin wrote:You have to use BASH programming to store the values passed to the script. BASH stores command line arguments passed to it in $1, $2, $3 etc, so:

Code: Select all

#!/bin/bash
HOSTNAME=`hostname`
SPATH=$1
COUNT=$2
SAMPLE=$3
SCRIPTS=$4

# email subject
SUBJECT="$HOSTNAME - Possible Spam Script"

# Email To
EMAIL="email"

# Email text/message
# EMAILMESSAGE="/tmp/emailmessage.txt"
EMAILMESSAGE="TEST"
echo -e "A script in $SPATH has sent at least $COUNT emails.\n\nHere is a sample from the exim log:\n$SAMPLE\n\nHere are some of the likely scripts:\n$SCRIPTS\n"> $EMAILMESSAGE

# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
Post Reply