Cheatsheet

Handy Dandy Cheatsheets!!

Check for number of arguments in bash

# Check for proper number of command line args.

EXPECTED_ARGS=1
E_BADARGS=65

if [ $# -ne $EXPECTED_ARGS ]
then
  echo "Usage: `basename $0` {arg}"
  exit $E_BADARGS
fi

looping through an array with the for loop in bash

VALUES=(
value1
value2
value3
...
valueN
)

# Alternately:
#VALUES=("value1" "value2" "value3" "..." "valueN")

for ((i=0; i<${#VALUES[@]}; i++))
do
  echo ${VALUES[$i]}
done

Extract individual files from an RPM

To extract an individual file from an rpm package without installing the rpm:

  1. Use rpm2cpio or rpm -qpl to list files and full paths in the package:
    $ rpm2cpio <package_name> | cpio -t

  2. Use rpm2cpio to extract a file. Run this command from /tmp or elsewhere in order to avoid overwriting any current system files.
    This creates the full path in the current directory and extracts the file specified.
    $ rpm2cpio <package_name> | cpio -iv --make-directories <full-file-path>

  3. To extract everything to the current directory:
    $ rpm2cpio <package_name> | cpio -ivd

Load your PHP pages faster with GZip compression

If you have heavy pages with lots of images and text, you can greatly improve its' performance by dynamically compressing the page with php.

Put the below code in the header of each php page.

<? ob_start("ob_gzhandler&quot;); ?>

It automatically gzips the page for browsers that support it.

This could also be set in the php.ini file instead, so all php pages are automatically compressed without having to add the above code in each and every php page.

In php.ini add the below code:

output_handler = ob_gzhandler

Sendmail config regeneration

Regenerate sendmail config:

# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

Regenerate access file:

# makemap hash /etc/mail/access.db < /etc/mail/access

Generate new aliases:

# newaliases

Comment