LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-31-2016, 05:12 AM   #1
jazzc
LQ Newbie
 
Registered: Aug 2016
Posts: 4

Rep: Reputation: Disabled
compare the parameter in sh


I have installed arpalert in Ubuntu and would like to send an email when there is a new device in the network, but the script does not work if I put the if statement there?

#!/bin/sh

#
# Arguments sent by ArpAlert are :
# 1 : MAC Address
# 2 : IP Address
# 3 : supp (used with unathrq alert)
# 4 : Type of alert (cf arpalert.conf)
#

# Intruder MAC address
intruder_MAC=$1

# Intruder IP address
intruder_IP=$2

# Alert Type
intruder_Detected_on=$4

# Ethernet Vendor
eth_vendor=$6

# Alert Type
alert_type=$5

# Mail recipient
mail_To="JazzC <jazz.c@abc.com>"

# Subject
mail_Subject="[Warning] New Device Detected [Warning]"

if $alert_type == "3"; then

# Body and send mail
cat << EOF | mail -s "$mail_Subject" $mail_To
/!\ New Device Detected /!\\

Intrusion time stamp : $(date)

Intruder Ip Address : $intruder_IP
Intruder MAC Address : $intruder_MAC

Ethernet Vendor: $eth_vendor
Detected on : $intruder_Detected_on
# Type of alert : $alert_type
EOF
fi
 
Old 08-31-2016, 06:37 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Code:
if [ $alert_type -eq 3 ]; then
see man sh, and look for [ expression ], or man [
 
Old 08-31-2016, 08:24 PM   #3
jazzc
LQ Newbie
 
Registered: Aug 2016
Posts: 4

Original Poster
Rep: Reputation: Disabled
The coding will send me an email alert if there is a device detected in the network. However, there will be too many email alerts to me, so I would like to filter if the type of alert is equal 3, other than that system will not send me an email and that's why I put the following "if $alert_type == "3"; then fi" coding there. But the coding still not working even I modified it with "if [ $alert_type -eq 3 ]; then".....

Regards

Jazz

Last edited by jazzc; 08-31-2016 at 08:26 PM.
 
Old 09-01-2016, 02:26 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
insert set -x at the beginning of your script and you will see what's happening. (that will not solve anything just will print a lot of information - which will help you to solve this issue)
 
1 members found this post helpful.
Old 09-02-2016, 06:15 AM   #5
gda
Member
 
Registered: Oct 2015
Posts: 130

Rep: Reputation: 27
Quote:
Originally Posted by jazzc
But the coding still not working even I modified it with "if [ $alert_type -eq 3 ]; then".....
Are you sure you are passing to your script as fifth argument ($5) a numeric value while testing?
 
1 members found this post helpful.
Old 09-02-2016, 09:49 AM   #6
jazzc
LQ Newbie
 
Registered: Aug 2016
Posts: 4

Original Poster
Rep: Reputation: Disabled
The problem has been fixed with the coding "set -x" to debug the scripts, yes the argument of $5 is string instead, thank you very much......
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to compare a list of files in two directories: compare content and print size Batistuta_g_2000 Linux - Newbie 9 03-24-2013 07:05 AM
in with a parameter? jncunliffe Linux - Newbie 6 01-06-2011 04:23 PM
shell getopts: opt w/ optional parameter is taking next opt as its parameter! GrapefruiTgirl Programming 22 10-27-2010 06:00 AM
linux bash - how to use a dynamic parameter in shell parameter expansion expression nickleus Linux - General 2 08-21-2006 04:54 AM
Which parameter to use...? FrogGuy Linux - Hardware 2 11-19-2005 08:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 09:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration