LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 12-06-2006, 02:00 PM   #1
mexxe
LQ Newbie
 
Registered: Dec 2006
Posts: 2

Rep: Reputation: 0
Convert seconds to minues in a script


Something like this
#!/bin/bash
SECONDS=0
doing some backup
echo $SECONDS
and now I wont to send it like an email but in minutes.
any idea's

/Mexxe
 
Old 12-06-2006, 02:18 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Quote:
Originally Posted by mexxe
and now I wont to send it like an email but in minutes.
What do you mean by that? You want to wait some minutes and then send an email? You want to send an email expressing the number of $SECONDS in minutes?

Is it the sending of an email which is the part you don't understand, or how to get a string containing a human-readable number of minutes which is problematic, or both?

You can mail using the command line mail program, or mailx. See the manual page for syntax, it's pretty straight forward, but here's an example:
Code:
echo "You message body here" |mailx -s "subject line" recipient@address.here
To get the number of minutes, divide by 60

If you just want an integer number of minutes, you could use this:
Code:
MINUTES=$(( $SECONDS / 60 ))
However, this will round down. So you might want to append the number of SECONDS mod 60. printf will prevent the seconds not having a leading 0 when you have less than 10 seconds.
Code:
MINUTES=$( printf "%d:%02d\n" $(($SECONDS / 60)) $(( $SECONDS % 60)) )
 
Old 12-06-2006, 04:36 PM   #3
mexxe
LQ Newbie
 
Registered: Dec 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks it worked great =)
 
  


Reply



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
convert total no of seconds in the format hour minutes and seconds suchi_s Programming 15 03-15-2011 11:34 AM
m4a convert - rename script webvolutionary Linux - General 1 11-21-2006 07:49 AM
Convert TERM script to Minicom 2.1 oharek Linux - Software 0 12-19-2005 08:22 AM
Convert a Bash script to C Linh Programming 5 04-25-2004 12:51 PM
script to convert system to Debian cloids Debian 2 01-15-2004 01:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:18 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration