Strange Bash script error

Source: Internet
Author: User

As a result of the work, write a script, the function of the script is to implement:

There are two. txt files, which contain some domain names, and then from these two. txt files, randomly remove a domain name, written to the shiting.htm and xiazai.htm files inside.

The script has been written, the grammar has been measured, no problem, the test passed in the virtual machine, no problem. But a copy into the production environment, there is a big problem. Tangled up my two days, now finally got the solution, now summarized below, lest make the same mistake again.

The script is as follows:

#!/bin/bash # 
Author:honway.liu # 
date:2012-06-01 #
     
Define location file 
yyxz=/data/cdn/xiazai.txt 
yyst=/data/cdn/shiting.txt 
#xiazai =/data/api/xiazai.htm 
#shiting =/data/api/shiting.htm 
Xiazai =/tmp/xiazai.htm 
shiting=/tmp/shiting.htm 
log=/tmp 
     
# Xiazai & shiting file line number 
xznm=$ (wc-l $yyxz |awk ' {print} ') 
stnm=$ (wc-l $yyst |awk ' {print} ') 
     
# Random for Xiazai & shiting 
down=$[$RANDOM% $xznm +1] 
listen=$[ $RANDOM% $stnm +1] 
     
# get Xiazai & shiting domain name 
xzym=$ (sed-n ${down}p $yyxz) 
stym=$ (Sed-n ${list En}p $yyst) 
     
# Write domain name into HTM files. 
Echo-n $xzym > $xiazai 
echo-n $stym > $shiting 
     
# out put logs 
echo "The $xzym at ' date + '%F%T ' is Provided ">>/$log/xiazai_domain.log 
echo" The $stym at ' date + '%F%T ' to provided ' >>/$log/shiting_dom Ain.log 
     
Exit 0

This column more highlights: http://www.bianceng.cn/OS/Linux/

Grammar checking is fine, but when it's done, it's messy.

The last mistake above is because exit0 has no spaces. See the results of the SED is OK, but the contents of the variable is a mess, people have a headache. Look at the results of the output

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.