ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi,
I'm a newbie on bash programing, I would like to ask how to compute the time on my asterisk cdr. WHat i would like to do is to compute the total minutes of all answered calls. Actually, i already done that part but what I need is to add or round off the time used to nearest minute. Let's say I a client uses 123 seconds(this is the standard format of asterisk cdr) and I wanted to round this of to nearest minute. If I compute this to minutes, this would be 2 minutes and 3 seconds. What I wanted to do is convert the remaining 3 seconds to minutes or round it off to nearest minutes and that would give me 3 minutes. I'm not sure how to do this. please help me
If I compute this to minutes, this would be 2 minutes and 3 seconds. What I wanted to do is convert the remaining 3 seconds to minutes or round it off to nearest minutes and that would give me 3 minutes.
I hope this isn't a billing system: where I come from 2 minutes and 3 seconds rounds down to 2 minutes, not up to 3 minutes. (Do you work for a legal firm, by any chance?)
Hi,
Nope this is not a billing system.I'm working as a sysad here in Manila. I'm just using this one to match or compare it with our termination partner. My boss wanted to have a email notification of the total minutes that we have used. Our termination partners is billing us on this manner. So i would like to have the same format to compare it with our partner. I hope you could help with this.thanks
Hi Jan61,
Thank you very much. Can I also ask if I can use this with to the cdr file of answer.Usually I a line per line calls which means these are total seconds per calls.
while read sec; do
# do the calculating stuff - e. g.
echo $(($sec / 60))
done <cdr.txt >out.txt
# or
for sec in `cat cdr.txt`; do
...
done >out.txt
To calculate a summary:
Code:
sum=0
while read sec; do
# do the calculating stuff - e. g.
sum=$(($sum + $sec / 60))
done <cdr.txt
echo $sum
# or
for sec in `cat cdr.txt`; do
...
done
echo $sum
Hi
First of all I wanted to thank you for helping me out. I have made the script working but there is one problem. I've tried to redirect the result in to a file but the only thing that was being printed on the file was the last line. I wanted to get all the lines or minutes in evry line to another file. Below is my simple script. When I tried the echo command, it was successful, i was able to retrieved 5 lines of the t3.txt(I have 5 lines that was in seconds and converted to minutes using this script). But when I tried using the printf the result was that the last entry of thiis result was printed into file.
#!/bin/bash
seconds=0
for i in `cat t3.txt`;
do
seconds=$((i + seconds / 60 ))
minutes=$(( seconds / 60 + 1))
seconds=$(( seconds % 60 ))
echo "$minutes"
using printf you must keep in mind, that you have to add a "\n" to your format string, printf does not add a newline per default (echo does that). How do you redirect your output? If you do it in the echo or printf line, you must use ">>file" (append), otherwise every new loop will overwrite the file.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.