LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-10-2010, 05:17 AM   #1
Mortuus
LQ Newbie
 
Registered: Mar 2010
Location: Madrid, Spain
Distribution: Debian Testing
Posts: 21

Rep: Reputation: 0
[Bash] Creating service for a script. Problem with positional vars


Hi all

I wrote a script for capturing port 5060 with tshark.

Well, it's only a line, but I needed to send a positional var, and I couldn't do it with an alias.

Now I need that script to run as a service, so I can start/stop.
(Using CentOS)

Code:
#!/bin/bash
#
# capture service

# Get functions
. /etc/init.d/functions

# start function
start() {
        initlog -c "echo -n Starting service: "
        /root/captura.sh #path to the original script
        # lock file
        touch /var/run/capturar.pid
        success $"Service started!"
        echo
}

# stop function
stop() {
        initlog -c "echo -n Stoping service: "
        #Select processes
        p1=`ps aux | grep captura | cut -c5-14 | sed -n 1p`
        p2=`ps aux | grep captura | cut -c5-14 | sed -n 2p`
        # Kill 'em all!
        kill -9 $p1
        kill -9 $p2
        # remove lock file
        rm -f /var/run/capturar.pid
}

## Main ##
case "$2" in # This is $2 because of the first positional var
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                start
                ;;
        *)
                echo $"Usage: {start|stop|restart}"
                exit 1
esac

exit 0

The first positional var is for setting a name for the capture like this:
Code:
/root/capturar.sh myCap
My problem is when I start the new service with:
Code:
/etc/init.d/capturar myCap start
It really starts, but ignores the first positional var.

How could I write this script for setting a name to the capture?

One more thing, my goal is to start/stop the service with
Code:
service myservice start|stop
Is that possible?

I read that I must use chkconfig.


Thanks in advantage.
 
Old 05-10-2010, 06:03 AM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 248Reputation: 248Reputation: 248
It ignores the first variable because you don't use the first variable anywhere.

change
Code:
/root/captura.sh #path to the original script
to
Code:
$(/root/captura.sh "$1")& #path to the original script
 
  


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
Case statements and vars for bash script geech Programming 1 01-09-2009 05:49 PM
trouble with positional parameter $0 on bash. linux distro: ubuntu breezy linrookie Linux From Scratch 2 05-07-2006 01:22 PM
Restart Service Bash Script XaViaR Linux - General 4 01-05-2006 03:10 AM
problem creating BASH script with files that have whitespace scattaneo Linux - General 2 11-06-2004 06:40 PM
Starting a service in a bash script AMMullan Programming 3 02-19-2004 12:06 PM


All times are GMT -5. The time now is 12:58 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration