sabato, novembre 05, 2016

Streaming webcam con MOTION (ubuntu 14)

Streaming USB webcam su browser con MOTION su Ubuntu 14.04

Procedura per installare MOTION su Ubuntu visto la necessità di avere una webcam di videosorveglianza

sudo apt-get install motion

Modifica il file di configurazione situato in /etc/default/motion con la seguente impostazione

start_motion_daemon=yes

Ora modifica il file che trovi in /etc/motion/motion.conf con le seguenti impostazioni


webcam_quality 85
webcam_localhost off
webcam_port 8080
webcam_motion on
webcam_maxrate 5

control_port8081
control_localhost off

Avvia MOTION con il seguente comando

sudo service motion start

Per visualizzare la cam su browser
http://127.0.0.1:8080

Per visualizzare impostazioni
http://127.0.0.1:8081

Per interrompere il salvataggio di immagini e video catturate con il Detect Motion e usare solo per Live streaming
http://127.0.0.1:8081/0/detection/pause

Esempio pagina html per esecuzione live camera avvio-sorveglianza-live.html
<html>
<head></head>
<body>
<img src="http://114.114.114.155:8080/0/detection/pause" style="display:none"/>  
<img src="http://114.114.114.155:8081"/>
</body>
</html>

lunedì, gennaio 25, 2016

Linux eseguire procedure con comando SCREEN

Il comando screen in linux permette di eseguire procedure lunghe come trasferimenti da terminali remoti senza dover necessariamente tenere aperta la shell.
Installare screen con: 
# apt-get install screen

Aprire il terminale (putty) ed eseguire un qualsiasi comando, come ad esempio un rsync, con il comando screen
# screen rsync -av /sorgente /destinazione

Ora chiudendo il terminale putty dalla "X" l'esecuzione del comando rsync non verrà interrotta ma proseguirà fino alla conclusione naturale.
In caso di verifica basterà riaprire il terminale putty e dopo il login eseguire
# screen -r

mercoledì, luglio 08, 2015

Linux Debian/Ubuntu, default GATEWAY e DNS


ip command to set a default router to 192.168.1.254

Login as the root and type:
# ip route add default via 192.168.1.254
OR
$ sudo ip route add default via 192.168.1.254

route command to set a default router to 192.168.1.254

Login as the root and type:
# route add default gw 192.168.1.254
OR
$ sudo route add default gw 192.168.1.254

Save routing information to a configuration file /etc/network/interfaces

Open /etc/network/interfaces file
# vi /etc/network/interfaces
OR
$ sudo vi /etc/network/interfaces

Find eth0 or desired network interface and add following option
gateway 192.168.1.254

Save and close the file. Restart networking:
# /etc/init.d/networking restart
OR
$ sudo /etc/init.d/networking restart

Per i DNS, editare il file /etc/resolv.conf ed aggiungere:

nameserver 8.8.8.8
nameserver 8.8.4.4

domenica, aprile 12, 2015

Script in PHP per cancellazione di files

Ho trovato questo script in php molto utile per la cancellazione di intere directory e contenuti, cosa che molto spesso capita di fare e che molto spesso non ci si riesce a causa di crash continui o blocchi del client ftp di turno.

Indicare a fine listato la directory da rimuovere: remove('it/');
Script:
 <?php

function remove($dirname = '.')
{
        if (is_dir($dirname))
        {
                echo "$dirname is a directory.<br />";

                if ($handle = @opendir($dirname))
                {
                        while (($file = readdir($handle)) !== false)
                        {
                                if ($file != "." && $file != "..")
                                {
                                        echo "$file<br />";

                                        $fullpath = $dirname . '/' . $file;

                                        if (is_dir($fullpath))
                                        {
                                                remove($fullpath);
                                                @rmdir($fullpath);
                                        }
                                        else
                                        {
                                                @unlink($fullpath);
                                        }
                                }
                        }
                        closedir($handle);
                }
        }
}

remove('it/'); // Questa e' la directory che verrà svuotata.

?>

lunedì, giugno 23, 2014

Accedere in SSH senza effettuare sempre il LOGIN

Per accedere ad una macchina tramite SSH senza dover tutte le volte digitare la password bisogna generare una chiave da posizionare nella directory utente\.ssh

