Skip to content
Snippets Groups Projects
Commit e7038f6d authored by rs11g21's avatar rs11g21
Browse files

Completed version (implemented extra error handling)

parent 43f57359
No related branches found
No related tags found
No related merge requests found
#! /usr/bin/bash
output=$(/opt/lampp/bin/mysql -u root -e"USE cryptoTracker; SELECT * FROM crypto;" --skip-column-names 2>&1)
status=$?
if [ $status -ne 0 ]; then
echo "MySQL error: $output"
else
echo "MySQL working."
if [ "$(curl -s -o /dev/null -w "%{http_code}" http://www.google.com/)" -eq "200" ]; then
echo "XAMPP's Apache server is connected to the internet."
awk -F':' '{
if(/BitCoin Value/){
cmd = "/opt/lampp/bin/mysql -u root -e \"USE cryptoTracker; INSERT INTO cryptoPrice(cryptoID,value,collected) VALUES (1, " $2 ",'\''" strftime("%Y-%m-%d %H:%M:%S") "'\'')\""
system(cmd)
}else if(/BitCoin 24 Hour Low/){
cmd = "/opt/lampp/bin/mysql -u root -e \"USE cryptoTracker; INSERT INTO lowPrice(cryptoID,value,collected) VALUES (1, " $2 ",'\''" strftime("%Y-%m-%d %H:%M:%S") "'\'')\""
system(cmd)
}else if(/BitCoin 24 Hour High/){
cmd = "/opt/lampp/bin/mysql -u root -e \"USE cryptoTracker; INSERT INTO highPrice(cryptoID,value,collected) VALUES (1, " $2 ",'\''" strftime("%Y-%m-%d %H:%M:%S") "'\'')\""
system(cmd)
}else if(/BitCoin 24 Hour Open/){
cmd = "/opt/lampp/bin/mysql -u root -e \"USE cryptoTracker; INSERT INTO openPrice(cryptoID,value,collected) VALUES (1, " $2 ",'\''" strftime("%Y-%m-%d %H:%M:%S") "'\'')\""
system(cmd)
}else if(/BitCoin Market Cap/){
cmd = "/opt/lampp/bin/mysql -u root -e \"USE cryptoTracker; INSERT INTO marketCap(cryptoID,value,collected) VALUES (1, " $2 ",'\''" strftime("%Y-%m-%d %H:%M:%S") "'\'')\""
system(cmd)
}else if(/BitCoin Change In Value/){
cmd = "/opt/lampp/bin/mysql -u root -e \"USE cryptoTracker; INSERT INTO changeInValue(cryptoID,value,collected) VALUES (1, " $2 ",'\''" strftime("%Y-%m-%d %H:%M:%S") "'\'')\""
system(cmd)
}else if(/BitCoin Return Percentage/){
cmd = "/opt/lampp/bin/mysql -u root -e \"USE cryptoTracker; INSERT INTO returnPercentage(cryptoID,value,collected) VALUES (1, " $2 ",'\''" strftime("%Y-%m-%d %H:%M:%S") "'\'')\""
system(cmd)
}else if(/BitCoin Volatility/){
cmd = "/opt/lampp/bin/mysql -u root -e \"USE cryptoTracker; INSERT INTO volatility(cryptoID,value,collected) VALUES (1, " $2 ",'\''" strftime("%Y-%m-%d %H:%M:%S") "'\'')\""
system(cmd)
}else if(/BitCoin 24 H Transaction Count/){
cmd = "/opt/lampp/bin/mysql -u root -e \"USE cryptoTracker; INSERT INTO transactionCount(cryptoID,value,collected) VALUES (1, " $2 ",'\''" strftime("%Y-%m-%d %H:%M:%S") "'\'')\""
system(cmd)
}else if(/BitCoin Transaction Fee/){
cmd = "/opt/lampp/bin/mysql -u root -e \"USE cryptoTracker; INSERT INTO transactionFee(cryptoID,value,collected) VALUES (1, " $2 ",'\''" strftime("%Y-%m-%d %H:%M:%S") "'\'')\""
system(cmd)
}
}' < /dev/stdin
else
echo "XAMPP's Apache server is not connected to the internet."
fi
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment