Linux

Using CRON hourly, daily folders

Built into most crontabs is the functionality to run scripts hourly, daily, weekly or monthly. All that is requires is that you create a bash file and place it in a folder. It will automagically run – no CRON reload. There are a few tricks. The file cannot have an extension or spaces The file must be executable. The folders are /etc/cron.hourly /etc/cron.daily /etc/cron.weekly /ect/cron.monthly You can check if the file is accepted by running…

Continue reading

Apache htaccess Linux

Password protecting an Apache Server

If you need to protect a web server so that a folder cannot be access without entering a password first. First ensure that the option is turned on vim /etc/apache2/sites-available/default change AllowOverride None to AllowOverride All Now, create a .htaccess file AuthUserFile /var/htpasswd AuthName “Authorization Required” AuthType Basic require valid-user Instead of “valid-user”, you can enter the usernames you want. Finally create a password file. For each user, replace “username” htpasswd -c /var/htpasswd username You…

Continue reading

Bash Linux

Redirection Output in Linux Bash/Shell

You can redirect outoput from a command into a file cat filename filename2 and that will redirect all output. But you can also select the type of output 0 = Standard Input 1 = Standard Output 2 = Standard Error So that this wil send error messages to nothing cat filename 2/dev/null Or explicitly send both standard output and standard error to a file with and ampersand (“&”) docommand &filename You can append to a…

Continue reading

Linux VIM

vim Cheat Sheet

Modes Vi has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute as soon as you type them except for “colon” commands which execute when you press the return key. Quitting 😡…

Continue reading

Linux

Find all files with two words

Suppose we want to find all files that contain two words. find . -type f | xargs grep -l “word1” | xargs grep -l “word2” How this works “find” will return a list of all files this list is piped into “xargs” “xargs” will pass each item in the list to its own function – in this case, the “grep” command the “-l” option on the “grep” will return just the filenames of those files…

Continue reading

Linux

Format a Drive in EXT4

To format a drive, using default options, in EXT4, mkfs.ext4 /dev/xvdh EXT4 also allows the number of inodes to be modified. Each file requires its own inode and if you have lots of small files, you may run out of inodes before you run out of space. Alternatively, if you are only going to have a few large files, you can get more disk space by limiting the number of inodes. To set the inode…

Continue reading

Linux MongoDB PHP

Install MongoDB with Nginx + PHP on Ubuntu

Assuming you already have Nginx and PHP installed and want to add MongoDB support. Install pre-requisites apt-get update apt-get install php5-cli php5-common php5-suhosin php5-cgi php5-curl php5-fpm php5-json php5-mcrypt php5-mysql php5-sqlite php5-dev php-pear php-apc Enable Mongo pecl install mongo echo “extension=mongo.so” >> /etc/php5/fpm/php.ini Install MongoDB apt-get install mongodb mongodb-server Restart Services service nginx restart service php5-fpm restart done

Continue reading

AWS Linux

Install s3fs on Ubuntu from SVN

s3fs mounts an Amazon AWS S3 bucket into your files system as a directory. This is fantastic for backup folders – backups are automagically off-site. Here is a better way of installing s3FS using SVN. Install Pre-requisites apt-get install build-essential libfuse-dev fuse-utils libcurl4-openssl-dev libxml2-dev mime-support Install s3fs svn checkout http://s3fs.googlecode.com/svn/trunk/ s3fsbr>cd s3fs/ autoreconf –install ./configure –prefix=/usr make make install Syntax is s3fs bucket-name mount/point You must either setup two environment variables AWSACCESSKEYID and AWSSECRETACCESSKEY or…

Continue reading

Linux

Forward all root email to an external email address

There are two easy ways of doing this. First, you could set up a forward for the root email account. All emails to root will be forwarded. `echo “you@yourmail.com” > /root/.forward` OR, Secondly, set up an alias for root as an external email address echo “root: you@yourmail.com” >> /etc/aliases && newaliases Beware that you only have one entry for root in the /ect/aliases file done

Continue reading