LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-16-2011, 03:36 AM   #1
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Rep: Reputation: 31
segmentation fault in my script


I've got an init.d script which launches multiple instances of a wrapper script, which is linked to a basic TCP port check. Are there any issues with running this many linked processes? I've noticed I get lots of segmentation faults and then the process usually stops after a few hours (sometimes days), is this likely to be a problem with my logic or having this many linked processes? Let me know if you need to see the code(s). I suspect there are multiple calls to the same one liner' and it's causing the seg faults, let me know what you think.

Last edited by genderbender; 02-16-2011 at 03:41 AM.
 
Old 02-16-2011, 03:53 AM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Yes, definitely post the code.
 
Old 02-16-2011, 05:28 AM   #3
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
init.d script:
Code:
NAGIOSDIR=/usr/local/nagios/libexec

start () {
nohup $NAGIOSDIR/check_port_timed -h 10.10.10.10 -p 1 > /dev/null 2>&1 &
nohup $NAGIOSDIR/check_port_timed -h 10.10.10.10 -p 2 > /dev/null 2>&1 &
nohup $NAGIOSDIR/check_port_timed -h 10.10.10.10 -p 3 > /dev/null 2>&1 &
nohup $NAGIOSDIR/check_port_timed -h 10.10.10.10 -p 4 > /dev/null 2>&1 &
nohup $NAGIOSDIR/check_port_timed -h 10.10.10.10 -p 5 > /dev/null 2>&1 &
nohup $NAGIOSDIR/check_port_timed -h 10.10.10.10 -p 6 > /dev/null 2>&1 &
nohup $NAGIOSDIR/check_port_timed -h 10.10.10.10 -p 7 > /dev/null 2>&1 &
nohup $NAGIOSDIR/check_port_timed -h 10.10.10.10 -p 8 > /dev/null 2>&1 &
nohup $NAGIOSDIR/check_port_timed -h 10.10.10.10 -p 9 > /dev/null 2>&1 &
nohup $NAGIOSDIR/check_port_timed -h 10.10.10.10 -p 10 > /dev/null 2>&1 &
nohup $NAGIOSDIR/check_port_timed -h 10.10.10.10 -p 11 > /dev/null 2>&1 &
nohup $NAGIOSDIR/check_port_timed -h 10.10.10.10 -p 12 > /dev/null 2>&1 &
}

stop () {
for i in `ps -ef | grep check_port_timed | awk '{print $2}'`; do kill -9 $i; done;
}

restart () {
stop
start
}

case $1 in
        start)
                start
        ;;
        stop)
                stop
        ;;
        restart)
                restart
        ;;
        *)

        echo $"Usage: $prog {start|stop|restart}"
        exit 0
esac
check-port-timed script:
Code:
#!/bin/bash

30_winks ()
{
sleep 30
check
}

check ()
{
systemstate=`/usr/local/nagios/libexec/check_tcp2 -H $hostname -p $port`
health=`echo $systemstate | grep OK | wc -l`
log=/var/port/$hostname-$port.log
if [ -z "$systemstate" ]; then
        msg="$systemstate"
        current_date=`date '+%b %m %H:%M:%S'`
        echo "$current_date $msg on $hostname." >> $log
        30_winks
elif [ "$health" -lt 1 ]; then
        msg="$systemstate."
        current_date=`date '+%b %m %H:%M:%S'`
        echo "$current_date $msg on $hostname." >> $log
        30_winks
elif [ "$health" -eq 1 ]; then
        msg="$systemstate"
        current_date=`date '+%b %m %H:%M:%S'`
        echo "$current_date $msg on $hostname." >> $log
        30_winks
else
        msg="Unable to check host."
        state=UNKNOWN
        current_date=`date '+%b %m %H:%M:%S'`
        echo "$current_date $msg on $hostname." >> $log
        30_winks
fi
30_winks
}

while getopts "p:h:" option
do
case $option in
p)port=$OPTARG
;;
h)hostname=$OPTARG
;;
*) echo "Syntax is $usage -h <hostname> -p <port>"
exit 1;;
esac
done

if [ -z "$hostname" ]; then
        echo "-h) IP address required."
        exit 1
elif [ -p "$port" ]; then
        echo "-p) port required."
        exit 1
else
        check
fi
the check_tcp2 code looks like it's wrote in C, I can't cat it.
 
Old 02-16-2011, 10:50 AM   #4
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
What kind of actual errors are you getting? If you are having trouble trying to catch them, try using gdb; it just may be coming from check_tcp2.
 
Old 02-16-2011, 11:32 AM   #5
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
Lots (and lots) of this:

Code:
check_port_time[6019]: segfault at 00007fffb553fe14 rip 00000000004214e0 rsp 00007fffb553fe00 error 6
 
Old 02-16-2011, 11:37 AM   #6
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Run
Code:
systemstate=`/usr/local/nagios/libexec/check_tcp2 -H $hostname -p $port`
by itself with the proper arguments and see what it gives you back in output. It may be dropping the error.
 
Old 02-17-2011, 03:41 AM   #7
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
Code:
>systemstate=`/usr/local/nagios/libexec/check_tcp2 -H $hostname -p $port`
>echo $systemstate
<CRITICAL - Generic check_tcp called with unknown service Usage: check_tcp2 -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>] [-e <expect string>] [-q <quit string>][-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j] [-D <days to cert expiry>] [-S <use SSL>] [-E]
Now with proper flags:

Code:
<CRITICAL - Socket timeout after 10 seconds
 
  


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
Segmentation fault AndeAnderson Linux - Laptop and Netbook 2 03-21-2007 08:10 AM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
Segmentation fault when mounting from a bash script crc294 Linux - Hardware 3 06-25-2004 04:00 PM
Executing chat script aolnet.scm Segmentation fault degraffenried13 Linux - Software 0 11-16-2003 08:05 PM
segmentation fault... perdesiz Linux - Software 1 08-18-2003 01:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:14 AM.

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