#Monitoring % Swap space
UserParameter=swap.percentage, free|tail -n -1|awk '{print ($3/$2)*100}'
piwik
dimecres, 5 de juny del 2013
Monitor swap space in Zabbix
Script that monitors the status of a HP physical RAID
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 | #!/bin/bash PHDRIVE[1]=`hpacucli ctrl all show config detail | grep "physicaldrive 1I:1:1" | awk '{print $10}' | sed 's/)//' | sed -e 's/[\t ]//g;/^$/d'` PHDRIVE[2]=`hpacucli ctrl all show config detail | grep "physicaldrive 1I:1:2" | awk '{print $10}' | sed 's/)//' | sed -e 's/[\t ]//g;/^$/d'` PHDRIVE[3]=`hpacucli ctrl all show config detail | grep "physicaldrive 1I:1:3" | awk '{print $10}' | sed 's/)//' | sed -e 's/[\t ]//g;/^$/d'` PHDRIVE[4]=`hpacucli ctrl all show config detail | grep "physicaldrive 1I:1:4" | awk '{print $10}' | sed 's/)//' | sed -e 's/[\t ]//g;/^$/d'` #PHDRIVE[1]="FAULT" #PHDRIVE[2]="FAULT" #PHDRIVE[3]="OK" #PHDRIVE[4]="OK" #echo ${PHDRIVE[1]} #Meaning of the variable ALARM, # 0 ----------- No alarms, everything OK # 1 ----------- Disk 1 doesn't have STATUS OK # 2 ----------- Disk 2 doesn't have STATUS OK # 3 ----------- Disk 3 doesn't have STATUS OK # 4 ----------- Disk 4 doesn't have STATUS OK ALARM=0 for i in `seq 1 4`; do if [ "${PHDRIVE[$i]}" != "OK" ]; then ALARM=$i fi done echo $ALARM |
How to list all the applications that had been installed through apt-get
( zcat $( ls -tr /var/log/apt/history.log*.gz ) ; cat /var/log/apt/history.log ) | egrep '^(Start-Date:|Commandline:)' | grep -v aptdaemon | egrep '^Commandline:' | sed 's/Commandline: //'
How to send emails through command line
echo -e "Subject: Here is gonna be the subject\nFrom: backup@arruixaqueplou.org\nTo: alarm@arruixaqueplou.org\n\$(`cat /home/backup/daily/mylvm-$(date +%Y-%m-%d.log) && cat /home/backup/web2/mysql/mysql_$(date +%Y-%m-%d)/backup_mysql_$(date +%Y-%m-%d) && cat /home/backup/web4/mysql/mysql_$(date +%Y-%m-%d)/backup_mysql_$(date +%Y-%m-%d) && cat /home/backup/web2/gluster/gluster_$(date +%Y-%m-%d)/backup_gluster_$(date +%Y-%m-%d)`) " | sendmail -t
Sed hacks.
How to remove empty lines from a file:
sed '/^$/d' file.txt
Remove commented lines from a specific file
sed 's/^#.*//' file.txt
Above command will replace # 'ed lines by empty lines, in case we want to merge both steps into a single command, we'll issue the following command.
sed -e 's/^#.*//;/^$/d' file.txt
sed '/^$/d' file.txt
Remove commented lines from a specific file
sed 's/^#.*//' file.txt
Above command will replace # 'ed lines by empty lines, in case we want to merge both steps into a single command, we'll issue the following command.
sed -e 's/^#.*//;/^$/d' file.txt
MySQL commands
==========================
Backup database using dump
==========================
1.- Backup
mysqldump -u root xcms > new-xcms.sql
2.- Restore
(Make sure we have created the corresponding database)
mysql -u root -proot xcms < new-xcms.sql
3.-Rename DB
---------------
mysql -e "CREATE DATABASE \`new_database\`;"
for table in `mysql -B -N -e "SHOW TABLES;" old_database`
do
mysql -e "RENAME TABLE \`old_database\`.\`$table\` to \`new_database\`.\`$table\`"
done
mysql -e "DROP DATABASE \`old_database\`;"
----------------
4.-Create DB
create database old_xcms;
5.- Backup triggers and stored procedures
mysqldump -u root --all-databases --triggers --routines -d -t > dbMasterProc.sql
6.- Create user and grant all privileges
mysql> create user 'root'@'172.16.%';
mysql> grant all privileges on *.* to 'root'@'172.16.%';
mysql> show grants;
+--------------------------------------------------+
| Grants for root@172.16.% |
+--------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.%' |
+--------------------------------------------------+
1 row in set (0.00 sec)
7.- Skip execution of one row in replication servers:
mysql> set global sql_slave_skip_counter = 1;
############
Show columns
############
mysql> show columns from tbl_gamechat;
+----------------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+----------------------+------+-----+---------+----------------+
| GCHT_iID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| GCHT_TLST_iID | int(10) unsigned | NO | MUL | 0 | |
| GCHT_GAM_iID | int(10) unsigned | NO | MUL | 0 | |
| GCHT_PLY_iID | int(10) unsigned | NO | MUL | 0 | |
| GCHT_cText | varchar(255) | NO | | | |
| GCHT_dDate | timestamp | YES | MUL | NULL | |
| GCHT_iChatType | smallint(5) unsigned | NO | | 0 | |
+----------------+----------------------+------+-----+---------+----------------+
##########
See rows
##########
mysql> select * from tbl_gamechat where GCHT_iID='24875';
+----------+---------------+--------------+--------------+------------+---------------------+----------------+
| GCHT_iID | GCHT_TLST_iID | GCHT_GAM_iID | GCHT_PLY_iID | GCHT_cText | GCHT_dDate | GCHT_iChatType |
+----------+---------------+--------------+--------------+------------+---------------------+----------------+
| 24875 | 1148 | 756640 | 1029050 | | 2013-02-19 12:31:03 | 0 |
+----------+---------------+--------------+--------------+------------+---------------------+----------------+
1 row in set (0.00 sec)
##########
Delete row
##########
mysql> delete from tbl_gamechat where GCHT_iID='24875';
Backup database using dump
==========================
1.- Backup
mysqldump -u root xcms > new-xcms.sql
2.- Restore
(Make sure we have created the corresponding database)
mysql -u root -proot xcms < new-xcms.sql
3.-Rename DB
---------------
mysql -e "CREATE DATABASE \`new_database\`;"
for table in `mysql -B -N -e "SHOW TABLES;" old_database`
do
mysql -e "RENAME TABLE \`old_database\`.\`$table\` to \`new_database\`.\`$table\`"
done
mysql -e "DROP DATABASE \`old_database\`;"
----------------
4.-Create DB
create database old_xcms;
5.- Backup triggers and stored procedures
mysqldump -u root --all-databases --triggers --routines -d -t > dbMasterProc.sql
6.- Create user and grant all privileges
mysql> create user 'root'@'172.16.%';
mysql> grant all privileges on *.* to 'root'@'172.16.%';
mysql> show grants;
+--------------------------------------------------+
| Grants for root@172.16.% |
+--------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.%' |
+--------------------------------------------------+
1 row in set (0.00 sec)
7.- Skip execution of one row in replication servers:
mysql> set global sql_slave_skip_counter = 1;
############
Show columns
############
mysql> show columns from tbl_gamechat;
+----------------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+----------------------+------+-----+---------+----------------+
| GCHT_iID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| GCHT_TLST_iID | int(10) unsigned | NO | MUL | 0 | |
| GCHT_GAM_iID | int(10) unsigned | NO | MUL | 0 | |
| GCHT_PLY_iID | int(10) unsigned | NO | MUL | 0 | |
| GCHT_cText | varchar(255) | NO | | | |
| GCHT_dDate | timestamp | YES | MUL | NULL | |
| GCHT_iChatType | smallint(5) unsigned | NO | | 0 | |
+----------------+----------------------+------+-----+---------+----------------+
##########
See rows
##########
mysql> select * from tbl_gamechat where GCHT_iID='24875';
+----------+---------------+--------------+--------------+------------+---------------------+----------------+
| GCHT_iID | GCHT_TLST_iID | GCHT_GAM_iID | GCHT_PLY_iID | GCHT_cText | GCHT_dDate | GCHT_iChatType |
+----------+---------------+--------------+--------------+------------+---------------------+----------------+
| 24875 | 1148 | 756640 | 1029050 | | 2013-02-19 12:31:03 | 0 |
+----------+---------------+--------------+--------------+------------+---------------------+----------------+
1 row in set (0.00 sec)
##########
Delete row
##########
mysql> delete from tbl_gamechat where GCHT_iID='24875';
dimarts, 4 de juny del 2013
Usefull hacks for grep command.
How to count the number of lines that match with a specific pattern in a file:
grep -c Josep /etc/passwd
Using -v option, we'll be inverting the results. The number of lines that do not match the pattern will be shown.
grep -cv Josep /etc/passwd
Ignoring case sensitive:
grep -i josep /etc/passwd
Searching through all subdirectories the files that inside them have at least one occurrence of the pattern.
grep -r mysql /home/josep
grep -c Josep /etc/passwd
Using -v option, we'll be inverting the results. The number of lines that do not match the pattern will be shown.
grep -cv Josep /etc/passwd
Ignoring case sensitive:
grep -i josep /etc/passwd
Searching through all subdirectories the files that inside them have at least one occurrence of the pattern.
grep -r mysql /home/josep
Subscriure's a:
Missatges (Atom)