——————————————–
nmap scan all network to find live ip
nmap -sP 192.168.1.1/24
——————————————-
yum install from file txt
rpm -qa > installed.txt
yum -y install $(cat installed.txt)
——————————————————–
systemctl il successore di chkconfig abilita servizio all avvio systemctl enable sshd disabilita servizio all avvio systemctl disable sshd controllo lo stato systemctl is-enabled sshd; echo $? note
Attiva un servizio immediatamente:
systemctl start foo.service
Disattiva un servizio immediatamente:
systemctl stop foo.service
Riavvia un servizio:
systemctl restart foo.service
Mostra lo stato di un servizio o se è avviato o meno:
systemctl status foo.service
Abilita un servizio per essere inizializzato all’avvìo:
systemctl enable foo.service
Disabilita un servizio per non essere inizializzato all’avvìo:
systemctl disable foo.service
Controlla se un servizio è già abilitato o meno:
systemctl is-enabled foo.service; echo $?
0 indica che è abilitato. 1 indica che è disabilitato. In Fedora 17, in aggiunta al codice di ritorno, “enabled” o “disabled” saranno stampati in output.
Far riferimento a man systemctl per maggiori dettagli.
——————————————————-
RSYNC
rsync -avz /tmp/scambio/ root@serveremoto.it:/tmp/scambio
tutto quello che cè in locale (anche sottocartelle ) va sul remoto senza cancellare niente dal remoto
rsync -avz –delete /tmp/scambio/ root@serveremoto.it:/tmp/scambio
uguale a sopra ma cancella i files dal remoto se dal source non ci sono
Postfix contare quante email ci sono in coda
postqueue -p | tail -n 1 | cut -d’ ‘ -f5
cancellare tutta la coda
postsuper -d ALL
Per liberare Ram dal kernel 2.6.16 in poi
$ free -m
# sync
# echo 3 > /proc/sys/vm/drop_caches
Per svuotare lo swap
swapoff -a
swapon -a
Aggiungere un disco a caldo su un guest linux sotto vmware
echo “- – -” > /sys/class/scsi_host/host0/scan
dove host# si ricava da
ls /sys/class/scsi_host
mysql
dump di tutto
mysqldump –all-databases -u root -p > /tmp/databases.sql
import di tutto (db e user )
mysql -u root -p < /tmp/databases.sql
export di 1 solo db
mysqldump -u root -p nomedb>nomedb.dmp
tipo vmstat ma per mysql
mysqladmin -i 5 status
netstat
Visualizzare il numero delle connessioni in totale
# netstat -n | wc -l
Visualizzare il numero delle connessioni da ip unici
# netstat -nat | awk ‘{ print $5}’ | cut -d: -f1 | sed -e ‘/^$/d’ | uniq | wc -l
Visualizzare il numero delle connessioni in totale di una sola porta, ad esempio la 80
# netstat -n | grep :80 | wc -l
Visualizzare e quantificare lo stato e il numero di connessioni
# netstat -nat | awk ‘{print $6}’ | sort | uniq -c | sort -n
Visualizzare e quantificare il numero di connessioni e lo stato di esse, provenienti da un solo ip, ad esempio 127.0.0.1
# netstat -nat |grep 127.0.0.1 | awk ‘{print $6}’ | sort | uniq -c | sort -n
Visualizzare la lista degli ip in ascolto e quantificare il numero delle connessioni in totale per ogni ip
# netstat -anp |grep ‘tcp\|udp’ | awk ‘{print $4}’ | cut -d: -f1 | sort | uniq -c | sort -n
Visualizzare la lista degli ip collegati e quantificare il numero delle connessioni totale per ogni ip
# netstat -anp |grep ‘tcp\|udp’ | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n
Visualizzare una lista completa di tutti gli ip connessi senza doppioni
# netstat -nat | awk ‘{ print $5}’ | cut -d: -f1 | sed -e ‘/^$/d’ | uniq
Visualizzare una lista completa delle connessioni
# netstat -tulpan
Visualizzare in modo ancora più completo tutte le connessioni stabilite ai software in rete
# lsof -i
Statistiche di rete
# netstat -s | less
# netstat -t -s | less
# netstat -u -s | less
# netstat -w -s | less
# netstat -s
# netstat –interfaces eth0
apache redirect sito su altro server
ServerAdmin webmasterdominio.it
ServerName www.dominio.it
DocumentRoot “/var/www/html/”
DirectoryIndex index.jsp
#JkMount /servlet/* default
#JkMount /*.jsp default
CustomLog /var/log/httpd/access.log combined
#JkOptions +ForwardDirectories
Options FollowSymLinks
AllowOverride none
AllowOverride AuthConfig Limit
RewriteEngine on
RewriteRule (.*) http://158.x.x.x/nomewebapps/$1 [P,L]
Rename a bunch of file extensions
e.g. change *.txt into *.htm
for f in *.txt; do mv ./”$f” “${f%txt}htm”; done
aggiornare ora
ntpdate us.pool.ntp.org
/etc/init.d/ntpd start
server italiani ntp
ntp1.inrim.it
ntp2.inrim.it
—————————————————————————————————-
Lanciare un comando dal server pippo al server pluto
ssh root@pluto “cp /tmp/pippo /home &”
Processare le statistiche di awstats
/var/www/awstats/awstats/awstats.pl -config=miodominio.com -update
Aumentare history a 5000 linee e con il timestamp
in /home/utente/.bashrc
aggiungere
export HISTTIMEFORMAT=”%h/%d – %H:%M:%S ”
HISTSIZE=5000
VirtualBox
VBoxManage startvm “nomeserver1″ –type headless
VBoxManage controlvm “nomeserver1″ poweroff
Aggiungere un ip al volo
ifconfig eth2:0 195.23.119.xxx up
Svuotare un file di log al volo senza restartare il processo
cp /dev/null access_log
oppure
cat /dev/null > catalina.out
trovare un file piu grande di 100 mb
find /var/www/nome_cartella -type f -size +102400k
————————————————————————————————-
find e replacec su directory e subdirectory
find . -type f -print0 | xargs -0 sed -i 's/subdomainA.example.com/subdomainB.example.com/g'
——————————————
VIM
The :substitute command searches for a text pattern, and replaces it with a text string. There are many options, but these are what you probably want:
:%s/foo/bar/g
Find each occurrence of ‘foo’, and replace it with ‘bar’.
:%s/foo/bar/gc
Change each ‘foo’ to ‘bar’, but ask for confirmation first.
:%s/\/bar/gc
Change only whole words exactly matching ‘foo’ to ‘bar’; ask for confirmation.
:%s/foo/bar/gci
Change each ‘foo’ (case insensitive) to ‘bar’; ask for confirmation.
:%s/foo/bar/gcI
Change each ‘foo’ (case sensitive) to ‘bar’; ask for confirmation.
The g flag means global – each occurrence in the line is changed, rather than just the first.