Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6004059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:12:34+00:00 2026-05-23T01:12:34+00:00

I was working on a little script that would do some logging for me

  • 0

I was working on a little script that would do some logging for me from an asterisk machine. From the linux (centOS) command line, I can type:

asterisk -rx "transcoder show"

which provides the output I need to log. This output looks like this:

5/5 encoders/decoders of 120 channels are in use.

I wanted to write a line to a log file that would look like this:

YYYY-MM-DD HH-MM-SS     #encoders     #decoders

and then I’d log this every couple of minutes, and I’d have a history of how many channels I was using. So I wrote a little php script:

<?php
exec("asterisk -rx \"transcoder show\" | sed 's|\\([0-9]*\\)\/\\([0-9]*\\).*|\\1:\\2|'",$retval);
$time = date('Y-m-d h:i:s');
$vals = explode(":",$retval[0]);
$encoders = trim($vals[0]);
$decoders = trim($vals[1]);
$logString = "$time\t$encoders\t$decoders\n";
$fh = fopen('/root/script/trans.log','a');
fwrite($fh,$logString);
fclose($fh);
?>

Sorry, the code is a little funky there, theoretically I should have been able to output exactly what I needed from sed, but the code you see there is after I had changed it to try to address the problem you’ll se below. In testing, I found the sed script worked fine from the command line; it output #encoders:#decoders as expected. But, when I ran the php script, it was writing lines like this to the log file:

2011-06-13 10:24:02     ^[[0;37;40m6    6

I can’t figure out where the ^[[0;37;40m is coming from. It’s a color code, I understand, to set the color for displaying the text in the shell, but is that something sed is adding, or is it coming from the original output? How do I get rid of it? If I use an echo statement to print the variables $encoders and $decoders to the command line, there is no special color formatting, nor is there in the output from the original asterisk -rx command.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:12:35+00:00Added an answer on May 23, 2026 at 1:12 am

    It’s not that sed is adding color codes, it’s just that it is passing it through from Asterisk. What you really want to do is receive output from Asterisk that does not have those color codes to begin with.

    The -n command will strip ANSI color support: Asterisk man page

    asterisk -nrx \"transcoder show\"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that appends some rows to a table. One of the
I'm working on a project in C# w/ XNA, and I want to reorganize

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.