Sponsored Content
Top Forums Shell Programming and Scripting INIT Script Getting Executed Twice? Post 302904800 by mrm5102 on Friday 6th of June 2014 04:34:40 PM
Old 06-06-2014
INIT Script Getting Executed Twice?

Hello All,

I copied and pasted the "/etc/init.d/skeleton" file to a new one so I could create my own init script for a program.
Basically the ONLY edit I made to the skeleton "template" so far was to search and replace "FOO" with "snort".

*NOTE: I know there are a bunch of snort init scripts out there, but they weren't working the way I wanted, so I wanted to play around a bit with the init script because I had just recently found out what the 'skeleton' file was for...

But anyway, when I run the script with 'status' as the only argument to the script it seems to execute the init script twice. i.e. It prints out the status twice to the screen...

Like this:
Code:
# /etc/init.d/snort_skeleton status
Checking for service snort                            running
Checking for service snort                            running

And if I change the line in the script for status from:
Code:
/sbin/checkproc $snort_BIN

To This:
Code:
OUTPUT=$(/sbin/checkproc $snort_BIN)
echo "OUTPUT='$OUTPUT'"

I get this as the output, which is telling me it's executing twice for some reason...
Code:
Checking for service snort OUTPUT = ' '

                                                 running
Checking for service snort OUTPUT = ' '

                                                 running

Any idea why this would execute twice? Below is the skeleton file, I removed MOST of the comment lines because there are a TON...
Filename: snort_skeleton
Command--> /etc/init.d/snort_skeleton status
Code:
#!/bin/sh
# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
snort_BIN=/usr/sbin/snort
test -x $snort_BIN || { echo "$snort_BIN not installed";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 5; fi; }

# Check for existence of needed config file and read it
snort_CONFIG=/etc/sysconfig/snort
test -r $snort_CONFIG || { echo "$snort_CONFIG not existing";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 6; fi; }

# Read config   
. $snort_CONFIG

. /etc/rc.status

# Reset status of this service
rc_reset


case "$1" in
    start)
        echo -n "Starting snort "
        /sbin/startproc $snort_BIN

        # Remember status and be verbose
        rc_status -v
    ;;
    stop)
        echo -n "Shutting down snort "
        /sbin/killproc $snort_BIN

        # Remember status and be verbose
        rc_status -v
    ;;
    try-restart|condrestart)
        if test "$1" = "condrestart"; then
        echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
        fi
        $0 status
        if test $? = 0; then
        $0 restart
        else
        rc_reset    # Not running is not a failure.
        fi
        # Remember status and be quiet
        rc_status
    ;;
    restart)
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
    ;;
    force-reload)
        echo -n "Reload service snort "
        ## if it supports it:
        /sbin/killproc -HUP $snort_BIN
        #touch /var/run/snort.pid
        rc_status -v

        ## Otherwise:
        #$0 try-restart
        #rc_status
    ;;
    reload)
        # If it supports signaling:
        echo -n "Reload service snort "
        /sbin/killproc -HUP $snort_BIN
        #touch /var/run/snort.pid
        rc_status -v
       
        ## Otherwise if it does not support reload:
        #rc_failed 3
        #rc_status -v
    ;;
    status)
        echo -n "Checking for service snort "

        /sbin/checkproc $snort_BIN

        rc_status -v
    ;;
    probe)
        test /etc/snort/snort.conf -nt /var/run/snort.pid && echo reload
    ;;
    *)
        echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
        exit 1
    ;;
esac
rc_exit

If anyone has ANY ideas why this would be happening please feel free...
Any thoughts or suggestions would be greatly appreciated.

Thanks in Advance,
Matt


---------------------------------------------------------------------------------------------------------------------------------------------------
UPDATE:
I added a simple echo statement to the very start of the script on the 1st line after the shebang line:
echo "FIRST LINE:"

Then, I run the script again manually from the command line, with:
./snort_skeleton status

And the Output is:
Code:
FIRST LINE:
FIRST LINE:
Checking for service snort                                      running
Checking for service snort                                      running

Just thought that was VERY strange... Any ideas??

Thanks Again,
Matt

---------- Post updated at 04:34 PM ---------- Previous update was at 02:24 PM ----------

Sorry, didn't want to just keep Update/Editing my original post, but I just found something else that seems pretty strange...

If I execute the script and I include a 2nd argument on the cli, NO MATTER WHAT THE ARG IS, it only runs once. I can make the
2nd argument be anything. From another init option like, start|stop|restart|etc... to "foo" to a single number, it ONLY runs once... How
strange is that??

