cut awk print nth field using awk / cut echo 'This is a test' | awk '{print substr($0, index($0,$3))}' awk '{print substr($0, index($0,$3))}' <<< 'This is a test' echo 'This is a test' | cut -d '
Wget Tutorials Wget Tips & Tricks Download to a different folder : > wget -O /etc/yum.repos.d/CentOS-Testing.repo http://dev.centos.org/centos/5/CentOS-Testing.repo Download File with Authentication: > wget –http-user=Username –http-password=password ‘url_to_download’ Using Curl : > curl –user $USERNAME ‘url’ Download with Rate Limited
Compression Utilities Tar : Create a tar ball tar -cvf tarfile.tar Extract from Tar tar -zxvf tarfile.tar Create Tar ball with compression tar -czvf tarfile.tar or tar -cjvf tarfile.tar Display Files inside a tarball: tar -tvf tarball.tar Delete a single file from inside the tarball tar –delete -f
Nagios Installation on Centos ** Install Nagios on Centos** Download the latest version of nagios core and plugins from : http://www.nagios.org/download Install Pre-requisites: > yum install httpd gc glibc glibc-common gd gd-devel php Add user and group : > useradd -m nagios groupadd nagcmd usermod -a -G nagcmd nagios usermod -a -G nagcmd
Security Apache Security Trace Back : Testing if Trace back is enabled : telnet localhost 80 TRACE / HTTP / 1.0 If you get any response back trace is enabled. Disabling Trace Back : vi /etc/httpd/conf/httpd.conf TraceEnable off or , use an htaccess or rewrite rule : RewriteEngine On RewriteCond %{REQUEST_METHOD} ^TRACE RewriteRule .* -
Rootkit Hunter--check if your system has been compromised Download Rootkit Hunter Here [http://downloads.sourceforge.net/project/rkhunter/rkhunter/1.3.8/rkhunter-1.3.8.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Frkhunter%2F&ts=1316446867&use_mirror=voxel] Untar and cd into the directory ./installer.sh –layout default –isntall rkhunter –update Now, you
Securing Server with Iptables ( Block Except ) Securing Server with Iptables Iptables is a great firewall when configured properly but sometimes you can lock yourself out with what you didn’t mean to. When you are starting to work on your firewall, it is always a good idea to create a cron job that will stop iptables
Block Ports in IPtables Blocking Ports in Iptables In order to block a single port you can use the following statement : > iptables -A INPUT -p <protocol – udp or tcp> –dport -j REJECT In order to block multiple ports , use the following statement : > iptables -A INPUT -p -m multiport –dports port1,
firewall Redirect or forward ports in iptables Redirect or Forward Ports using Iptables Port Redirection: iptables -t nat -A PREROUTING -i <interface> -p tcp --dport <port number=""> -j REDIRECT --to-port <port_number></port_number></port></interface> or iptables -t nat -I PREROUTING --src
Optimize MySQL From my-large.cnf 1. Copy the my-large.cnf which usually comes with mysql-server , usually inside the /usr/share/mysql directory Note: you might want to backup your existing my.cnf before doing this. > cp -p /usr/share/mysql/my-large.cnf /etc/my.cnf Note: All values are in seconds for time and
Monitoring Mysql Variables Top Useful MySQL Variables, That you Might Want to Monitor Max_used_connections: Displays the maximum number of connection made at any instance of time. > mysql -p -e”show global status” | grep Max_used_connections Threads_connected: Indicates the total number of open connections to the server > mysql
Password Protected tar files There can be cases when you want to password protect the tar files. There are two ways you can do it. First Method Using SSL and Salt: Encrypt: > tar -cj directory | openssl des3 -salt > encrypted.tarfile Decrypt: > cat encrypted.tarfile | openssl des3 -d -salt |tar -xvj Second
MySql Performance Tuning and utilities Optimize A Table : mysql>optimize table ; Performance Tuning Parameters: > max_connections= 100 System RAM= Global Buffers + (Thread Buffers * max_connections) max_connections= (Available RAM – Global Buffers) / Thread Buffers Values for buffer sizes, lengths, and stack sizes are given in bytes unless otherwise specified. Typical Linux Installations can handle
Create a swap file To Create a 2M swap file ( 1024 * 2048M = 2097152) or this works as well bs = 1M count = 2048 dd if=/dev/zero of=/swapfile bs=1024 count=524288 mkswap /swapfile swapon /swapfile vi /etc/fstab /swapfile swap swap defaults 0 0
Delete all files except > rm -rf $(ls * | grep -v “directory or file to save”) In order to delete all files except multiple files you can do : > rm -rf $(ls * | egrep -v “foo|bar|test|”
Mysql Troubleshooting * Mysql error – Got a packet bigger than ‘max_allowed_packet’ bytes ** In mysql console type the following :** `set global net_buffer_length=1000000;``` `set global max_allowed_packet=10000000000000;``` and then import as : mysql -u root -p --max_allowed_packet=1000M < dbdump.sql * Cannot load from mysql.proc. The
php compile error configure: error: Cannot find libmysqlclient under /usr ./configure –with-mysql=/usr/bin/ –with-libdir=lib64
Rename mutiple files > for i in *.dump; do mv “$i” “${i/.dump}”;done for i in *.JPG; do mv "$i" "${i/.JPG}".jpg; done
Shell script to backup/restore an existing svn repository Cd in to your svn repository path and create and run this script #!/bin/bash<br></br> for i in *<br></br> do<br></br> if [ "${i}" != "backupsvn.sh" ]; then<br><
PHP basic compile options when buidling from source ./configure –prefix=/usr –sysconfdir=/etc –with-config-file-path=/etc/ –localstatedir=/var –with-apxs2 –with-openssl –with-zlib –enable-calendar –with-gd –with-jpeg-dir=/usr/lib –with-png-dir=/usr/lib –with-imap –with-imap-ssl –with-kerberos –enable-sysvsem –enable-sysvshm –enable-sockets –with-curl –enable-mbstring –with-mcrypt –with-mysql –with-mysqli –with-gettext –with-freetype-dir –enable-gd-native-ttf
Compile individual php module You need to have a package phpize in order to compile an additional module. If you dont have phpize, you need to install php-devel . When you install php from source.. you should get the phpize package. Go to the directory where you have the extensions. eg. /usr/src/php-5.2.
Compile mysql client library with utf 8 support > ./configure –prefix=/usr –sysconfdir=/etc –localstatedir=/var –disable-largefile –with-charset=utf8 –with-unix-socket-path=/var/lib/mysql/mysql.sock –with-mysqld-user=mysql –with-zlib-dir=/usr –without-debug –with-ssl –with-ndbcluster –without-ndb-debug –with-extra-charsets=gb2312