|
|
第 151 帖 | ||
|
|
标题: 下载的那个页面 要转码,不然的话 echo "没有该城市的天气讯息!" 引用:
wget下面加一句: iconv -f GB2312 -t UTF-8 index.shtml > index.shtml1 下面的 index.shtml 改为: index.shtml1 最后面 加一句: rm -f index.shtml1 |
||
|
|
|
||
|
|
第 152 帖 | |
|
|
#/bin/bash
#author : cppgp #function: replace string #time : 2007 08 17 08:45 if [ ! -n "$3" ] then echo echo echo -e " Usage:" echo -e "\t`basename $0` need three parameters at least" echo -e "\tand the parameters like as : source dest replace.txt" echo -e "\tand wildcard can be used in filename , like as : source dest *.txt!" echo echo exit 127 fi echo echo "source =$1" echo "dest =$2" echo echo "replace begin......." echo echo #protect-self scriptself=${0##*/} index=1 for arg in "$@" do { if [ "$index" -gt 2 -a $arg != $scriptself ] then echo "now replace file $arg ......" sed "s/$1/$2/" $arg -i.bak fi let "index+=1" } done echo echo echo "replace finish ....." echo exit 0 ############################# #以下是使用说明 ############################# 替换脚本使用说明 本文档假设该脚本已经以 replace.sh 保存 1.使用说名: 1).脚本使用命令行参数来实现替换及待替换文件 2).参数表如下: replace.sh 源串 目的串 文件1 文件2 ... 文件n 其中文件可以有任意多个,文件名中可以有通配符 3).执行任何以次操作之后,都会将原文件备份成 filename.bak 2.使用案例 1).假设在当前文件夹下有 index.html,001.html,002.html,003.txt,004.h,005.cpp 六个文件 想替换 index.html 中的 211.157.99.197 成 211.157.104.136 那么替换命令如下: ./replace.sh 211.157.99.197 211.157.104.136 index.html 同时会替换对应字符串且备份 index.html 为 index.html.bak 2).假设在当前文件夹下有 index.html,001.html,002.html,003.txt,004.h,005.cpp 六个文件 想替换 index.html , 001.html , 002.html 中的 211.157.99.197 成 211.157.104.136 那么替换命令如下: ./replace.sh 211.157.99.197 211.157.104.136 index.html 001.html 同时会替换对应字符串且备份 index.html 为 index.html.bak 同时会替换对应字符串且备份 001.html 为 001.html.bak 3).假设在当前文件夹下有 index.html,001.html,002.html,003.txt,004.h,005.cpp 六个文件 想替换所有文件名以.html结尾的文件中的 211.157.99.197 成 211.157.104.136 那么替换命令如下: ./replace.sh 211.157.99.197 211.157.104.136 *.html 同时会替换对应字符串且备份 index.html 为 index.html.bak 同时会替换对应字符串且备份 001.html 为 001.html.bak 同时会替换对应字符串且备份 002.html 为 002.html.bak 4).假设在当前文件夹下有 index.html,001.html,002.html,003.txt,004.h,005.cpp 六个文件 想替换所有文件中的 211.157.99.197 成 211.157.104.136 那么替换命令如下: ./replace.sh 211.157.99.197 211.157.104.136 * 同时会替换对应字符串且备份 index.html 为 index.html.bak 同时会替换对应字符串且备份 001.html 为 001.html.bak 同时会替换对应字符串且备份 002.html 为 002.html.bak 同时会替换对应字符串且备份 003.txt 为 003.txt.bak 同时会替换对应字符串且备份 004.h 为 004.h.bak 同时会替换对应字符串且备份 005.cpp 为 005.cpp.bak 3.附注: 欢迎对本脚本提出批评建议;任何时间可以用email或者TQ联系我! TQ : 8069002 Email : cppgp@163.com cppgp 2007-08-17 |
|
|
|
|
|
|
|
第 153 帖 | |
|
|
标题: 为方便在Ubuntu下使用Drcom而编的SHELL 源代码如下
Drcom文件: 代码:
为该文件添加可执行选项 sudo chown -R root:root /opt/Drcom sudo chmod -R 755 /opt/Drcom 向主菜单的应用程序下的网络项目下添加快捷方式 sudo gedit /usr/share/applications/Drcom.desktop 在新增的文件Drcom.desktop内加入下面这几行 代码:
此帖于 07-10-06 00:06 被 天涯海客 编辑. |
|
|
|
|
|
|
|
第 154 帖 | ||
|
|
引用:
为何我看不到附件? |
||
|
|
|
||
|
|
第 155 帖 | ||
|
|
引用:
为何我看不到附件? |
||
|
|
|
||
|
|
第 156 帖 | |
|
|
for ((i=0;i<=100;i++));do printf "["; for ((j=0;j<=$i;j++));do printf ">";done;for ((k=0;k<=100-$j;k++));do printf " ";done ;printf "] $i%%\r";sleep 0.1;done;echo ""
我写的进度条,赫赫。 |
|
|
|
|
|
|
|
第 157 帖 | |
|
|
超级简单的程序。 mac2unix.
#! /bin/sh for x do echo "Converting $x" tr '\r' '\n' < "$x" > "tmp.$x" mv "tmp.$x" "$x" done 将mac下的文件行以\r结尾转换为 unix 下的 \n. 若是 winxp 的 tr '\r\n' '\n'. |
|
|
|
|
|
|
|
第 158 帖 | |
|
|
获取网关mac地址
#!/bin/bash echo "请输入网关IP地址:" read ip arp -a | grep $ip | awk '{print $4}' 在rhel4下测试可用 |
|
|
|
|
|
|
|
第 159 帖 | |
|
|
获取网关mac地址:
#!/bin/bash echo "请输入网关IP地址:" read ip arp -a | grep $ip | awk '{print $4}' 在rhel4下测试可用 |
|
|
|
|
|
|
|
第 160 帖 | |
|
|
查看用户是否存在:
#!/bin/bash echo "请输入用户名:" read name if grep "$name" /etc/passwd > /dev/null 2>&1 then echo 存在该用户 else echo 用户不存在 fi |
|
|
|
|
|
|
|
第 161 帖 | |
|
|
标题: 一个穷极无聊之下写的除法计算器 bash的只能给出整数结果,所以,写了那么一个脚本。
代码:
__________________
上善若水,好好灌水…… 穷折腾,折腾穷,越穷越折腾…… |
|
|
|
|
|
|
|
第 162 帖 | |
|
|
好~~学习了,牛人
__________________
linux~~,i like it ,just do it! |
|
|
|
|
|
|
|
第 163 帖 | |
|
|
标题: MySQL备份并上传到FTP的shell脚本 #!/bin/bash
######################################################################## ## Author:zhao mingfeng ## ## Date:2009-05-12 ## ## Copyright(c) 2009, zhaomf All Rights Reserved ## ######################################################################## # this shell aimed at 2 points: # 1.use mysqldump backup mysql database bwisp to /backup/mysql. # 2.upload /backup/mysql backup files to a delicated ftp address. # before start this shell you should set privileges use chmod as fllows # chmod 755ftp.sh echo echo "__________________________start_________________________" ################ use mysqldump backup mysql database bwisp ################ echo "$(date +%Y-%m-%d_%H M S)"echo "++++++++++start using mysqldump backup mysql database +++++++++" MyUSER="bwisp2" #usename MyPASS="bwisp2" #password MyHOST="192.168.168.4" #hostname of host ip # Linux bin paths, change this if it can't be autodetected via which command MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" CHOWN="$(which chown)" CHMOD="$(which chmod)" TAR="$(which tar)" GZIP="$(which gzip)" TOUCH="$(which touch)" CAT="$(which cat)" # Backup Dest directory, change this if you have someother location DEST="/backup" # Main directory where backup will be stored MBD="$DEST/mysql" # Get hostname HOST="$(hostname)" # Get data in yyyy-mm-dd format NOW="$(date +"%Y-%m-%d")" # File to store current backup file FILE="" # Store list of databases DBS="" # DO NOT BACKUP these databases FANFAN="information_schema" [ ! -d $MBD ] && mkdir -p $MBD || : # Only root can access it! $CHOWN 0.0 -R $DEST $CHMOD 0600 $DEST # Get all database list first DBS="$($MYSQL -u $MyUSER -h $MyHOST -p$MyPASS -Bse 'show databases')" for db in $DBS do skipdb=-1 if [ "$FANFAN" != "" ]; then for i in $FANFAN do [ "$db" == "$i" ] && skipdb=1 || : done fi if [ "$skipdb" == "-1" ] ; then FILE="$MBD/$db.$HOST.$NOW.gz" # do all inone job in pipe, # connect to mysql using mysqldump for select mysql database # and pipe it out to gzip file in backup dir $MYSQLDUMP -u $MyUSER -h $MyHOST -p$MyPASS $db | $GZIP -9 > $FILE fi done echo "$(date +%Y-%m-%d_%H M S)"echo "+++++++++ finished dump mysql databases to $MBD +++++++++" ################## starting upload files to delicated ftp ################## $TOUCH $MBD/ftp.cmd FTP_CMD=$MBD/ftp.cmd FTP=xxx.xxx.xxx.xxx echo "$(date +%Y-%m-%d_%H M S)"echo "+++++++++++++++ start uploading $MBD back files to ftp:${FTP} +++++++++++++++++++++" echo "open ${FTP}" > ${FTP_CMD} echo "user xx xx" >> ${FTP_CMD} echo "bin" >> ${FTP_CMD} echo "hash" >> ${FTP_CMD} echo "put $FILE /$db.$HOST.$NOW.gz" >> ${FTP_CMD} echo "close" >> ${FTP_CMD} echo "bye" >> ${FTP_CMD} $CAT ${FTP_CMD} | ftp -n rm ${FTP_CMD} rm $FILE echo "$(date +%Y-%m-%d_%H M S)"echo "+++++++++++ finished upload files to ftp:${FTP} +++++++++++++++" echo "_______________________________end___________________________" echo ################################## the end ################################## 此帖于 09-07-03 20:59 被 zhaomf 编辑. |
|
|
|
|
|
|
|
第 164 帖 | |
|
|
这个帖子非常好。不过脚本还有待完善,还有很多值得讨论的地方,我刚看第一个,就发现了问题:1、脚本只能修改最后一行,其他行修改之后被原来的覆盖 2、如果文件存在特殊字符(如'/'),脚本报错。希望能有个专门讨论该帖子的脚本的空间……
|
|
|
|
|
|
|
|
第 165 帖 | |
|
|
标题: 该帖子值得讨论,希望有人组织一个讨论群或组,专门讨论该帖子的脚本 这个帖子非常好。不过脚本还有待完善,还有很多值得讨论的地方,我刚看第一个,就发现了问题:1、脚本只能修改最后一行,其他行修改之后被原来的覆盖 2、如果文件存在特殊字符(如'/'),脚本报错。希望能有个专门讨论该帖子的脚本的空间……
|
|
|
|
|
|