search for string in big source code linux

search for tty string in all .sh files in /etc dir

for i in $( find /etc -name *.sh );do OUT=$( grep -i 'tty' $i ); test "$OUT" && echo -e "\n$i\n$OUT"; done

search for database string in all .php files in local dir

for i in $( find . -name *.php );do OUT=$( grep -i 'database' $i ); test "$OUT" && echo -e "\n$i\n$OUT"; done

search for log4j string in all .java files in local dir

for i in $( find . -name *.java );do OUT=$( grep -i 'log4j' $i ); test "$OUT" && echo -e "\n$i\n$OUT"; done
Advertisements

phpmyadmin with multiple servers

how to configure phpmyadmin with two servers

vi /path/to/phpmyadmin/config.inc.php
/* Servers configuration */
$i = 0;

/* Server: 192.168.0.7 */
$i++;
$cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['host'] = '192.168.0.7';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['password'] = '';

/* Server: 192.168.0.8 */
$i++;
$cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['host'] = '192.168.0.8';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['password'] = '';

/* End of servers configuration */

$cfg['blowfish_secret'] = '5707870738.70703';
$cfg['DefaultLang'] = 'en';
$cfg['ServerDefault'] = 1;
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';

Logar Erros PHP

1 – Altere as entradas abaixo em /etc/php.ini

log_errors = On
error_log = /var/log/php_errors.log

2 – Teste

php -r "error_log('123');"
more /var/log/php_errors.log

3 – Adicionando entrada ao logrotate ( opcional )

vi /etc/logrotate.d/php-cli

/var/log/php_errors.log {
  weekly
  missingok
  rotate 13
  compress
  delaycompress
  copytruncate
  notifempty
  create 664 root www-users
  sharedscripts
}

Script para Exportar usuarios e permissoes MySQL

<?php
// Exporta usuarios e permissoes MySQL

$host = 'localhost';
$user = 'root';
$pass = 'toor';

header('Content-type: text/plain; Charset=UTF-8');
$export = array();
$link = new mysqli($host, $user, $pass, 'mysql', 3306);

if ($link->connect_error) {
printf('Connect failed (%s): %s', $link->connect_errno, $link->connect_error);
die();
}

$link->query('SET NAMES \'utf8\'');
$result = $link->query('SELECT `User`, `Host`, `Password` FROM `user`');

if ($result) {
while ($row = $result->fetch_row()) {
$user = $row[0];
$host = $row[1];
$pass = $row[2];

$export[] = 'CREATE USER `'. $user .'`@`'. $host .'` IDENTIFIED BY \''. $pass .'\'';

// Fetch any permissions found in database
$result2 = $link->query('SHOW GRANTS FOR `'. $user .'`@`'. $host .'`');

if ($result2) {
while ($row2 = $result2->fetch_row()) {
$export[] = $row2[0];
} // while ($row2...
} // if ($result2)...
} // while ($row...
}

$link->close();
echo implode(";\n", $export);
?>