#take_screenshot by Josef Meile @ June, 2019 # #Takes a screenshot of the raspberry pi chromium kiosk and saves it to the #specified SCREENSHOT_DIR # #If you want to use this on a crontab, then it must be on the one of the user #running the kiosk. If you do it on the root crontab, then it won't work; even #if you put 'export DISPLAY=:0 && ' in front of the command # #Remarks: #- Scrot has big problems when using shell variables on its first argument: they # won't be replaced. I though it would be nice to have an IMAGE_FORMAT file to # specify the image format, ie: jpg or png, then use it as follows: # scrot '%H.%M.%S_$wx$h.$IMAGE_FORMAT'; however it won't work. I tried several # ways, ie: $(scrot '%H.%M.%S_$wx$h.$IMAGE_FORMAT'), but it seems that scrot # blocks shell variables. If you find a way, let me know. So, if you want to # use other format, then edit directly the scrot command (last line) and put # the image extension manually, ie: scrot '%H.%M.%S_$wx$h.jpg' #-------------------------> Customization begins here #Image quality (1-100) high value means high size, low compression. Default: 75. #(Effect differs depending on file format chosen). IMAGE_QUALITY=50 #Log file to now when x was restarted LOG_FILE=/media/your_mount_point/your_folder/takescreenshot.txt #DISPLAY :0 is the x11 display where the kiosk is running #export DISPLAY=:0 #Update: DISPLAY :0 is not always the display where the kiosk is running. #When killing x11 several times, the new display will be always the old one #plus one. This command will get the current active display export DISPLAY=`w -oush | grep -Eo ' :[0-9]+' | uniq | cut -d \ -f 2` #Where to store the screenshots SCREENSHOT_DIR="/media/your_mount_point/your_folder" #-------------------------> Customization ends here DAY=`date +'%d'` MONTH=`date +'%m'` YEAR=`date +'%Y'` HOUR=`date +'%H'` MIN=`date +'%M'` SEC=`date +'%S'` export SAVE_TO_DIR="$SCREENSHOT_DIR/$YEAR.$MONTH.$DAY" mkdir -p "$SAVE_TO_DIR" #Will generate jpg files FILE_NAME=$(scrot '%H.%M.%S_$wx$h.jpg' -e 'echo $f ; mv $f \$SAVE_TO_DIR' -q $IMAGE_QUALITY -z) #This will generate png files #FILE_NAME=$(scrot '%H.%M.%S_$wx$h.png' -e 'echo $f ; mv $f \$SAVE_TO_DIR' -q $IMAGE_QUALITY -z) #Now see if the file is a "Aw, Snap! Something went wrong while displaying this #webpage." error. They are usually 36694 bytes long FILE_SIZE=$(wc -c "$SAVE_TO_DIR/$FILE_NAME" | awk '{print $1}') CHROMIUM_ERROR_SIZE=36694 if [ "$FILE_SIZE" -eq "$CHROMIUM_ERROR_SIZE" ] ; then echo "Restarting x on $DAY.$MONTH.$YEAR at $HOUR:$MIN:$SEC" | tee -a $LOG_FILE /home/pi/startx else echo "X wasn't restarted" fi