PhantomJS: wait for it

When you want to take screenshots with PhantomJS, you probably need to wait before your page is completely loaded. I mean all resources are loaded and scripts executed. Use the following code to delay your screenshot : var page = new WebPage(); page.open(‘http://stackoverflow.com/’, function (status) { just_wait(); }); function just_wait() { setTimeout(function() { page.render(‘screenshot.png’); phantom.exit(); … 

 

Find and remove files

I regularly use the find command in scripts to clean directories on my servers. The common way to use find to do this is to write something like: find ./my_dir -name ‘cache-*’ -exec rm -rf \{\} \; It works fine but it always outputs messages like this: find: ./mydir/cache-001: No such file or director which … 

 

Quickly check hosts with ping

I needed a script for a quick health check of a bunch of servers. This is how I did it using the ping command: for((i=1;i<42;i++)); do ping -c 1 -W 3 host${i}.domain.com &> /dev/null if [ $? -ne 0 ] ; then echo “host${i} is down” else echo “host${i} is up” fi done You can …