分类 Linux 下的文章

变量 a:

a="1、测试\n2、哈哈"

如果想达到换行的效果怎么办?

1、测试
2、哈哈

如用 echo $a 输出,则换行都会被忽略,所有内容输出到一行
而用 echo "$a" 可正常输出变量中的换行

经常会有这样一种需求,为了方便部署软件或者工具,降低部署安装配置难度,需要把安装过程封装起来,只需要执行一条命令即可。

实现方法:
首先新建一个文件,命名为shell_pack.sh,写入以下内容:

#!/bin/bash - 
#===============================================================================
#
#          FILE: shell_pack.sh
# 
#         USAGE: ./shell_pack.sh 
# 
#   DESCRIPTION: 
# 
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: lwq (28120), scue@vip.qq.com
#  ORGANIZATION: 
#       CREATED: 04/22/2015 02:38:01 PM CST
#      REVISION:  ---
#===============================================================================

#===  FUNCTION  ================================================================
#         NAME:  usage
#  DESCRIPTION:  Display usage information.
#===============================================================================
function usage ()
{
        cat <<- EOT

  Usage :  $0 -p package -s script file1 file2 file3 ..

  Options:
  -h|help       Display this message
  -p|package    The output package name
  -s|script     The script will run when unpack package
  Other         The all files what you want to pack

EOT
}    # ----------  end of function usage  ----------

#-----------------------------------------------------------------------
#  Handle command line arguments
#-----------------------------------------------------------------------

while getopts ":hp:s:" opt
do
  case $opt in

    h|help    ) usage; exit 0   ;;
    p|package ) package_name=$OPTARG ;;
    s|script  ) install_script=$OPTARG ;;
    \?        ) echo -e "\n  Option does not exist : $OPTARG\n"
          usage; exit 1   ;;

  esac    # --- end of case ---
done
shift $(($OPTIND-1))

if [[ -z $package_name ]]; then
    echo "package_name can't not be empty"
    usage
    exit
fi

if [[ -z $package_name ]]; then
    echo "install_script can't not be empty"
    usage
    exit
fi

files=$@

generate_wrapper_script(){
    local install_script=$1
    local wrapper_script=$2
    cat <<-'EOT' >$wrapper_script
#!/bin/sh
echo "begin ..."
unpackdir=/tmp/$(basename $0)_unpack
rm -rf $unpackdir 2>/dev/null
mkdir -p $unpackdir
echo "unpacking ..."
sed '1, /^#__SCRIPTEND__/d' $0 | tar zxf - -C $unpackdir
if [ $? -ne 0 ]; then
    echo "unpack package failed."
    exit 1
fi
echo ""
echo "installing ..."
cd $unpackdir
EOT
    cat <<-EOR >>$wrapper_script
chmod +x $install_script
./$install_script
EOR
    cat <<-'EOE' >>$wrapper_script
if [ $? -ne 0 ]; then
    echo "install failed."
    exit 2
elif [[ -d $unpackdir ]]; then
    rm -rf $unpackdir
fi
echo "install ok, enjoy!"
exit 0
#__SCRIPTEND__
EOE
}

tarfile=package_content_$$.tgz
wrapfile=wrap_$$.sh

echo -e "start packing ..\n"
tar zcvf $tarfile $files $install_script
generate_wrapper_script $install_script $wrapfile
cat $wrapfile $tarfile > $package_name
chmod +x $package_name

echo -e "\noutput: $package_name\n"

rm -f $tarfile
rm -f $wrapfile

用法:shell_pack.sh -p package -s script file1 file2 file3 ..

1、首先下载python3.7.5源码

wget "https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz"

2、解压源码

tar xzvf Python-3.7.5.tgz

3、安装依赖库,不然python会报错找不到 _ctype等模块

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel gcc kernel-devel kernel-headers make bzip2

4、切换至源码目录并编译

cd Python-3.7.5
./configure --prefix=/usr/local/python3.7 --enable-optimizations
make && make install

5、软链接python3和pip3

ln -s /usr/local/python3.7 /usr/bin/python3
ln -s /usr/local/pip3.7 /usr/bin/pip3

6、Enjoy!!!

公司的版本服务器存放是使用win共享方式的,但是我的测试脚本运行环境是ubuntu,采用以下方式解决问题。

1、安装相关插件和工具

sudo apt install samba cifs-utils

2、新建挂载文件夹

sudo mkdir /mnt/share

3、挂载共享即可

mount -t cifs //server-name/share-name /mnt/share -o username=username,password=password,domain=workgroup,directio

