Mittwoch, 4. Februar 2009
Check network connection
#!/bin/bash
x=`ping -c1 google.com 2>&1 | grep unknown`
if [ ! "$x" = "" ]; then
echo "It's down!! Attempting to restart."
/etc/init.d/networking restart
echo "restarted gurke" | mail -s gurke_restart test@hotmail.com
fi
- chmod 777 check_network.sh
- add it to crontab so it checks it for every hour or so..
Mittwoch, 2. Juli 2008
webgui status rtorrent over cgi
http://www.g-loaded.eu/2007/06/23/rtorstat-a-simple-rtorrent-status-web-page-generator/
1) to get it run
edit rtorstat.py and get rid of this:
Requirement
try:
from bencode import bdecode
except ImportError:
try:
from BitTorrent.bencode import bdecode
except ImportError:
sys.stderr.write("%s: ERROR: Missing dependency\nbencode.py was not found in current directory or in local BitTorrent Client (Mainline) installation.\n" % sys.argv[0])
sys.stderr.flush()
sys.exit(1)
download somewhere from the web "bencode.py" file and JUST paste it where the previouys lines above were....
2) access over the your installation
place 3 files in your cgi-bin (/usr/lib/cgi-bin/) : rtorstat.py, rtorstat.cgi and bencode.py.
Now, you can visit the web page http://yourdomain.example.org/cgi-bin/rtorstat.cgi
Samstag, 26. Januar 2008
External Hard Drive
get more gigs
you can not life these days with only 20 gig, so: configuring the External Hard Drive, as recommended in herea)add in /etc/fstab
/dev/sdb1 pladde/ ntfs-3g defaults,force 0 0
b) After the installation is done, you can optionally add an external hard drive to make it easier to move your data. We'll be using a service called "autofs" to automatically detect your hard drive and make it ready to share on the network each time you plug it in. To install autofs, use this command:
sudo apt-get install autofs
Once that finishes, you'll want to connect your external hard drive and find out what device Ubuntu assigns it. After plugging in the hard drive wait a few seconds and then enter this command:
dmesg | tail
You should see something very similar to this:
[47820.164000] sdb: Write Protect is off
[47820.164000] sdb: Mode Sense: 03 00 00 00
[47820.164000] sdb: assuming drive cache: write through
[47820.164000] SCSI device sdb: 398297088 512-byte hdwr sectors (203928 MB)
[47820.168000] sdb: Write Protect is off
[47820.168000] sdb: Mode Sense: 03 00 00 00
[47820.168000] sdb: assuming drive cache: write through
[47820.168000] sdb: sdb1
[47820.184000] sd 4:0:0:0: Attached scsi disk sdb
[47820.184000] sd 4:0:0:0: Attached scsi generic sg2 type 0
The line "[47820.168000] sdb: sdb1" is what you'll want to pay attention to. This tells us that Ubuntu is assigning the device to "sdb", and it's partition is labeled as "sdb1". "1" being the first and only partition on the disk. Next, we'll what to find out what kind of partition is on the disk. Enter this into the console:
sudo fdisk -l /dev/sdb
The "System" column will display what kind of partition it is. Take note on what type of partition it is for the following instructions. If it's "HPFS/NTFS", you'll want to use the "ntfs-3g" driver. If it contains "FAT", you'll use the "vfat" driver. Finally, if it's "Linux", you can just use the "auto" driver. Note, if it is a NTFS partition, you will have to manually install the new NTFS read/write drivers by using:
sudo apt-get install ntfs-3g
Next, we'll want to add this information to the autofs service. Use to following command to edit to autofs master configuration file:
sudo nano /etc/auto.master
Note: You can replace "nano" with your preferred text editor. To save a file in nano, use the keyboard shortcut Ctrl+O. To exit, press Ctrl+X.
Now, find the line containing:
#/misc /etc/auto.misc
Change it to:
/misc /etc/auto.misc --timeout=60
Save it and edit the autofs "miscellaneous" configuration file next by entering this command:
sudo nano /etc/auto.misc
Add this to the bottom of the file:
external -fstype=ntfs-3g :/dev/sdb1
Remember to replace "ntfs-3g" with the type of driver you found earlier in this section. Note, if you are using "ntfs-3g", you might want to append ",force" , making it "-fstype=ntfs-3g,force". This makes it easier to use uncleanly unmounted drives. This maybe a little risky, but it makes it so much easier to troubleshoot.
Finally, restart the autofs service:
sudo /etc/init.d/autofs restart
Now, every time anything tries to find files in the "/misc/external" directory, Ubuntu will attempt to automatically mount that drive to be used.
accessing mybox from everywhere
Add DynDNS to your router (if your router does not support DynDNS, good luck wit the http://en.wikipedia.org/wiki/DD-WRT fimrware) so you can access your network from outside, even if your provider changes the IP.
A big brother is watching you webcam server
To make your box squeak when there is an alarm event:
sudo apt-get install mpg321 alsamixer
Adjust volume: alsamixer
To trigger the alarm on the very moment of the event based on this how to
Install perl
Create perl script to monitor DB (alarm_loop.pl)
#!/usr/bin/perl -w
use strict;
use ZoneMinder;
$| = 1;
zmDbgInit( "myscript", level=>0, to_log=>0, to_syslog=>0, to_term=>1 );
my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS );
my $sql = "select M.*, max(E.Id) as LastEventId from Monitors as M left join Events as E on M.Id = E.MonitorId where M.Function != 'None' group by (M.Id)";
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or die( "Can't execute '$sql': ".$sth->errstr() );
my @monitors;
while ( my $monitor = $sth->fetchrow_hashref() )
{
push( @monitors, $monitor );
}
$sql = "select * from Events where Id = ?";
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
while( 1 )
{
foreach my $monitor ( @monitors )
{
next if ( !zmShmVerify( $monitor ) );
if ( my $last_event_id = zmHasAlarmed( $monitor, $monitor->{LastEventId} ) )
{
$monitor->{LastEventId} = $last_event_id;
# print( "Monitor ".$monitor->{Name}." has alarmed\n" );
$res = $sth->execute( $last_event_id ) or die( "Can't execute '$sql': ".$sth->errstr() );
my $event = $sth->fetchrow_hashref();
if ( $event->{Id} ) {
# print( "EventID= ".$event->{Id} );
my $command = "./alarm1.sh"
# ." --monitor=" .$monitor->{Id}
." --event=" .$event->{Id}
." --starttime=\"" .$event->{StartTime} ."\"";
my $output = qx( $command );
my $status = $? >> 8;
# print ("Output(" .$status ."):" .$output);
# Print output if required
# Check status if required
#
# Do your stuff here
#
}
}
}
sleep( 1 );
}
Create bash script with link to alrm file (alarm1.sh)
#!/bin/bash
echo "1=$1 2=$2 3=$3 4=$4"
mpg123 /home/boxuser/www/wav/alarm.mp3
Run perl script:
sudo ./alarm_loop.pl\
Activate 640×480 streamingYou should be able to use a similar procedure with other distributions to modify the shared memory pool without kernel recompilations though in some cases this may be necessary. Note, this error also sometimes occurs if you have an old shared memory segment lying around from a previous run that is too small. Use the ipcs and ipcrm system commands to check and remove it if necessary.'"
You can often find out how much shared memory is available by typing the following :-
cat /proc/sys/kernel/shmall
and the most you can allocate in one go :-
cat /proc/sys/kernel/shmmax
To change these values type (for example) :-
echo 134217728 >/proc/sys/kernel/shmall
echo 134217728 >/proc/sys/kernel/shmmax
Be sure to restart ZoneMinder after this.However be aware that sometimes you will only need to change the shmmax value as shmall is often large enough. Also changing these values in this way is only effective until your machine is rebooted.
To change them permanently you will need to edit /etc/sysctl.conf and add the following lines (for example) :-
kernel.shmall = 134217728
kernel.shmmax = 134217728
To load these settings in the sysctl.conf file type:
sysctl -p
To check your shared memory settings type:
ipcs -l
These changes will now also be set the next time your machine is restarted.
To send an email on event
- install the exim4 according to https://help.ubuntu.com/community/Exim4
- my /etc/exim4/update-exim4.conf.conf looks like this (using the normal smtp server of my provider)
dc_eximconfig_configtype='smarthost'restart the system.
dc_other_hostnames='nerd.alert'
dc_local_interfaces='127.0.0.1'
dc_readhost=''
dc_relay_domains=''
dc_minimaldns='true'
dc_relay_nets=''
dc_smarthost='mail.bluewin.ch::25'
CFILEMODE='644'
dc_use_split_config='false'
dc_hide_mailname='false'
dc_mailname_in_oh='true'
dc_localdelivery='mail_spool'
sudo update-exim4.conf
sudo /etc/init.d/exim4 restart
test if you can mail:
echo test | mail -s test_mail yourmail@yourprovider.com
To send an email on event with video included
chnage in the options sections of ZM
ZM_OPT_MPEG to ffmpeg
ZM_PATH_FFMPEG to /usr/bin/ffmpeg
add the %EV% in the e-mail text: will attach the movie as mail
Check in zmvideo.pl and change ">& ffmpeg.log" to "&> /tmp/ffmpeg.log"To do:
Surf anonymously / blocked sites at work (with SQUID)
first on your box at home:sudo apt-get install squid
- in /etc/squid/squid.conf change the line # And finally deny all other access to this proxy
#http_access deny all
http_access allow all
In putty (get it here) on your work PC do
In Firefox (IE is similar) on your work machine
Enjoy all the blocked sites...
same same here: http://rdiggle.blogspot.com/2007/12/facebook-blocked-at-work.htmlrtorrent+TOR+Windows= bittorrent fun on the easy and save way
Reboot the system (
a) mount on your windows the BOX over samba
Do it this way in windows explorer
Tools -> map Network drive and assign a drive letter to the samba share (quite handy)
Browse into the boxuser folder
Then
b) drop the the torrent trackr files (*.torrent) into the folder called torrents
c) as soon as the torrent is finished it apears in the finished folder
you can the copy and delete from your windooze machine whatever you want
- To see the performance of your torrent download, log with putty or similar into the box and call
screen –r
to exit without destroing the downloads do: Ctrl A D
in the .rtorrent.rc you can change
- the bandwith used on a daily schedule
- if the torrents can not connect to the tracker: uncomment the last line
