
之前自己寫下的 CentOS 7 安裝教學,其中一部份是關於 MySQL。最近想試用 MariaDB,發現原本 CentOS 7 已跟機附有,而 MariaDB 及 MySQL 只能二擇其一,所以得要刪除 MySQL。方法是:
yum remove mysql-community-client mysql-community-common mysql-community-server
My studies, development and creations on Robotics, iPhone Apps, Andriod Apps,...etc.
#!/bin/bash ##---------------------------------------------------------------------------------------- ## Packt Free eBook Downloader ##---------------------------------------------------------------------------------------- ## Platform: CentOS7 + bash ## Written by Pacess ## Copyright 2016 Pacess Studio. All rights reserved. ##---------------------------------------------------------------------------------------- ##---------------------------------------------------------------------------------------- ## Update History: ##---------------------------------------------------------------------------------------- ## 2016.08.25 ## - Added auto commit to GitLab ##---------------------------------------------------------------------------------------- ## Variables userID="sita@chan.com" password="Sita0310" timeOut=5 noOfRetry=3 sleepTimeBetweenRequest=1 userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36" downloadDirectory="/Users/pacessho/MEGA/eBooks" log="packt_igustin.log" cookie="cookie.txt" ##---------------------------------------------------------------------------------------- function PHLog { echo "$1" echo "$(date '+%Y-%m-%d %H:%M:%S') $1" >> "$log" } ##---------------------------------------------------------------------------------------- ## Program start echo "$(date '+%Y-%m-%d %H:%M:%S')" echo "-----------------------------------------------------------" echo "-- Packt Free eBook Downloader Version 1.10 --" echo "-- Written by Pacess --" echo "-- Copyright 2016 Pacess Studio. All rights reserved. --" echo "-----------------------------------------------------------" echo "" ## Move to home directory first cd /root/PacktDownloader ## Remove previous temp file rm -f $cookie packt*.html ##---------------------------------------------------------------------------------------- ## Website login PHLog "Logging in $userID..." curl -s --retry $noOfRetry -m $timeOut -A "$userAgent" -b "$cookie" -c "$cookie" -d "email=$userID" -d "password=$password" -d "op=Login" -d "form_build_id=form-73ba86bbfb2a50719049129632c84810" -d "form_token=2f1d586bf7df196b77d0761709d03199" -d "form_id=packt_user_login_form" https://www.packtpub.com errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } curl -s --retry $noOfRetry -m $timeOut -A "$userAgent" -b "$cookie" -c "$cookie" https://www.packtpub.com/packt/offers/free-learning > packt_daily.html errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } ##---------------------------------------------------------------------------------------- ## Extract claim URL claim=$(grep -oE "freelearning-claim/[0-9]+/[0-9]+" packt_daily.html) PHLog "Claim URL: $claim" ## Extract book title, trim and remove invalid characters title=$(grep "dotd-title" -A 2 packt_daily.html | tail -1 | sed 's/^[^0-9A-Za-z]*//;s/[\t ]*<\/h2>$//') title="$(echo -e "${title}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/[^A-Za-z0-9 ._-]//g')" PHLog "eBook Found: $title" ## Extract book ID bookID=$(echo $claim | sed "s/.*\/\([0-9]*\)\/.*/\1/") echo ""; ## Claim ebook now curl -s --retry $noOfRetry -m $timeOut -A "$userAgent" -b "$cookie" -c "$cookie" -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.5' -H 'Connection: keep-alive' -H 'Host: www.packtpub.com' -H 'Referer: https://www.packtpub.com/packt/offers/free-learning' "https://www.packtpub.com/$claim" errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } ##---------------------------------------------------------------------------------------- ## Download PDF version PHLog "Downloading PDF...$title.pdf" curl -s -L --retry $noOfRetry -A "$userAgent" -b "$cookie" -c "$cookie" "https://www.packtpub.com/ebook_download/$bookID/pdf" > "$downloadDirectory/$title.pdf" errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } ## Download EPUB version PHLog "Downloading EPUB...$title.epub" curl -s -L --retry $noOfRetry -A "$userAgent" -b "$cookie" -c "$cookie" "https://www.packtpub.com/ebook_download/$bookID/epub" > "$downloadDirectory/$title.epub" errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } ## Download MOBI version PHLog "Downloading MOBI...$title.mobi" curl -s -L --retry $noOfRetry -A "$userAgent" -b "$cookie" -c "$cookie" "https://www.packtpub.com/ebook_download/$bookID/mobi" > "$downloadDirectory/$title.mobi" errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } ##---------------------------------------------------------------------------------------- ## Job done, log out now PHLog "Logging out..." curl -s --retry $noOfRetry -m $timeOut -A "$userAgent" -b "$cookie" -c "$cookie" https://www.packtpub.com/logout > packt_logout.html errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } ## Remove temporary file rm -f $cookie packt*.html echo "" >> "$log" ##---------------------------------------------------------------------------------------- ## Commit to GitLab PHLog "Commiting to GitLab..." git config --global user.name "Sita Chan" git config --global user.email "sita@pacess.com" git add * git commit -m "Added '$title'" git push -u origin master ##---------------------------------------------------------------------------------------- ## Send email alert echo -e "Dear Pacess,\n\nA Packt ebook '$title' have been downloaded and commit to GitLab. Thanks!\n\nSita-bot" | mail -r "sita@pacess.com (Sita-bot)" -s "[GitLab] Added Packt ebook '$title'..." pacess@pacess.com
Host 192.168.1.100 Hostname 192.168.1.100 PreferredAuthentications publickey IdentityFile ~/.ssh/centos7_vm/id_rsa Host 54.230.73.94 Hostname 54.230.73.94 PreferredAuthentications publickey IdentityFile ~/.ssh/viu.tv/id_rsa Host 69.58.186.114 Hostname 69.58.186.114 PreferredAuthentications publickey IdentityFile ~/.ssh/ikea.com.hk/id_rsa
#!/bin/bash ##---------------------------------------------------------------------------------------- ## Packt Free eBook Downloader ##---------------------------------------------------------------------------------------- ## Platform: macOS + bash ## Written by Pacess ## Copyright 2016 Pacess Studio. All rights reserved. ##---------------------------------------------------------------------------------------- ## Variables userID="sita@chan.com" password="Sita0310" timeOut=5 noOfRetry=3 sleepTimeBetweenRequest=1 userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36" downloadDirectory="/Users/pacessho/MEGA/eBooks" log="packt_igustin.log" cookie="cookie.txt" ##---------------------------------------------------------------------------------------- function PHLog { echo "$1" echo "$(date '+%Y-%m-%d %H:%M:%S') $1" >> "$log" } ##---------------------------------------------------------------------------------------- ## Program start echo "-----------------------------------------------------------" echo "-- Packt Free eBook Downloader Version 1.00 --" echo "-- Written by Pacess --" echo "-- Copyright 2016 Pacess Studio. All rights reserved. --" echo "-----------------------------------------------------------" echo "" ## Remove previous temp file rm -f $cookie packt*.html ##---------------------------------------------------------------------------------------- ## Website login PHLog "Logging in..." curl -s --retry $noOfRetry -m $timeOut -A "$userAgent" -b "$cookie" -c "$cookie" -d "email=$userID" -d "password=$password" -d "op=Login" -d "form_build_id=form-73ba86bbfb2a50719049129632c84810" -d "form_token=2f1d586bf7df196b77d0761709d03199" -d "form_id=packt_user_login_form" https://www.packtpub.com errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } curl -s --retry $noOfRetry -m $timeOut -A "$userAgent" -b "$cookie" -c "$cookie" https://www.packtpub.com/packt/offers/free-learning > packt_daily.html errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } ##---------------------------------------------------------------------------------------- ## Extract claim URL claim=$(grep -oE "freelearning-claim/[0-9]+/[0-9]+" packt_daily.html) PHLog "Claim URL: $claim" ## Extract book title, trim and remove invalid characters title=$(grep "dotd-title" -A 2 packt_daily.html | tail -1 | sed 's/^[^0-9A-Za-z]*//;s/[\t ]*<\/h2>$//') title="$(echo -e "${title}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/[^A-Za-z0-9 ._-]//g')" PHLog "eBook Found: $title" ## Extract book ID bookID=$(echo $claim | sed "s/.*\/\([0-9]*\)\/.*/\1/") echo ""; ## Claim ebook now curl -s --retry $noOfRetry -m $timeOut -A "$userAgent" -b "$cookie" -c "$cookie" -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.5' -H 'Connection: keep-alive' -H 'Host: www.packtpub.com' -H 'Referer: https://www.packtpub.com/packt/offers/free-learning' "https://www.packtpub.com/$claim" errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } ##---------------------------------------------------------------------------------------- ## Download PDF version PHLog "Downloading PDF...$title.pdf" curl -s -L --retry $noOfRetry -A "$userAgent" -b "$cookie" -c "$cookie" "https://www.packtpub.com/ebook_download/$bookID/pdf" > "$downloadDirectory/$title.pdf" errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } ## Download EPUB version PHLog "Downloading EPUB...$title.epub" curl -s -L --retry $noOfRetry -A "$userAgent" -b "$cookie" -c "$cookie" "https://www.packtpub.com/ebook_download/$bookID/epub" > "$downloadDirectory/$title.epub" errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } ## Download MOBI version PHLog "Downloading MOBI...$title.mobi" curl -s -L --retry $noOfRetry -A "$userAgent" -b "$cookie" -c "$cookie" "https://www.packtpub.com/ebook_download/$bookID/mobi" > "$downloadDirectory/$title.mobi" errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } ##---------------------------------------------------------------------------------------- ## Job done, log out now PHLog "Logging out..." curl -s --retry $noOfRetry -m $timeOut -A "$userAgent" -b "$cookie" -c "$cookie" https://www.packtpub.com/logout > packt_logout.html errorCode=$?; test "$errorCode" -ne "0" && { PHLog "curl exit error code: $errorCode"; exit; } ## Remove temporary file rm -f $cookie packt*.html echo "" >> "$log"
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.pacess.cronjob</string> <key>Program</key> <string>/Users/pacess/cronjob.sh</string> <key>StartCalendarInterval</key> <dict> <key>Hour</key> <integer>12</integer> <key>Minute</key> <integer>00</integer> </dict> <key>StandardOutPath</key> <string>/Users/pacess/cronjob.log</string> </dict> </plist>
<key>StartInterval</key> <integer>7200</integer>
#!/bin/bash now=$(date +"%D %T") echo "$now - Start cronjob.sh" export PATH=/usr/local/bin:$PATH /usr/local/bin/casperjs ~/cronjob.js now=$(date +"%D %T") echo "$now - End cronjob.sh"
//---------------------------------------------------------------------------------------- // Packt Free eBook Downloader //---------------------------------------------------------------------------------------- // Platform: macOS + PhantomJS + CasperJS + Javascript // Written by Pacess // Copyright 2016 Pacess Studio. All rights reserved. //---------------------------------------------------------------------------------------- var casper = require("casper").create(); // Load free ebook page var host = "https://www.packtpub.com"; var url = host+"/packt/offers/free-learning"; casper.start(url); // Once page loaded, login first casper.then(function() { this.echo("Logging in..."); this.fillSelectors("#packt-user-login-form-respo", { "#email": "sita@chan.com", "#password": "Sita0310" }, true); }); // Once login, then extract claim URL casper.then(function() { this.echo("Extracting claim URL..."); url = ""; var html = this.getHTML(); var index = html.search("/freelearning-claim/"); this.echo("Index: "+index); if (index >= 0) { // Claim pattern found var link = html.substring(index, index+40); index = link.search("\""); if (index >= 0) { // Construct complete claim URL url = host+link.substring(0, index); this.echo("Claim URL: "+url); casper.thenOpen(url, function() { this.echo("URL: "+this.getCurrentUrl()); }); } } }); // If there is error, log it out casper.on("error", function(msg, backtrace) { this.echo("### "+msg); throw new ErrorFunc("fatal", "error", "filename", backtrace, msg); }); // Run above script now! casper.run();
<?php //---------------------------------------------------------------------------------------- // Scriptable Browser Test //---------------------------------------------------------------------------------------- // Written by Pacess HO // Copyright 2016 Pacess Studio. All rights reserved. //---------------------------------------------------------------------------------------- require_once("simpletest/browser.php"); //---------------------------------------------------------------------------------------- function packt() { $url = "https://www.packtpub.com/packt/offers/free-learning"; $browser = new SimpleBrowser(); //---------------------------------------------------------------------------------------- // Load first page $content = $browser->get($url); $count = strlen($content); if ($count < 200) {echo("### Cannot load URL: $url..."); exit(0);} $content2 = $browser->click("Log in"); if ($content == $content2) {echo("### Content not loaded..."); exit(0);} //---------------------------------------------------------------------------------------- // Fill in account information $success = $browser->setFieldById("email", "sita@chan.com"); if ($success != true) {echo("### Cannot found email field..."); exit(0);} $success = $browser->setFieldById("password", "Sita0310"); if ($success != true) {echo("### Cannot found password field..."); exit(0);} //---------------------------------------------------------------------------------------- // Login now! $content = $browser->click("Login"); $url = $browser->getUrl(); echo("URL:[$url]"); //---------------------------------------------------------------------------------------- // Redeem a book $browser->click("Claim Your Free eBook"); $url2 = $browser->getUrl(); echo("URL:[$url2]"); echo("Done!"); } //======================================================================================== packt(); ?>結果還是不行。估計是因為網頁內的 Javascript 沒有執行。我嘗試過編寫一個簡單的網頁,有兩個 HTML 檔。第一個做轉向,另一個才是有內容。結果是內容只停留在轉向那頁。看來以 SimpleTest 來測試簡單的網頁是非常方便;若中間有動態內容時,SimpleTest 未必能成功處理。