- generare la chiave
[utente@linuxbox1 ~]$ ssh-keygen -b 2048 -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/utente/.ssh/id_rsa):
Created directory '/home/utente/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/utente/.ssh/id_rsa.
Your public key has been saved in /home/utente/.ssh/id_rsa.pub.
The key fingerprint is:
90:98:4f:f5:69:39:57:5d:46:83:a4:a2:d6:63:3c:25
 A questo punto dovremmo copiare la chiave pubblica sul server SSH. Questa essendo pubblica può essere letta da chiunque, senza problemi di sicurezza. Per copiarla possiamo usare anche scp, programma per la copia di SSH. Ipotizzando che il server si chiami linuxbox2 e che l’utente si chiami utente2, il comando sarà:

[utente@linuxbox1 ~]$ scp /home/utente/.ssh/id_rsa.pub utente2@linuxbox2:.

Ci verrà chiesta la password di utente2 e il file id_rsa.pub, contenente la chiave pubblica, verrà copiata nella home di utente2 su linuxbox2. A questo punto facciamo il login su linuxbox2 (ovviamente come utente2), e copiamo il contenuto del file appena copiato nel file /home/utente2/.ssh/authorized_keys:

cat /home/utente2/id_rsa.pub >> /home/utente2/.ssh/authorized_keys

A questo punto basterà provare a collegarsi dall’host linuxbox1 su linuxbox2 per connettersi a patto di inserire la passphrase scelta (per quanto sconsigliabile questa può anche non essere inserita, a patto di creare una coppia di chiavi con passphrase vuota):

ssh utente2@linuxbox2

Trasferire file da Linux a Linux

Mi trovo con la necessità di trasferire i dati da un vecchio server Linux ad uno nuovo, ho usato il comando SCP (ssh)

da ALTRO PC ad QUESTO PC
# scp -r user@ip:/dir/da/copiare .
# scp -r user@ip:/dir/da copiare /destinazione
nota: usare il punto per directory corrente e -r per directory comprese

da QUESTO PC ad ALTRO PC
# scp <miofile> user@ip:/dir/destinazione

mercoledì, giugno 04, 2014

[GNU/Linux] Montare disco di rete da shell

Per montare un disco di rete da shell, la sintassi del comando è la seguente:
mount -t protocollo //percorso_da_montare/directory /directory_destinazione -o username=user,password=pwd,sec=ntlm

Dove al posto di protocollo è necessario specificare il protocollo/file system da usare per la condivisione dei file (cifs, nfs), come avviene similmente nel caso si debba montare un disco locale (ntfs, ext2, ext3, ext4, …).

esempio da un sistema Windows:
mount -t cifs //reteazienda.it/documenti /mnt/dati_condivisi -o username=matteo,password=12345678,sec=ntlm

domenica, agosto 11, 2013

Rsync - failed: Operation not supported (95)




Errore sul log:
failed: operation not supported (95)

Risolto in questo modo:
creo un directory "temp" e dico a rsync di usarla prima di trasferire il file

# mkdir -p /var/tmp/rsync
# rsync -av --delete --temp-dir=/var/tmp/rsync <sorgente> <destinazione>

martedì, giugno 11, 2013

Script di backup con RSYNC

Nota:
Per verificare se un'unità è montata verifico semplicemente l'esistenza e la scrittura di un file presente sull'unità di destinazione. Nella root principale del disco esterno creo un file chiamato ".controllo" e verifico se il file esiste, se può essere letto e se può essere scritto.

#!/bin/sh
FILE="/mnt/nas/.controllo";
if [ -r $FILE -a -w $FILE ]; then
     echo "Verifica destinazione: OK"
else
     echo "errore, destinazione non raggiungibile, provo a fare un mount del disco"
     mount /mnt/nas
fi
if [ -r $FILE -a -w $FILE ]; then
     echo "Inizio il backup in data: $(date)"
     /usr/bin/sudo rsync -av --delete --no-group --no-owner /home /mnt/nas/backup
else
     echo "Attenzione non è possibile effettuare il backup. Destinazione non disponibile"
fi

mercoledì, maggio 22, 2013

Verificare se un volume è montato MOUNT

Faccio una verifica nel file /proc/mounts se esiste la riga in riferimento al volume desiderato:

#!/bin/sh
if grep -qs '/mnt/miacartella' /proc/mounts; then
echo "il volume è montato!";
else
echo "il volume non è montato!";
fi

Per info, nel file /proc/mounts vengono elencati tutti i mount effettuati sulla macchina

SMBFS mount


Articolo preso da: http://www.linuxnix.com/2009/09/8-ways-to-mount-smbfs-samba-file-system-in-linux.html

How to Mount smbfs (SAMBA file system) permanently in Linux.In this post I am going to give some examples how to do SMB (Server Message Block) mounts.

Type1 : Listing SMB shared folder through command prompt
#smbclient –L ipadd –U username
Here –L will specify listing of SMB share for the server with ipadd

Or
#smbclient //192.168.0.1/share1 –U username

Example :
#smbclient –L 192.168.0.1 –U root

Type2 : Mounting SMB share on local folder by using smbmount command
#smbmount //ipadd/sharename /mountpoint –o username=userid,workgroup=workgroupname

Example :
#smbmount //192.168.0.1/share1 /mnt –o username=steev,workgroup=test

Type3 : Mounting SMB share by using mount command
#mount –t smbfs ipadd:/sharename /mountpoint –o username=userid,workgroup=workgroupname

Or
#mount –t smbfs //ipadd/sharename /mountpoint –o username=userid,workgroup=workgroupname

Example :
#mount –t smbfs 192.168.0.1:/share1 /mnt –o username=surendra,workgroup=test

Type4 : Mounting CIFS (Common Internet File System) is nothing but a advanced SMB file system implementation which support RAP (Remote Access Protocol)
#mount –t cifs ipadd:/sharename /mountpoint –o username=userid,workgroup=workgroupname

Example :
#mount –t cifs 192.168.0.1:/share1 /test –o username=Surendra,workgroup=test

Type5 : All the above commands will ask password to display/mount the share name, however we can specify the password in command itself as below
#mount -t smbfs -o username=userid,workgroup=workgroupname,password=XXXXX //ipadd/sharepoint /mountpoint/

Example :
#mount –t smbfs –o username=Surendra,workgroup=test,password=xylBJRS8 //192.168.0.1/share1 /test

Type6 : Mounting permanently by editing /etc/fstab file, below is the fstab file entry example
#vi /etc/fstab//192.168.0.1/share1 /test smbfs rw,user,username=surendra,password=xylBJRS8 0 0

Save and exit the file and conform that you edited fstab file properly. By below commands
#mount –a

This command should not through any error,
#df –H

This command should n style="font-size: small;"> show mount from 192.168.0.1 server

Type7 : Mounting a share where user belongs to a domain permanently by editing /etc/fstab file
The above command will not work properly for domain users so we have to specify domain as well when specifying username
So now username will be changed to domainusername
#vi /etc/fstab
//192.168.0.1/share1 /mnt smbfs rw,user,username=testsurendra,password=xylBJRS8 0 0

Save the file and exit then execute mount –a and df –H for just conformation if the mount is done successfully.

Type8:As you people know /etc/fstab file is visible to all the users who logged in, so specifying user password in /etc/fstab file is not that much good procedure.. So there is a work around to resolve this issue, just create a credential file in users home directory and point that file in /etc/fstab file entry as mention below.
#cd ~
#echo username=surendra > .smbfile
#echo password=xylBJRS8 >> .smbfile
#chmod 600 .smbfile

Then edit the /etc/fstab file and specify the entries as below
#vi /etc/fstab
//192.168.0.1/share1 /mnt smbfs credentials=/home/myhomedirectoryofuser/. smbfile,rw,user 0 0

Save and exit the file and execute mount –a, df –H to check if you did any mistakes..

mercoledì, maggio 15, 2013

Filesystem NFS

Installazione pacchetto NFS e mount
# apt-get install nfs-common

Supponendo che il server NFS sia "192.168.1.100" e la directory condivisa sia "/home/user"
#mount 192.168.1.100:/home/user /mnt/miadir

Per il mount su fstab:

inserire nel file etc/fstab la riga:
192.168.1.100:/home/user mnt/miadir nfs rsize=8192,wsize=8192,timeo=14,intr

poi, semplicemente:
#mount /mnt/ftp


venerdì, maggio 10, 2013

Linux MDBTOOLS (mdb-export)

Per esportare tabelle create con Access in MySQL

Installare utility mdbtools:
# apt-get install mdbtools

Per esportare le tabelle di Access usare mdb-export con questa sintassi:

