#################################
## xffhandler.sh
#!/bin/bash
SLEEP_INT=10
case "$1" in
start)
DISPLAY=:2.0
export DISPLAY
if [[ "$(top -bn1 | grep Xvfb)" == "" ]];
then
echo "Starting Xvfb (and waiting $SLEEP_INT secs)..."
#Xvfb :2 -screen 0 1024x1400x24 >/dev/null 2>&1 &
Xvfb :2 -screen 0 1024x2000x24 >/dev/null 2>&1 &
while [[ "$(top -bn1 | grep Xvfb)" == "" ]];
do
sleep $SLEEP_INT;
done
else
echo "Xvfb ALREADY LOADED"
fi
if [[ "$(top -bn1 | grep firefox-bin)" == "" ]];
then
echo "Starting firefox (and waiting $SLEEP_INT secs)..."
firefox >/dev/null 2>&1 &
sleep $SLEEP_INT;
while [[ "$(top -bn1 | grep firefox-bin)" == "" ]];
do
sleep $SLEEP_INT;
done
else
echo "firefox ALREADY LOADED"
fi
;;
stop)
echo "Stopping firefox/Xvfb..."
if [[ "$(top -bn1 | grep firefox-bin)" != "" ]];
then
killall firefox-bin
echo " firefox has been killed"
else
echo " firefox NOT LOADED"
fi
if [[ "$(top -bn1 | grep Xvfb)" != "" ]];
then
killall Xvfb
echo " Xvfb has been killed"
else
echo " Xvfb NOT LOADED"
fi
;;
status)
if [[ "$(top -bn1 | grep Xvfb)" != "" ]];
then
echo "Xvfb is running"
else
echo "Xvfb NOT running"
fi
if [[ "$(top -bn1 | grep firefox-bin)" != "" ]];
then
echo "Firefox is running"
else
echo "Firefox is NOT running"
fi
;;
esac
exit 0
#################################
#################################
## ffcapture.sh
#!/bin/bash
URL=$1
FILE=$2
CPU_LIMIT=15
SLEEP_INT=15
DISPLAY=:2.0
echo "performing a screen capture on:"
echo " $URL"
echo " and saving result to: $FILE"
/path/to/XFFhandler.sh start
export DISPLAY
firefox -remote "openurl($URL,new-window)"
sleep $SLEEP_INT
echo " waiting for page to load (pid's cpu usage < $CPU_LIMIT)"
while [[ "$(top -bn1 | grep firefox-bin | awk '{print $9}')" > "$CPU_LIMIT" ]];
do
echo " sleeping for $SLEEP_INT secs...";
sleep $SLEEP_INT;
done
xwd -root -silent | convert - $FILE ## wait until page is loaded
echo "success! ...i think :)";
/path/to/XFFhandler.sh stop
exit 0
#################################