LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-24-2009, 05:12 AM   #1
Lordmonkey
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Rep: Reputation: 0
How to pass commands to asterisk CLI via bash script?


Quick question: I have a bash script that I want to use to connect to and set up asterisk, pass some commands to it via the atserisk CLI (reloading config files, etc...) then leave the asterisk CLI open in the terminal. I've written a script that can connect to asterisk but I don't know how to pass commands to the asterisk CLI via bash:

Code:
#! /bin/bash
sudo asterisk -rv
I tried using the -x option but it seemed to just quit asterisk:

Code:
#! /bin/bash
sudo asterisk -rvx "sip reload"
Can anyone help?
 
Old 03-24-2009, 07:12 AM   #2
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: always back to Fedora
Posts: 241

Rep: Reputation: 50
Do a "man bash" and have a look at the ARGUMENTS section. You will find that anything on the command line is "set" to 0, 1, 2, 3 up to 9 as an argument to the command. For example, if you had a script called my-script, you could give the script parameters by :-

$ my-script p1 p2 p3 p4

and within your script, you could get the values for p1 p2 p3 and p4 via $p1 $p2 $p3 and $p4.
BTW $0 is set to my-script.
 
Old 03-24-2009, 07:31 AM   #3
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,230

Rep: Reputation: 132Reputation: 132
Quote:
Originally Posted by Lordmonkey View Post
I tried using the -x option but it seemed to just quit asterisk:

Code:
#! /bin/bash
sudo asterisk -rvx "sip reload"
Can anyone help?
Did you mean its quite the asterisk service? No...

"x" option will help you to execute asterisk CLI commands and after completion of command execution it will terminate asterisk CLI, check the "x" in asterisk manpage for more information.

To pass the arguments to your script
#!/bin/bash
asterisk -rx $1

Last edited by kirukan; 03-24-2009 at 07:36 AM.
 
Old 03-24-2009, 08:59 AM   #4
Lordmonkey
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Smile

Quote:
Originally Posted by kirukan View Post
"x" option will help you to execute asterisk CLI commands and after completion of command execution it will terminate asterisk CLI, check the "x" in asterisk manpage for more information
Yep, just checked that page. All I had to do afterwards was get back in to the asterisk CLI:

Code:
#! /bin/bash
sudo /etc/init.d/dhcp3-server restart
sudo asterisk -rx "sip reload"
sudo asterisk -rx "dialplan reload"
sudo asterisk -rx "sip show peers"
sudo asterisk -r
Thanks for your help

Last edited by Lordmonkey; 03-24-2009 at 09:01 AM.
 
  


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] pass password in bash script to SSH vikas027 Programming 4 01-20-2012 03:09 PM
How to pass a c variable to a bash script? daYz Programming 3 09-28-2007 08:30 AM
how to pass a keystroke to a bash script? minike Programming 5 01-21-2007 11:42 AM
Bash script - how to tell if in GUI or CLI? dive Programming 2 11-19-2005 02:12 AM
commands behind a bash here script onurbi Linux - Software 3 11-14-2003 07:38 AM


All times are GMT -5. The time now is 08:18 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