Direttamente in mysql
# mdb-export -D '%Y/%m/%d' -I mysql database.mdb table_name | sed -e 's/)$/)\;/' | mysql -u username --password=<pwd> database_name


In un file MySQL
# mdb-export -D '%Y/%m/%d' -I mysql database.mdb table_name | sed -e 's/)$/)\;/' > nomefile.sql

In CSV
# mdb-export database.mdb table_name > export.csv

L'opzione -D serve per la formattazione della data, in questo caso con lo standard "%Y / %m / %d" ossia "ANNO/MESE/GIORNO"

Da notare nelle ultime versioni di mdbtools l'indicazione del tipo di "backend" nell'opzione "-I" che sono: access, sybase, oracle, postgres, mysql

NB
per importare in MySQL da un file con il terminale:
# mysql -u username --password=<pwd> database_name < file.sql

Rsync su FTP con CURLFTPFS

Necessario sia RSYNC che CURLFTPFS

Installazione:
# apt-get install rsync
# apt-get install curlftpfs

Eseguire mount su server linux da ftp:
# curlftp -o allow_other ftp://utente:password@mioserverftp.it /mnt/ftp

Eseguire rsync su cartella remota
# rsync -av --delete /home /mnt/ftp

Per inviare report via mail usare server "mutt" (vedi configurazione MUTT) in questo modo:
# rsync -av --delete /home /mnt/ftp | mutt -s "Report backup rsync" destinatario@mail.com

Per il mounting automatico di curlftpfs editare il file /etc/fstab in questo modo:
curlftpfs#user:password@mioserverftp /mnt/ftp fuse rw,uid=500,user,noauto 0 0

poi direttamente:
# mount /mnt/ftp


Configurare MUTT su linux (debian/ubuntu based)

Necessario: MUTT e SSMTP

# apt-get install mutt ssmtp

Configurazione per GMAIL:

Editare il file "ssmtp.conf" in /etc/ssmtp/ssmtp.conf in questo modo:

Per GMAIL
root=miamail@gmail.com
mailhub=smtp.gmail.com:465
UseTLS=YES
hostname=nomeserver
FromLineOverride=YES

---------------------------------------------------------------------------

Per altro gestore, ad es ARUBA
#root=
mailhub=smtp.aruba.it:25
#rewriteDomain=
#hostname=
UseSTARTTLS=NO
AuthUser=utente
AuthPass=password
FromLineOverride=YES

Creare nella directory utente (in questo caso root /root) il file ".muttrc" ed inserire:

Per GMAIL con IMAP
set imap_user = "vostra_email@gmail.com"
set imap_pass = "vostra_password"
set from = "vostra_email@gmail.com"
set realname = "vostro_nome"
set sendmail = "/usr/sbin/ssmtp -fvostro_nome -au vostra_email@gmail.com -ap vostra_password"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed="+[Gmail]/Drafts"
set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates
set sort = 'threads'
set sort_aux = 'last-date-received'
set imap_check_subscribed
set move = no

ignore "Authentication-Results:"
ignore "DomainKey-Signature:"
ignore "DKIM-Signature:"
hdr_order Date From To Cc

---------------------------------------------------------

Per altro gestore, ad es ARUBA
# Purge deleted message without confirm.
set delete=yes

# Don't move read message to mbox and don't ask for it!
set move=no

# Set a customized "From: " header.
my_hdr From: Pippo<info@pippo.it>

# Mailbox format should be autodetected.
#set mbox_type=Maildir

# Specifies the default location of local mailboxes.
# Default is "~/Mail".
set folder=~/Maildir

# Append sent messages to "Sent", mbox or Maildir format will
# be autodetected. The "+" sign means relative to the $folder
# directory.
set record=+Sent

# Where to store postponed messages (instead of ~/postpone).
set postponed=+Postponed

# Choose which header to hide/show, and their order.
ignore *
unignore  from: date: subject: to: cc:
hdr_order from: date: subject: to: cc:

# Select the text editor.
set editor="/usr/bin/nano -r 65"

------------------------------------------

Per inviare mail da terminale:
# echo "prova invio mail" | mutt -s "soggetto messaggio" destinatario@mail.com

Server DNS: come crearlo nella propria LAN locale

Ho dovuto realizzare un server DNS locale per risolvere tutti quei domini interni alla mia rete LAN perché mi sono rotto le palle che su un ...