check_shib.sh

Keep an eye on the price of SHIB.
 avatar
unknown
plain_text
4 years ago
2.0 kB
6
Indexable
#!/bin/bash

# Set up local script variables
    function DEFINE_VARIABLES {
        TODAYS_DATE=$(date +"%m-%d-%Y");
		SHIB_WGET_FILE="/tmp/shib.html";
    }

# Set up a lock to prevent this script from running on top of itself if executed via cron
    function SETUP_LOCK {
        SCRIPT_FILE_NAME=`echo $(basename $0) | sed 's/\..*$//'`;
        LOCK_FILE=/var/lock/$SCRIPT_FILE_NAME.lock;
        touch $LOCK_FILE;
        read lastPID < $LOCK_FILE;
        [ ! -z "$lastPID" -a -d /proc/$lastPID ] && echo "" && echo "# There is another copy of this script currently running. Exiting now for safety purposes." && exit 1
        echo $BASHPID > $LOCK_FILE;
    }

# Define the script exit function to clean up
    function FINISH {
        [ -e "${SHIB_WGET_FILE}" ] && rm "${SHIB_WGET_FILE}";
    }
    trap FINISH EXIT

# Define the main script function
    function CHECK_SHIB {
        
        # Download a copy of crypto.com's SHIB page to parse and check what the price currently is.
            wget -q -O "${SHIB_WGET_FILE}" "https://crypto.com/price/shiba-inu";
        
        # Determine the number of times to run the loop
            LOOP_COUNT=$(grep -o -i "aria-valuetext=" "${SHIB_WGET_FILE}" | wc -l);
            LOOP_START=1;

        # Loop through the html, parsing for the SHIB value.
            while [ $LOOP_START -ne $LOOP_COUNT ]; do
                LOOP_START=$(($LOOP_START+1));
                SHIB_VALUE=$(cat "${SHIB_WGET_FILE}" | awk -F 'aria-valuetext="' "{ print \$${LOOP_START} }" | awk -F '"' '{ print $1 }' | xargs);
                if [ "$SHIB_VALUE" == "1.00" ]; then
                    :; # This isn't a real value we are searching for. If it hits a dollar, we will surely know.
                else
                    echo "Shib value is: ${SHIB_VALUE}";
                fi
            done

    }
    
# Call all of the script functions
    DEFINE_VARIABLES;
    SETUP_LOCK;
    CHECK_SHIB;
Editor is loading...