~ubuntu-branches/ubuntu/precise/byobu/precise

« back to all changes in this revision

Viewing changes to bin/uptime

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-05-07 00:54:43 UTC
  • Revision ID: james.westby@ubuntu.com-20090507005443-6ryuqfkl4vphssnw
Tags: upstream-2.1
Import upstream version 2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh -e
 
2
#
 
3
#  uptime: condensed uptime of the machine
 
4
#  Copyright (C) 2009 Raphaël Pinson.
 
5
#  Copyright (C) 2009 Canonical Ltd.
 
6
#
 
7
#  Authors: Raphaël Pinson <raphink@ubuntu.com>
 
8
#           Dustin Kirkland <kirkland@canonical.com>
 
9
#
 
10
#  This program is free software: you can redistribute it and/or modify
 
11
#  it under the terms of the GNU General Public License as published by
 
12
#  the Free Software Foundation, version 3 of the License.
 
13
#
 
14
#  This program is distributed in the hope that it will be useful,
 
15
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
#  GNU General Public License for more details.
 
18
#
 
19
#  You should have received a copy of the GNU General Public License
 
20
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
#
 
22
 
 
23
if [ "$1" = "--detail" ]; then
 
24
        uptime
 
25
        exit 0
 
26
fi
 
27
 
 
28
u=$(sed "s/\..*$//" /proc/uptime)
 
29
printf "\005{= wb}"
 
30
if [ "$u" -gt 86400 ]; then
 
31
        echo "$u" | awk '{printf "%dd%dh", $1 / 86400, ($1 % 86400)/3600 }'
 
32
elif [ "$u" -gt 3600 ]; then
 
33
        echo "$u" | awk '{printf "%dh%dm", $1 / 3600, ($1 % 3600 )/60}'
 
34
elif [ "$u" -gt 60 ]; then
 
35
        echo "$u" | awk '{printf "%dm", $1 / 60 }'
 
36
else
 
37
        printf "%ds" "$u"
 
38
fi
 
39
printf "\005{-} "