关于访问速度优化可以参考这个:
https://www.cnblogs.com/afa2010/archive/2010/08/24/cifs_transfer_speed.html

清除命令:

sudo apt-get remove --purge mysql*
sudo dpkg -l | grep -i mysql
sudo apt-get clean
sudo updatedb


重新安装:

sudo apt-get install libmysqlclient-dev mysql-client
sudo apt-get install mysql-server

搞定!

删除nginx配置文件

sudo apt-get purge nginx

卸载nginx依赖

sudo apt-get autoremove

查看版本 nginx -v,可以看到No such file。

手动删除其他nginx文件

rm -rf /etc/nginx
rm -rf /etc/init.d/nginx
rm -rf /var/lib/nginx
rm -rf /var/log/nginx
rm -rf /etc/logrotate.d/nginx

重启:

sudo reboot

Enjoy!!!

Edit this file:

vim ~/.vimrc

Add code:

set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set fileencoding=utf-8
set encoding=utf-8

Finished,enjoy!!!

0x00.Terminal下,备份自带源

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

0x01.修改源:

sudo vim /etc/apt/sources.list

输入密码
按i键,插入如下源地址:
中科大源:

deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted
deb http://mirrors.ustc.edu.cn/ubuntu/ precise universe
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise universe
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates universe
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates universe
deb http://mirrors.ustc.edu.cn/ubuntu/ precise multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu precise-security main restricted
deb-src http://security.ubuntu.com/ubuntu precise-security main restricted
deb http://security.ubuntu.com/ubuntu precise-security universe
deb-src http://security.ubuntu.com/ubuntu precise-security universe
deb http://security.ubuntu.com/ubuntu precise-security multiverse
deb-src http://security.ubuntu.com/ubuntu precise-security multiverse

搜狐源:

deb http://mirrors.sohu.com/ubuntu/ precise-updates main restricted
deb-src http://mirrors.sohu.com/ubuntu/ precise-updates main restricted
deb http://mirrors.sohu.com/ubuntu/ precise universe
deb-src http://mirrors.sohu.com/ubuntu/ precise universe
deb http://mirrors.sohu.com/ubuntu/ precise-updates universe
deb-src http://mirrors.sohu.com/ubuntu/ precise-updates universe
deb http://mirrors.sohu.com/ubuntu/ precise multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise multiverse
deb http://mirrors.sohu.com/ubuntu/ precise-updates multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise-updates multiverse
deb http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse

网易源:

deb http://mirrors.163.com/ubuntu/ precise-updates main restricted
deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted
deb http://mirrors.163.com/ubuntu/ precise universe
deb-src http://mirrors.163.com/ubuntu/ precise universe
deb http://mirrors.163.com/ubuntu/ precise-updates universe
deb-src http://mirrors.163.com/ubuntu/ precise-updates universe
deb http://mirrors.163.com/ubuntu/ precise multiverse
deb-src http://mirrors.163.com/ubuntu/ precise multiverse
deb http://mirrors.163.com/ubuntu/ precise-updates multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-updates multiverse
deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse

0x02.使用新换的源更新下缓存

sudo apt-get update
sudo apt-get upgrade

0x03.完成,enjoy!

1.先执行一下命令:

sudo apt-get --purge remove nginx
sudo apt-get autoremove
dpkg --get-selections|grep nginx

罗列出与nginx相关的软件, nginx-common deinstall 然后

sudo apt-get --purge remove nginx-common

这样就可以完全卸载掉nginx包括配置文件

2.ps -ef |grep nginx 看下nginx还有没有启动,一般执行完1后,nginx还是启动着的,如下:

yo@ubuntu:/$ ps -ef |grep nginx
root     4061  2418  0 Mar11 ?        00:00:00 nginx: master processsbin/nginx
nobody   4062  4061  0 Mar11 ?        00:00:00 nginx: worker process
yo  15487  4229  0 01:13 pts/0    00:00:00 grep --color=auto nginx

3.kill nginx进程

sudo kill -9  4061  4062

4.sudo find / -name nginx*

/usr/local/nginx
/usr/local/nginx/logs/nginx.pid
/usr/local/nginx/conf/nginx.conf.default
/usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx

5.依依删除4列出的所有文件

sudo rm  -r  /usr/local/nginx
sudo rm  -r  /usr/local/nginx/logs/nginx.pid
sudo rm  -r  /usr/local/nginx/conf/nginx.conf.default
sudo rm  -r  /usr/local/nginx/conf/nginx.conf
sudo rm  -r  /usr/local/nginx/sbin/nginx

这样就彻底删除nginx了