LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


LinkBack Search this Thread
Old 05-10-2010, 04:17 AM   #1
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)

# capture service

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

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

# 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/

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

exit 0

The first positional var is for setting a name for the capture like this:
/root/ myCap
My problem is when I start the new service with:
/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
service myservice start|stop
Is that possible?

I read that I must use chkconfig.

Thanks in advantage.
Old 05-10-2010, 05:03 AM   #2
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.

/root/ #path to the original script
$(/root/ "$1")& #path to the original script


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -5. The time now is 02:26 PM.

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