File: rem_temp

package info (click to toggle)
digitemp 3.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 828 kB
  • sloc: ansic: 7,254; perl: 644; makefile: 118; python: 67; sh: 39; sql: 11
file content (154 lines) | stat: -rwxr-xr-x 4,244 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/perl -w
#
# DigiTemp remote system update script
# Copyright 1997-2001 by Brian C. Lane <bcl@brianlane.com> www.brianlane.com
# All Rights Reserved
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
#

#
# Read the temperature logfile, write it to an include file for the webpage,
# then ftp the files to the destination server.
#
# The following perl extensions are required :
# libnet package from http://www.perl.com/CPAN-local/modules/by-module/Net/
#   I used libnet-1.0506.tar.gz
#
# Data-Dumper package from: CPAN/modules/by-module/Data/Data-Dumper-x.x.tar.gz
#   I used Data-Dumper-2.07.tar.gz

#
# Sensor #0 is the Window
# Sensor #1 is the inside of the Linux box
#
# Dec 18 21:46:47  Sensor 0 C: 8.81 F: 47.86
# Dec 18 21:46:47  Sensor 1 C: 26.41 F: 79.54
#
use Net::FTP;

# Include file for the webpage (included from the main page)
$inc_file = "/tmp/temp.inc";

# Temperature logfile updated by seperate DigiTemp daemon
$log_file = "/var/log/temperature";

# Script to run to bring up the link
# I use diald, you probably use something different.
$ip_up = "/usr/sbin/dialdc up";

# Your username for the destination ftp server
$ftp_user = "username";

# Your password for the destination ftp server
$ftp_pass = "password";

# Destination ftp server's address
$ftp_host = "ftp.host.com";

# Directory on the destination ftp server to place $inc_file
$dest_dir = "/home/login/public_html";

# Create a new include file, overwrite the old one
open( INCFILE, ">$inc_file") || die "Can't open $inc_file";

# Include a break line and center the text
print INCFILE "<HR>\n";
print INCFILE "<CENTER>\n";

# You should customize this!
print INCFILE "The current temperatures are<P>\n";

# Run tail -2 /var/log/temperature and parse the output
# The -2 is the number of sensors you have (last 2 lines from logfile)
open( TEMPLOG, "tail -2 $log_file |") || die "Can't fork: $!";

# Parse the output of the tail program
while( <TEMPLOG> )
{
  # Get the time and date, sensor number, temperature in c and f
  ($month,$day,$time,$d1,$sensor,$d1,$centigrade,$d1,$fahrenheight) = split( " ", $_ );

  # Print some custom messages for the sensors
  # The \xB0 is supposed to be a degree symbol. This works on some systems
  # but not on others.
  if( $sensor eq '0' )
  {
    print INCFILE "The modems are at $fahrenheight\xB0 F ($centigrade\xB0 C)<BR>\n";
  }

  if( $sensor eq '1' )
  {
    print INCFILE "The room is a ";

    if( $fahrenheight < 40.0 )
    {
      print INCFILE "freezing";
    }

    if( $fahrenheight >= 40.0 and $fahrenheight < 70.0 )
    {
      print INCFILE "chilly";
    }

    if( $fahrenheight >= 70.0 and $fahrenheight < 80.0 )
    {
      print INCFILE "comfortable";
    }

    if( $fahrenheight >= 80.0 and $fahrenheight < 100.0 )
    {
      print INCFILE "balmy";
    }

    if( $fahrenheight >= 100.0 )
    {
      print INCFILE "blistering";
    }

    print INCFILE " $fahrenheight\xB0 F ($centigrade\xB0 C)<BR>\n";
  }
}

print INCFILE "Last updated: $month $day $time<BR>\n";

# Blantant advertisement <G>
print INCFILE "<PRE>These temperatures generated with ";
print INCFILE "<A HREF=\"http://www.brianlane.com\">";
print INCFILE "DigiTemp</PRE><BR>\n";
print INCFILE "</CENTER>\n";

close( TEMPLOG );
close( INCFILE );

# Send it to the server
# Fire up the link
system $ip_up;

# Wait a little bit to let ppp0 come up
sleep 60;

# Send it to the server
$ftp = Net::FTP->new($ftp_host);
$ftp->login($ftp_user,$ftp_pass);
$ftp->cwd($dest_dir);
$ftp->binary();
$ftp->put($inc_file);
$ftp->quit;

# Shut down the link
system $ip_down;

# done!