Generate Browser Screenshots With Google Chrome Ubuntu Bash Script

#!/bin/bash

# Script is written and developed by Mathew Moore
# https://NWDigital.cloud

time="$(date +%d%m%Y_%H%M%S)";

#setup some variables for the urls and save location folder
allit="https://yahoo.com";
engineering="https://northwoodsdigital.com";
website1="https://apple.com";
website2="https://microsoft.com";
service="https://google.com";
media="https://facebook.com";
health="https://twitter.com";
custom="$2";

folder="/var/www/html/kpi";

case "$1" in
  'all')
      # All Weekly Metrics
      url=$allit;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1855,1080 --screenshot="$folder/allit.jpg" $url --virtual-time-budget=5000 | pv -N "Generating All FCP IT - Weekly Metrics" -t;
      echo "All FCP IT - Weekly Metrics Generated"
      sleep 3;

      # Engineering - Weekly Metrics
      url=$engineering;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1855,1080 --screenshot="$folder/engineering.jpg" $url --virtual-time-budget=5000 | pv -N "Generating Engineering - Weekly Metrics" -t;
      echo "Engineering - Weekly Metrics generated"
      sleep 3;

      # Service Desk - Weekly Metrics
      url=$service;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1855,1080 --screenshot="$folder/service.jpg" $url --virtual-time-budget=5000 | pv -N "Generating Service Desk - Weekly Metrics" -t;
      echo "Service Desk - Weekly Metrics generated"
      sleep 3;

      # Media Team - Weekly Metrics
      url=$media;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1855,1080 --screenshot="$folder/media.jpg" $url --virtual-time-budget=5000 | pv -N "Generating Media Team - Weekly Metrics" -t;
      echo "Media Team - Weekly Metrics generated"
      sleep 3;

      # Health - Weekly Metrics
      url=$health;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1855,1080 --screenshot="$folder/health.jpg" $url --virtual-time-budget=5000 | pv -N "Generating Health IT - Weekly Metrics" -t;
      echo "Health IT - Weekly Metrics generated"
      sleep 3;

      # Website 30 Days Stats - generate image from PowerBI page
      url=$website1;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1920,1080 --screenshot="$folder/website1.jpg" $url --virtual-time-budget=5000 | pv -N "Generating FCP Website 1 KPI" -t;
      echo "Website 1 KPI generated"
      sleep 3;

      # Website 2 30 Days Stats - generate image from PowerBI page
      url=$website2;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1920,1080 --screenshot="$folder/website2.jpg" $url --virtual-time-budget=5000 | pv -N "Generating FCP Website 2 KPI" -t;
      echo "Website 2 KPI generated"
      sleep 3;

      # Email confirmation with Attachments
      cd /var/www/html/kpi;
      echo "New KPI's have been generated. See attached." | mail -a "From: CRN-WEB-02 KPIs <kpis@fcpotawatomi-nsn.gov>" -a "Subject: Generate KPI Status" -A "allit.jpg" -A "engineering.jpg" -A "service.jpg"  -A "media.jpg" -A "health.jpg" -A "website1.jpg" -A "website2.jpg" mathew.moore@fcpotawatomi.com; # for multiple recipients just separate with a space
      cd;

      echo "Email Confirmation Sent"
  ;;

  'allit')
      # All FCP IT - Weekly Metrics
      url=$allit;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1855,1080 --screenshot="$folder/$1.jpg" $url --virtual-time-budget=5000 | pv -N "Generating All FCP IT - Weekly Metrics" -t;
      echo "All FCP IT - Weekly Metrics Generated"
  ;;

  'engineering')
      # Engineering - Weekly Metrics
      url=$engineering;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1855,1080 --screenshot="$folder/$1.jpg" $url --virtual-time-budget=5000 | pv -N "Generating Engineering - Weekly Metrics" -t;
      echo "Engineering - Weekly Metrics generated"
  ;;

  'service')
      # Service Desk - Weekly Metrics
      url=$service;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1855,1080 --screenshot="$folder/$1.jpg" $url --virtual-time-budget=5000 | pv -N "Generating Service Desk - Weekly Metrics" -t;
      echo "Service Desk - Weekly Metrics generated"
  ;;

  'media')
      # Media Team - Weekly Metrics
      url=$media;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1855,1080 --screenshot="$folder/$1.jpg" $url --virtual-time-budget=5000 | pv -N "Generating Media Team - Weekly Metrics" -t;
      echo "Media Team - Weekly Metrics generated"
  ;;

  'health')
      # Health - Weekly Metrics
      url=$health;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1855,1080 --screenshot="$folder/$1.jpg" "$url" --virtual-time-budget=5000 | pv -N "Generating Health IT - Weekly Metrics" -t;
      echo "Health IT - Weekly Metrics generated"
  ;;

  'website1')
      # Website 1 - 30 Days Stats - generate image from PowerBI page
      url=$website1;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1920,1080 --screenshot="$folder/$1.jpg" $url --virtual-time-budget=5000 | pv -N "Generating FCP Website KPI" -t;
      echo "Website 1 KPI generated"
  ;;

  'website2')
      # Website 2 - 30 Days Stats - generate image from PowerBI page
      url=$website2;
      chromium-browser --headless --no-sandbox --disable-gpu --window-size=1920,1080 --screenshot="$folder/$1.jpg" $url --virtual-time-budget=5000 | pv -N "Generating FCP Website 2 KPI" -t;
      echo "Website 2 KPI generated"
  ;;

  'email')
      # Email confirmation with Attachments
      cd /var/www/html/kpi;
      echo "New KPI's have been generated. See attached." | mail -a "From: KPIs <kpis@northwoodsdigital.com>" -a "Subject: Generate KPI Status" -A "allit.jpg" -A "engineering.jpg" -A "service.jpg"  -A "media.jpg" -A "health.jpg" -A "website1.jpg" -A "website2.jpg" your_email@your_domain.com; # for multiple recipients just separate with a space
      cd;

      echo "Email Confirmation Sent"
  ;;

  '')
      echo "Usage: $0[all|allit|engineering|service|media|health|website1|website2|email]"
  ;;
esac

chmod -R 775 $folder;

Leave a Comment