Shell Script-page static

Source: Internet
Author: User
Tags curl gettext

Real needs:

For some pages that are not real-time, the data changes are not very large pages, we can make this JSP or Freemark page static.

Such a benefit, when our service hangs up, through Nginx's agent, we can still access the relevant page.


Realize:

Through the shell script and the Linux crontab Timer task implementation. This is just about how to implement the script.


1. First we will learn to use the Curl script:


Download a single file and print the output to standard output (STDOUT) by default

Curl http://www.centos.org


Save the downloaded file to the specified file with the-o/-o option:

-O: Save the file as the file name specified on the command line

-O: Save the file to local using the default file name in the URL

# Download the file locally and name it mygettext.html

Curl-o mygettext.html http://www.gnu.org/software/gettext/manual/gettext.html

# Save the file locally and name it gettext.html

Curl-o http://www.gnu.org/software/gettext/manual/gettext.html

Example 1:index.sh the specific script is as follows: Description:1.http://127.0.0.1:8082/index?clean=true  is a JSP page provided by our native container service. 2.status1 ,status2,status3,status  is to determine whether the JSP page returned by the service is legitimate,   is implemented according to your JSP page. Because once the JSP page is wrong, returning the wrong page overwrites the good page,   static is meaningless. The 3.cp ,mv  operation is to back up and overwrite the current static page. For simple usage of   4.sed, the operation of SED is not necessary. http://www.cnblogs.com/dong008259/archive/2011/12/07/2279897.html#!/bin/sh#resin index#/opt/www/pages/ Index.tmp#index pagehttp_code= ' Curl -o /opt/www/pages/index.tmp -s -w %{http_ Code} http://127.0.0.1:8082/index?clean=true ';if [ ${http_code} -eq 200 ]     then    status1= ' Cat /opt/www/pages/index.tmp |grep -o   "Content_item" |wc -l '     status2= ' Cat /opt/www/pages/index.tmp |grep  -o  "Photocdn" |wc -l '     status3= ' cat /opt/www/pages/index.tmp | grep -o   "Focus" |wc -l ' &NBsp;   status= ' cat /opt/www/pages/index.tmp |grep -o  "Data-columnid" |WC  -l '    # echo  ' ${status1},${status2},${status3},${status} '      if [ ${http_code} -eq 200 ] && [ ${status} -ge  15 ] && [ ${status1} -ge 80 ] && [ ${ status2} -ge 80 ] && [ ${status3} -ge 1 ]         then         date= ' date  + "%y-%m-%d-%h-%m" ';         cp /opt/www/pages/index.html /opt /www/pages/index.${date};        mv /opt/www/pages/index.tmp  /opt/www/pages/index.html;         #debug_str = ' <!--' Date  + "%y-%m-%d-%h-%m"          #sed  -i  ' 1a\ ' ${debug_str} /opt/www/pages/index.html      else        echo  "Build index  ${status} ${status2} ${status3} fail "    fi; else     echo  "build index fail!"; Fi
Example 2: Statically related sub-pages, test2.sh#!/bin/sh#pgc page cids= (70040000 70080000 70060000 70070000  70090000 70120000 70100000 70110000 71010000 71020000 71030000  71060000 71050000 71040000 71070000 71080000 71090000 71100000 71220000  71110000 71120000 71230000 71130000 71140000 71150000 71160000  71170000 71180000 71200000 71260000 71270000) i=0length=${#cids [*]}while [  $i  -lt  $length  ] ; do    cid=${cids[$i]}     Http_code= ' curl -o /opt/www/pages/pgc$cid.tmp -s -w %{http_code} http:// 127.0.0.1:8082/pgc/$cid clean=true ';     status= ' cat /opt/www/pages/pgc$cid.tmp | grep -o  "Data-columnid" |wc -l '     if [ ${http_code} -eq  200 ] && [ ${status} -ge 1 ]        then         date= ' date + "%y-%m-%d-%h-%m";         if [  -f /opt/www/pages/pgc$cid.html ]             then            cp /opt/www/pages /pgc$cid.html /opt/www/pages/pgc$cid.${date};        fi;         mv /opt/www/pages/pgc$cid.tmp /opt/www/pages/pgc$cid.html;         debug_str= ' <!--' date + "%y-%m-%d-%h-%m" and "         sed -i  ' 1a\ ' ${debug_str} /opt/www/pages/pgc$cid.html      else        echo  "build hots$ cid fail! " &nBsp;   fi;    let i++done 
Example 3:test3.sh#!/bin/sh#hots page  #精选: hots128.html     funny:hots132.html      #福利:hots133.html     News: hots129.html    # Entertainment:hots130.html     Sports:hots131.html     #一分钟:hots134.html     World Cup: hots177.html#: hots164.html#son hots249.htmlcids= (128 132 129 130 131  223 224 225 134 164 249) i=0length=${#cids [*]}while [  $i  -lt   $length  ] ; do    cid=${cids[$i]}    http_code= ' curl -o /opt/www/pages/hots$cid.tmp -s -w %{http_code} http://127.0.0.1:8082/ hots/$cid? clean=true ';    if [ ${http_code} -eq 200 ]         then        date= ' date + '%Y-% M-%d-%h-%m "';         if [ -f /opt/www/pages/hots$cid.html ]             then             cp /opt/www/pages/hots$cid.html /opt/www/pages/hots$cid.${date};         fi;        mv /opt/www/pages/hots$cid.tmp  /opt/www/pages/hots$cid.html;        debug_str= ' <!--' Date  + "%y-%m-%d-%h-%m" "--        sed -i  ' 1a\ ' ${debug_ str} /opt/www/pages/hots$cid.html     else         echo  "build hots$cid fail!"     fi;    let i++done
 Example 4: For example, the head and tail of a generic reference to our website, always change,        We can not change JSP every time to go online. These can have the website of the editing maintenance,        we regularly download the relevant documents just fine.  #!/bin/shwget http://tv.baidu.com/s2012/frag/83/20092861_344978361.inc -q -o /opt/ www/h5-server/web-inf/includes/footer_tmp.jsp >/dev/null 2>&1cd /opt/www/h5-server/ Web-inf/includes/iconv -f gb2312 -t utf-8 footer_tmp.jsp -o footer.jsprm  -rf footer_tmp.jsp       Example 5: If we want to refresh an interface on a timed basis, or periodically let some data flash into the cache. We can also do a timed task of the script, timed execution of the script. #!/bin/shcurl -o /tmp/cooperation.tmp http://localhost:8082/cooperation/listall.json?clean=true  > /dev/null 2>&1exit 0 
Example 8:test8#!/bin/shwget http://tv.baidu.com/s2013/frag/78/120173_381017846.inc-q-o/opt/www/h5-server/web-inf/ includes/navproms_tmp.jsp >/dev/null 2>&1cd/opt/www/h5-server/web-inf/includes/iconv-f gbk-t UTF-8 Navproms_tmp.jsp-o navproms.jspsed-i ' 1i<%@ page language=\ "java\" pageencoding=\ "utf-8\" contentType=\ "text/html ; charset=utf-8\ "%> '/opt/www/h5-server/web-inf/includes/navproms.jsp#yes|cp-af/opt/www/h5-server/web-inf/ INCLUDES/NAVPROMS.JSP/OPT/WWW/HOTHTML5/WEB-INF/INCLUDES/NAVPROMS.JSPRM-RF navproms_tmp.jsp


This article is from the "My Java World" blog, so be sure to keep this source http://hanchaohan.blog.51cto.com/2996417/1834727

Shell Script-page static

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.