zoukankan      html  css  js  c++  java
  • Linux命令、脚本

    1、传文件

      FTP/SFTP:ftp 用户名@远程ip

      SCP:注意ip后有个   :

        本地文件发到远程
        scp 本地文件 用户名@远程ip:远程路径
     
        远程文件发到本地
        scp 用户名@远程ip:远程路径 本地文件
     
    2、查询进程并kill掉
      
    ps -ef|grep logstash|grep -v grep|awk '{print $2}'|xargs kill -9

    3、scp脚本上传到主机上,或者复制文件回到本主机(可用于批量操作)

    sh 脚本文件.sh put 用户名 远程主机 密码 文件名 路径
    #!/usr/bin/ksh
    #scp脚本上传到主机上,或者复制文件回到本主机
    #使用:
    #上传:scp_file put user ip pwd 本地路径和文件名 上传路径和文件名
    #下载:scp_file get user ip pwd 远程主机路径和文件名 下载到本地的路径和文件名
    scp_file(){
            if [[ $1 == 'put' ]];
            then
                    expect -c "
                    set timeout 30;
                    spawn scp $5 $2@$3:$6;
                    expect {
                            "*assword" {send "$4
    ";exp_continue;}
                            "yes/no" {send "yes
    "; exp_continue;}
                            "Permission denied" exit
                    }" | grep -i "100%" 
                     _rScp=$?
                    #rScp=0表示成功,1表示失败。
                    if [[ ${_rScp} -eq 1 ]];
                    then
                            echo 1;
                    else
                            echo 0;
                    fi
            else if [[ $1 == 'get' ]];
                    then
                            expect -c "
                            set timeout 30;
                            spawn scp $2@$3:$5 $6
                            expect {
                                    "*assword" {send "$4
    ";exp_continue;}
                                    "yes/no" {send "yes
    "; exp_continue;}
                                    "Permission denied" exit
                            }" | grep -i "100%" 
                         _rScp=$?
                            #rScp=0表示成功,1表示失败。
                            if [[ ${_rScp} -eq 1 ]];
                            then
                                    echo 1;
                            else
                                    echo 0;
                            fi
                    fi
            fi
    }
    scp_file "$1" "$2" "$3" "$4" "$5" "$6"

    4、登录主机执行命令  ssh_do wangguan ip passwd command

    #!/usr/bin/ksh
    ssh_do(){
            expect -c "
            set timeout 30;
            spawn ssh $1@$2 "$4;exit"
            expect {
                    "*assword" {send "$3
    ";exp_continue;}
                    "yes/no" {send "yes
    "; exp_continue;}
                    "Permission denied" exit
            }"
    }
    #ssh_do wangguan ip passwd command
    ssh_do $1 $2 $3 "$4"
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    [React] Styled System with extendable Box element
    [CSS] Use grid-template to make your CSS Grid declarations more readable
    [Machine Learning Ex2] Linear Regression with Multiple Variables
    [Machine Learning] Normal Equation for linear regression
    [React] Use react styled system with styled components
    [Machine Learning] Polynomial Regression
    [Machine Learning] Gradient Descent in Practice I
    IT 运行在云端,而云运行在 Linux 上
    html+php超大视频上传代码
    html+php超大视频上传源代码
  • 原文地址:https://www.cnblogs.com/chappell/p/9004310.html
Copyright © 2011-2022 走看看