How to use the command asterisk (with examples)

How to use the command asterisk (with examples)

The command asterisk is used for managing and running a telephone and exchange (phone) server. It allows users to connect to a running server, execute commands, and manage various aspects of the server. In this article, we will explore several use cases of the asterisk command and provide example code, motivations, explanations, and example outputs for each use case.

Use case 1: Reconnect to a running server, and turn on logging 3 levels of verbosity

Code:

asterisk -r -vvv

Motivation: The motivation behind using this example is to reconnect to a running Asterisk server and enable verbose logging to troubleshoot any issues or monitor the server.

Explanation:

  • asterisk: This is the command itself.
  • -r: This flag reconnects to a running Asterisk server.
  • -vvv: This flag sets the verbosity level to 3, enabling detailed logging.

Example output:

Connected to Asterisk 16.8.0 currently running on server (pid = 1234)
Verbosity is at least 3

Use case 2: Reconnect to a running server, run a single command, and return

Code:

asterisk -r -x "command"

Motivation: This example allows users to quickly execute a single command on a running Asterisk server and get the output without staying connected to the server.

Explanation:

  • asterisk: The command itself.
  • -r: Reconnects to a running Asterisk server.
  • -x "command": Executes the specified command and returns the output.

Example output:

Output of the executed command

Use case 3: Show chan_SIP clients (phones)

Code:

asterisk -r -x "sip show peers"

Motivation: This use case is helpful when you want to view the SIP clients (phones) connected to the Asterisk server.

Explanation:

  • asterisk: The command itself.
  • -r: Reconnects to a running Asterisk server.
  • -x "sip show peers": Executes the command sip show peers to display the list of SIP clients.

Example output:

Name/username             Host      Dyn Forcerport Comedia  ACL Port     Status    Description
1000/1000                 10.0.0.1  D   N  T  5060     OK (5 ms)
1001/1001                 10.0.0.2  D   N  T  5060     OK (5 ms)
2 sip peers [Monitored: 2 online, 0 offline Unmonitored: 0 online, 0 offline]

Use case 4: Show active calls and channels

Code:

asterisk -r -x "core show channels"

Motivation: This example allows you to see the active calls and channels on the Asterisk server, which can help monitor the system’s usage and identify any issues.

Explanation:

  • asterisk: The command itself.
  • -r: Reconnects to a running Asterisk server.
  • -x "core show channels": Executes the command core show channels to display information about active calls and channels.

Example output:

Channel              Location             State   Application(Data)             
PJSIP/1000-00000001  s@default:1          Up      Playback(custom/sound)
PJSIP/1001-00000002  s@default:2          Up      Playback(custom/sound)
2 active channels
2 active calls

Use case 5: Show voicemail mailboxes

Code:

asterisk -r -x "voicemail show users"

Motivation: This use case lets you view the voicemail mailboxes set up on the Asterisk server, providing insights into the configuration and usage of voicemail.

Explanation:

  • asterisk: The command itself.
  • -r: Reconnects to a running Asterisk server.
  • -x "voicemail show users": Executes the command voicemail show users to display the voicemail mailboxes.

Example output:

Context   Extension  Mailbox   Duration  New  Message
default   1000       1000      0         No   No messages
default   1001       1001      0         No   No messages
2 voicemail users configured

Use case 6: Terminate a channel

Code:

asterisk -r -x "hangup request channel_ID"

Motivation: This example allows you to terminate a specific Asterisk channel, which can be useful for troubleshooting or ending a call.

Explanation:

  • asterisk: The command itself.
  • -r: Reconnects to a running Asterisk server.
  • -x "hangup request channel_ID": Executes the command hangup request with the specified channel_ID parameter to terminate a channel.

Example output:

Hangup request successfully sent

Use case 7: Reload chan_SIP configuration

Code:

asterisk -r -x "sip reload"

Motivation: This use case allows you to reload the configuration of the chan_SIP module in Asterisk, which is necessary when making changes to the SIP configuration.

Explanation:

  • asterisk: The command itself.
  • -r: Reconnects to a running Asterisk server.
  • -x "sip reload": Executes the command sip reload to reload the SIP configuration.

Example output:

Module 'chan_sip.so' reloaded successfully.

Conclusion:

In this article, we explored several use cases of the asterisk command, which is used for managing and running an Asterisk telephone and exchange server. Each use case provided example code, motivations, explanations, and example outputs, demonstrating the versatility and functionality of the asterisk command.

Related Posts

How to use the command 'rolldice' (with examples)

How to use the command 'rolldice' (with examples)

The ‘rolldice’ command is used to simulate rolling dice in a virtual environment.

Read More
How to use the command rargs (with examples)

How to use the command rargs (with examples)

The rargs command is a tool that allows you to execute a command for each line of standard input, similar to the xargs command.

Read More
How to use the command tlmgr candidates (with examples)

How to use the command tlmgr candidates (with examples)

The tlmgr candidates command is used to get a list of available candidate repositories from which a TeX Live package can be installed.

Read More