Example:
Code:
# ./snort_skeleton status 1
Checking for service snort                                                     running

# ./snort_skeleton status foo
Checking for service snort                                                     running

# ./snort_skeleton status start
Checking for service snort                                                     running

But if I include "status" as the ONLY option I get:
Code:
 # ./snort_skeleton status
Checking for service snort                                                     running
Checking for service snort                                                     running

Thought that could possibly help. I do see in the script they use "$@" but that is the only reference I see to more then just the 1st
CLI Option, *i.e. "$2" is not used in the script anywhere...

Any ideas...?

Thanks in Advance,
Matt

Last edited by mrm5102; 06-06-2014 at 05:14 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Init 6 & Init 0 problem

Hi Expert, I have encountered some problem with my SUN system. Everytime when i issue command #init 6 OR #init 0 it just logout and prompt for login again instead of rebooting the server when run init 6 and system shutdown when run init 0.. I can only reboot the system using reboot ... Was... (6 Replies)
Discussion started by: sc2005
6 Replies

2. Shell Programming and Scripting

How to know who executed a script?

Dear all I would like to capture who executed a script to a script's variable (i.e. testing.sh), so I can save it to a log file. testing.sh #! bin/ksh user=`<< code here >>` // get the info below in RED color <<main logic>> echo "$user execute testing.sh on `date`" >> testing.log ... (2 Replies)
Discussion started by: on9west
2 Replies

3. Linux

How to I change init levels after typing init 1

Dear all, I typed in init 1 on my redhat box as root and according to wikipedia (http://en.wikipedia.org/wiki/Runlevel): 1 Single-User Mode Does not configure network interfaces, start daemons, or allow non-root logins So now I can't connect back to it. How do I change the init back to 3?... (8 Replies)
Discussion started by: z1dane
8 Replies

4. UNIX for Advanced & Expert Users

Problem on init 0, execution is the same with init 6

Hi, I am experiencing a weird thing on my SUNFIRE machine with Solaris 9 OS. When I do init 0 to shutdown the machine to go to ok prompt, what it did was shutdown and reboot like an init 6 command do. I did check the corresponding rc scripts that were involved with init 0 and compared with rc... (2 Replies)
Discussion started by: Yenthanh
2 Replies

5. Red Hat

init-script failing because of /etc/rc.d/init.d/functions

I encountered a problem on one of our database servers. OS: CentOS 5.5 final Kernel: 2.6.18-238.5.1.el5.028stab085.2 (OpenVZ kernel) We wrote some DB-Start/Stop-scripts ("/db2/admin/scripts_dba/start_services.ksh" and ".../stop_services.ksh") to start the database instances. (Database... (1 Reply)
Discussion started by: bakunin
1 Replies

6. AIX

Script not getting executed via cron but executes when executed manually.

Hi Script not getting executed via cron but executes successfully when executed manually. Please assist cbspsap01(appuser) /app/scripts > cat restart.sh #!/bin/ksh cd /app/bin date >>logfile.out echo "Restart has been started....." >>logfile.out date >>logfile.out initfnsw -y restart... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

7. Shell Programming and Scripting

Shell script executed from Informatica ETL tool is spawning 2 processes for one script

Hi, I am having a shell script which has a while loop as shown below. while do sleep 60 done I am executing this script from Informatica ETL tool command task from where we can execute UNIX commands/scripts. When i do that, i am seeing 2 processes getting started for one script... (2 Replies)
Discussion started by: chekusi
2 Replies

8. Shell Programming and Scripting

Start up init d script

Hi All, I'm trying to build a start up script, wud be gr8 if any one can explain what the below field means and how can i check it for my script. DAEMON_PATH="/home/wes/Development/projects/myapp" DAEMON=myapp DAEMONOPTS="-my opts" NAME=myapp DESC="My daemon description"... (4 Replies)
Discussion started by: Karthick N
4 Replies

9. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

10. Linux

Troubleshooting init.d script

This is what I did: 1. I wrote a simple init.d script (myscript.sh) 2. I placed it under /etc/init.d (where many other default scripts already are) 3. Set the perms to 755 4. Run: update-rc.d myscript.sh defaults I can run it perfectly by doing: /etc/init.d/myscript.sh start... (2 Replies)
Discussion started by: rlopes
2 Replies
All times are GMT -4. The time now is 09:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy