Skip to content

Instantly share code, notes, and snippets.

@Sydney-o9
Last active February 2, 2018 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sydney-o9/47984765d029f74334b9ee6468e36cbf to your computer and use it in GitHub Desktop.
Save Sydney-o9/47984765d029f74334b9ee6468e36cbf to your computer and use it in GitHub Desktop.
# @Author Jobinhood
BV_GREEN_TICK='\e[0;32m [✔] \e[0m';
BV_RED_CROSS='\e[0;91m [✗] \e[0m';
BV_YELLOW_DOT='\e[0;33m [.] \e[0m';
BV_YELLOW_DOTS='\e[0;33m ... \e[0m';
# Helper to run sudo commands for us by asking
# sudo password if needed
sudo_needed() {
# Check if user can use sudo
if [ $(sudo -n uptime 2>&1|grep "load"|wc -l) = 0 ]; then
# If not, ask for sudo password
printf "\e[0;33m This script must be run as root, enter your password. \e[0m\n" 1>&2
sudo -l > /dev/null
fi
}
# Start Selenium Server
# @param printStatus 0|1 Whether to print status or not
# Set to 1 by default.
start_selenium() {
printStatus=${1:-1}
sudo_needed;
printf "$BV_YELLOW_DOT Starting selenium server $BV_YELLOW_DOTS \n"
sudo launchctl load /Library/LaunchDaemons/org.seleniumhq.selenium.plist > /dev/null;
if [[ $printStatus = 1 ]]; then
status_selenium;
fi
}
# Stop Selenium Server
# @param printStatus 0|1 Whether to print status or not
# Set to 1 by default.
stop_selenium() {
printStatus=${1:-1}
sudo_needed;
printf "$BV_YELLOW_DOT Stopping selenium $BV_YELLOW_DOTS \n"
sudo launchctl unload /Library/LaunchDaemons/org.seleniumhq.selenium.plist > /dev/null;
if [[ $printStatus = 1 ]]; then
status_selenium;
fi
}
# Status Selenium Server
status_selenium() {
if [ $# -eq 1 ]; then
if [ "$1" != "-v" ]; then
printf "$BV_RED_CROSS Option $1 not recognised. Only -v exists. \n"
fi
fi
if [[ $(ps -ef | grep selenium | grep java | grep chromedriver | grep -v grep | grep -c selenium) -ge 1 ]]; then
printf "$BV_GREEN_TICK selenium running. \n"
if [[ $1 = '-v' ]]; then
ps aux | grep selenium | grep java | grep chromedriver | grep -v grep;
fi
else
printf "$BV_RED_CROSS selenium NOT running. \n"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment