Category Archives: Bash - Page 4

php-wkhtmltox

wkhtmltox is a great piece of kit to convert webpages to PDF format.

It is – however – an absolute Pita to install, as there are minimal resources on the net for installing this onto a Linux Server.

The first step is to download both the static library

libwxhtmltox

and the wkhtmltox static binary

wkhtmltopdf

Both of these can be downloaded from the Google Code repository found HERE Download the correct files for your server (i386 or amd64).

The will be packed in the unusal bunzip2 format, to exact type

bunzip2 #filename#

Then tar the file out with

tar xvf #filename#

copy the wkhtmltox directory to /usr/local/include
copy the lib/libwkhtmltox.so to /usr/local/lib/

unpack wkhtmltopdf and copy to a dir which is symlinked so you can use the CLI version from anywhere in your shell.

To add the PHP-extension requires a little more trickery.

Firstly download the source from HERE

unpack and run these commands


phpize
./configure
make test
make install

If the make test fails, it usually will mean that php was unable to load the library, so you need to add the following .

Go to

/etc/ld.so.conf.d/

and edit (or create if it doesn’t exist)

usr-local-lib.conf

add the following path

/usr/local/lib

then in your php.ini file add

extension=phpwkhtmltox.so

restart your web server, and check your phpinfo() to make sure the phpwkhtmltox extension has been loaded.

If you are installing on 32bit Centos 5.x you may have a very hard time trying to figure out why the phpize/configure fails. It usually means that you don’t have fontconfig installed, or it is an older version.

If you want to produce PDF’s from a site that is SSL enabled, you will fail… miserably… WKHTML 0.11 breaks UNLESS openssl-devel package has been installed… I lost 4 years of my life and now have a head full of grey hair. Hopefully this little tid bit of information helps some other poor soul.

You may also find that the rendered PDF’s have garbled boxes, you will need these fonts installed – on Centos

yum install urw-fonts

Yum Update excluding packages

http://www.cyberciti.biz/faq/redhat-centos-linux-yum-update-exclude-packages/

yum –exclude=perl* update

Block IP addresses with iptables

iptables -A INPUT -s IP-ADDRESS -j DROP

then save

service iptables save

Spawn Rsync Expect Timeout!

So you’ve written a bash script to do a rsync backup, but the script times out?

Scratching your heading trying to figure out what the issue is?

Well, if you are using expect to auto-insert your SSH password, then expect will timeout as it is not receiving any response.

You can set the timeout (in seconds) as such

set timeout 60

That will set the script to time out after 60 seconds if expect has received no trigger.

Setting the timeout to -1 will cause the ‘except’ script to never timeout, hence you’re RSYNC backup will execute and not fail due to an expect timeout.

CHROOT local users to their own directory

Once VSFTPD is installed, edit the

/etc/vsftpd/vsftpd.conf file and add the following line if it does not exist

chroot_local_user=YES

This will lock the FTP user into their home dir and they won’t be able to jump out.

Referenced from-

http://centoshacker.com/kabir/remove-access/creating-a-chroot-jail-enabled-ftp-service.html

PID Off….

find out the process ID of a process

pidof processname

to kill it?

kill -9 PID

Copy files between servers using SCP

scp username@hostB:~/myfile.file /localdir

hostB is the remote server we want to copy the file from

Proc Info

System Info – procinfo
procinfo gathers some system data from the /proc directory and prints it formatted on the screen.

Some of the information displayed is

Last Boot time
Load Average
average number of jobs running
number of runnable processes
total number of processes
PID of the last process run (idem)
Swap info
Memory resources
Number of disks
IRQ info
Installed modules (with the -a or -m option)
File Systems (with the -a or -m option)
To automatically update the displayed info every 30 seconds

yum install procinfo

procinfo -fn30

Free up some memory with DROP Cache

sync; echo 3 > /proc/sys/vm/drop_caches

Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.
This is a non-destructive operation, and dirty objects are not freeable, the user should run “sync” first in order to make sure all cached objects are freed

Change the default editor for Crontab

export EDITOR=nano