uptime 1.55 KB
Newer Older
İsmail Dönmez's avatar
   
İsmail Dönmez committed
1
#!/usr/bin/env perl
2
3

# Uptime script for Konversation
4
# SPDX-FileCopyrightText: Magnus Romnes <gromnes@online.no>
5
6
7
8
9
10
# 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;
11
12
13
14
15
16
17
18
19

$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 {
İsmail Dönmez's avatar
   
İsmail Dönmez committed
20
	$UPTIME = `cat /proc/uptime`;
21
	if (not $UPTIME) {
Wouter Becq's avatar
Wouter Becq committed
22
		exec 'qdbus', 'org.kde.konversation', '/irc', 'info', 'Could not read uptime. Check that /proc/uptime exists.';
23
24
	}
	@uparray = split(/\./, $UPTIME);
İsmail Dönmez's avatar
İsmail Dönmez committed
25
    $seconds = $uparray[0];
26
27
28
29
}

if($seconds >= 86400)
{
İsmail Dönmez's avatar
İsmail Dönmez committed
30
31
	$days = int($seconds/86400);
	$seconds = $seconds-($days*86400);
32
33
34
}
if($seconds >= 3600)
{
İsmail Dönmez's avatar
İsmail Dönmez committed
35
36
	$hours = int($seconds/3600);
	$seconds = $seconds-($hours*3600);
37
38
39
}
if($seconds > 60)
{
İsmail Dönmez's avatar
İsmail Dönmez committed
40
	$minutes = int($seconds/60);
41
42
} else {
	$minutes = 0
43
44
}
if( $days && $hours ) {
Wouter Becq's avatar
Wouter Becq committed
45
	exec 'qdbus', 'org.kde.konversation', '/irc', 'say', $SERVER, $TARGET, "Uptime: $days days, $hours hours and $minutes minutes";
46
47
}
elsif( !$days && $hours ) {
Wouter Becq's avatar
Wouter Becq committed
48
	exec 'qdbus', 'org.kde.konversation', '/irc', 'say', $SERVER, $TARGET, "Uptime: $hours hours and $minutes minutes";
49
50
}
elsif( $days && !$hours ) {
Wouter Becq's avatar
Wouter Becq committed
51
	exec 'qdbus', 'org.kde.konversation', '/irc', 'say', $SERVER, $TARGET, "Uptime: $days days and $minutes minutes";
İsmail Dönmez's avatar
İsmail Dönmez committed
52
}
53
elsif( !$days && !$hours ) {
Wouter Becq's avatar
Wouter Becq committed
54
	exec 'qdbus', 'org.kde.konversation', '/irc', 'say', $SERVER, $TARGET, "Uptime: $minutes minutes";
İsmail Dönmez's avatar
İsmail Dönmez committed
55
}
56