打开网页并将其记录为 cron 作业的脚本

打开网页并将其记录为 cron 作业的脚本

我需要并且必须创建一个脚本,以网页地址和时间(以秒为单位)作为参数。它记录网页上显示的任何内容 - 即 JavaScript 和 HTML 内容(不需要 Flash)。脚本将以 cron 作业非交互方式运行。其他限制是它不能启动登录管理器或劫持已经运行的 X 服务器。也不能假设已安装登录管理器或服务器内置了哪种图形适配器。这是我目前想到的半解决方案,但由于 Xserver 和需要作为 cron 作业运行,它并不好。此外,它还需要在最新的 Ubuntu 或 Debian 上运行!

如果您有任何其他解决方法或建议,请说!:)

if [ $# -ne 3 ]then
echo "Arguments missing!";
echo "Entered  : $0 $1 $2 $3 (out of $# vars)";
echo "Should be: $0 http://feri.uni-mb.si/ 60s i_stare_at_websites_everyday.ogv";
exit
fi

#continued...
URL=$1;
TIME=$2;
OUTFILE=$3;

echo "++ Using URL: $URL";
echo "++ Capturing browser window for $TIME seconds";

# chromium is used as a better workaround for firefox's safe mode PITA browser.jar settings unpack+set+pack bug
#firefox $1 &
chromium-browser --disable-translate --app=$URL --user-data-dir /tmp &
browserPID=$!
#sleep for 4 secodns = loading firefox + webpage loading time 2+2?
#recordmydesktop has a delay argument which doesn't work.
#we need to sleep the execution old school way.
sleep 4s

unset xC yC wC hC
  eval $(xwininfo -id $(xdotool getactivewindow) |
    sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/xC=\1/p" \
           -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/yC=\1/p" \
           -e "s/^ \+Width: \+\([0-9]\+\).*/wC=\1/p" \
           -e "s/^ \+Height: \+\([0-9]\+\).*/hC=\1/p" )

echo "Starting capture...";
recordmydesktop -x=$xC -y=$yC --width=$wC --height=$hC -o $OUTFILE 2&> /tmp/record_script_log &
# 2&> /tmp/recording_script.log &
recorderPID=$!
echo "++ Firefox Process ID: $firefoxPID, RCD ID: $recorderPID, Recording for: $TIME";
sleep $TIME
echo "++ All done! Cleaning up..."
echo "++ File saved as $OUTFILE";
# shut down "record my desktop" nicely
kill $recorderPID
kill -9 $browserPID

答案1

使用wget。它应该安装在您的系统上,因为它是软件包的依赖项ubuntu-standard。否则使用 进行安装apt-get install wget

相关内容