File: uptime

package info (click to toggle)
konversation 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 17,080 kB
  • ctags: 4,900
  • sloc: cpp: 45,134; perl: 475; python: 397; sh: 211; makefile: 9
file content (54 lines) | stat: -rwxr-xr-x 1,548 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env perl

# Uptime script for Konversation
# made by Magnus Romnes (gromnes@online.no)
# The script might be uncompatible with other unix variants than linux.
# only tested on Debian GNU/Linux Sid
# use the code for whatever you wish :-)

$SERVER = shift;
$TARGET = shift;

$PLATFORM = `uname -s`;
chomp($PLATFORM);
if($PLATFORM eq "FreeBSD") {
	$BOOTTIME = `sysctl kern.boottime`;
	$BOOTTIME =~ s/.* sec = ([0-9]+).*/\1/;
	$TIMENOW = `date +%s`;
	$seconds = $TIMENOW - $BOOTTIME;
} else {
	$UPTIME = `cat /proc/uptime`;
	if (not $UPTIME) {
		exec 'qdbus', 'org.kde.konversation', '/irc', 'info', 'Could not read uptime. Check that /proc/uptime exists.';
	}
	@uparray = split(/\./, $UPTIME);
    $seconds = $uparray[0];
}

if($seconds >= 86400)
{
	$days = int($seconds/86400);
	$seconds = $seconds-($days*86400);
}
if($seconds >= 3600)
{
	$hours = int($seconds/3600);
	$seconds = $seconds-($hours*3600);
}
if($seconds > 60)
{
	$minutes = int($seconds/60);
}
if( $days && $hours ) {
	exec 'qdbus', 'org.kde.konversation', '/irc', 'say', $SERVER, $TARGET, "Uptime: $days days, $hours hours and $minutes minutes";
}
elsif( !$days && $hours ) {
	exec 'qdbus', 'org.kde.konversation', '/irc', 'say', $SERVER, $TARGET, "Uptime: $hours hours and $minutes minutes";
}
elsif( $days && !$hours ) {
	exec 'qdbus', 'org.kde.konversation', '/irc', 'say', $SERVER, $TARGET, "Uptime: $days days and $minutes minutes";
}
elsif( !$days && !$hours ) {
	exec 'qdbus', 'org.kde.konversation', '/irc', 'say', $SERVER, $TARGET, "Uptime: $minutes minutes";
}