精华内容
下载资源
问答
  • 循环执行shell脚本

    千次阅读 2017-04-15 18:20:06
    /////////////////////////////////////////////////////////////////////////////////////////////////////循环执行shell脚本 #$language = "VBScript" #$interface = "1.0" crt.Screen.Synchronous = False  ...

    /循环执行shell脚本
    #$language = "VBScript"
    #$interface = "1.0"
    crt.Screen.Synchronous = False 
    Sub Main
    set fs  = createobject("scripting.filesystemobject")
    Set conf = crt.OpenSessionConfiguration("10.0.0.1")
    Set tab = conf.ConnectInTab()
    Dim logfile
    logfile = "E:\ALFT\Log\ALFT_20170411145534.log"
    crt.Session.LogFileName = logfile
    crt.Session.Log false
    DO While true
    crt.Screen.WaitForString "root@LTE-GW:~#"
    ;暂停1秒钟
    crt.sleep 1000
    crt.Screen.Send AAAA
    crt.Screen.WaitForString "root@LTE-GW:~#"
    crt.Screen.Send BBBB
    crt.Screen.WaitForString "root@LTE-GW:~#"
    crt.Screen.Send CCCC
    crt.Screen.WaitForString "root@LTE-GW:~#"
    crt.Screen.Send DDDD
    loop
    crt.Screen.Synchronous = False
    crt.Session.Log False
    crt.Session.Disconnect
    crt.quit
    End Sub


    借助终端工具SecuretCRT.exe

    通过cmd命令执行这个shell脚本,mySystem(ini_securecrtPath,_T("/script Log/alft.vbs"),2);



    展开全文
  • for 实现: 代码如下: #!/bin/bash set i=0 set j=0 for((i=0;i<10;)) do ... echo “————-j is $j ——————-“ ... 您可能感兴趣的文章:Shell中的循环语句for、while、until实例讲解Shel
  • Linux中循环执行shell命令的方法

    千次阅读 2021-05-08 22:09:45
    Linux命令行,循环执行shell命令死循环命令格式while true ;do ; done;可以将 command 替换为任意命令。下面以echo “hello”; sleep 1;为 command 展示最终效果效果wanghan@ubuntu:~$ while true ;do echo "hello";...

    Linux命令行,循环执行shell命令

    死循环

    命令格式while true ;do ; done;

    可以将 command 替换为任意命令。

    下面以echo “hello”; sleep 1;为 command 展示最终效果

    效果wanghan@ubuntu:~$ while true ;do echo "hello"; sleep 1; done;

    hello

    hello

    hello

    hello

    hello

    ^C

    wanghan@ubuntu:~$

    每隔一秒,打印一次hello,直到按下Ctrl+C才停止。

    普通计数循环

    循环10次mycount=0; while (( $mycount < 10 )); do ;((mycount=$mycount+1)); done;

    可以将 command 替换为任意命令。

    下面以 echo “mycount=$mycount”;为 command 展示最终效果

    效果wanghan@ubuntu:~$ mycount=0; while (( $mycount < 10 )); do echo "mycount=$mycount"; ((mycount=$mycount+1)); done;

    mycount=0

    mycount=1

    mycount=2

    mycount=3

    mycount=4

    mycount=5

    mycount=6

    mycount=7

    mycount=8

    mycount=9

    mycount计数到10后停止循环。或者使用for循环:

    使用i来循环执行10次命令。for i in {1..10}; do echo "Hello"; done

    用for循环更简单一些,下面是for的几种不同的使用方式:

    Linux shell 实现用for循环100次的方法

    今天小编就为大家分享一篇Linux shell 实现用for循环100次的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧.

    前言

    循环不管在程序中还是脚本中都需要经常用到,在写shell脚本时,经常需要for进行100次循环。这里谈谈几种从1到100的循环方法。

    四种方法

    C语言风格for ((i=1; i<=100; i++))

    do

    echo $i

    done

    Python风格(in的使用)for i in {1..100}

    do

    echo $i

    done

    Seq的使用

    注意代码中不是单引号。for i `seq 1 100`

    do

    echo $i

    done

    展开全文
  • 今天小编就为大家分享一篇通过shell脚本循环进入目录执行命令的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
  • shell脚本循环执行任务的脚本

    千次阅读 2016-06-19 21:04:39
    #! /bin/sh while true; do ./test.sh > test.txt; sleep 3; done 最近研究了下shell,如上true代表循环执行 do 后接执行命令 sleep沉睡时间 done结束

    #! /bin/sh

    while true;  do ./test.sh > test.txt; sleep 3; done


    最近研究了下shell,如上true代表循环执行 do 后接执行命令 sleep沉睡时间 done结束

    展开全文
  • shell 循环执行sql脚本

    2021-03-10 15:11:39
    线上批量更新,数量过多,流程上必须写脚本,就试着先写个简单的,逻辑: 每次更新一条,根据id逐条更新。 后续其实可以优化为分页批量执行(limit x,y 或者 where id < last and id >= id +1000),效率会...

     

    线上批量更新,数量过多,流程上必须写脚本,就试着先写个简单的,逻辑: 每次更新一条,根据id逐条更新。

    后续其实可以优化为分页批量执行(limit x,y  或者 where id < last and id >= id +1000),效率会更高。

    #!/bin/bash
    
    i=1
    step=1
    #cnt=$(/usr/local/MySQL/bin/mysql -u root -p -Dtf_test -s -e "${cmd}")
    while (($i<=3))
    do
      #${cnt}
      cmd="update test_1 set no=11 where id=$i"
      echo ${cmd}
      /usr/local/MySQL/bin/mysql -h'localhost' -u'root' -p'root'  -D tf_test -s -e "${cmd}"
      i=`expr $i + $step`
    done
    echo "执行完毕:${i}"

    sql  命令行的说明:

    -h, --host=name     Connect to host.  连接的host 
    -u, --user=name     User for login if not current user. 指定的用户名
    -p, --password[=name] 指定的密码
    -P, --port=#        Port number to use for connection.  指定的数据端口号
    
    -D, --database=name Database to use.  指定数据库的 database
    -e, --execute=name  Execute command and quit. (Disables --force and history 执行具体的sql
    -s, --silent        Be more silent. Print results with a tab as separator, 以制表符作为分隔符打印结果

    需要注意一点的是,环境中 直接执行  mysql  -uroot -proot 是没有问题的,在shell 脚本中,  -proot  要写成 -p'root',否则会被认为 root 是 database,执行错误

    mysql的命令:

    Usage: /usr/local/MySQL/bin/mysql [OPTIONS] [database]
      -?, --help          Display this help and exit.
      -I, --help          Synonym for -?
      --auto-rehash       Enable automatic rehashing. One doesn't need to use
                          'rehash' to get table and field completion, but startup
                          and reconnecting may take a longer time. Disable with
                          --disable-auto-rehash.
                          (Defaults to on; use --skip-auto-rehash to disable.)
      -A, --no-auto-rehash
                          No automatic rehashing. One has to use 'rehash' to get
                          table and field completion. This gives a quicker start of
                          mysql and disables rehashing on reconnect.
      --auto-vertical-output
                          Automatically switch to vertical output mode if the
                          result is wider than the terminal width.
      -B, --batch         Don't use history file. Disable interactive behavior.
                          (Enables --silent.)
      --bind-address=name IP address to bind to.
      --binary-as-hex     Print binary data as hex
      --character-sets-dir=name
                          Directory for character set files.
      --column-type-info  Display column type information.
      -c, --comments      Preserve comments. Send comments to the server. The
                          default is --skip-comments (discard comments), enable
                          with --comments.
      -C, --compress      Use compression in server/client protocol.
      -#, --debug[=#]     This is a non-debug version. Catch this and exit.
      --debug-check       This is a non-debug version. Catch this and exit.
      -T, --debug-info    This is a non-debug version. Catch this and exit.
      -D, --database=name Database to use.
      --default-character-set=name
                          Set the default character set.
      --delimiter=name    Delimiter to be used.
      --enable-cleartext-plugin
                          Enable/disable the clear text authentication plugin.
      -e, --execute=name  Execute command and quit. (Disables --force and history
                          file.)
      -E, --vertical      Print the output of a query (rows) vertically.
      -f, --force         Continue even if we get an SQL error.
      --histignore=name   A colon-separated list of patterns to keep statements
                          from getting logged into syslog and mysql history.
      -G, --named-commands
                          Enable named commands. Named commands mean this program's
                          internal commands; see mysql> help . When enabled, the
                          named commands can be used from any line of the query,
                          otherwise only from the first line, before an enter.
                          Disable with --disable-named-commands. This option is
                          disabled by default.
      -i, --ignore-spaces Ignore space after function names.
      --init-command=name SQL Command to execute when connecting to MySQL server.
                          Will automatically be re-executed when reconnecting.
      --local-infile      Enable/disable LOAD DATA LOCAL INFILE.
      -b, --no-beep       Turn off beep on error.
      -h, --host=name     Connect to host.
      -H, --html          Produce HTML output.
      -X, --xml           Produce XML output.
      --line-numbers      Write line numbers for errors.
                          (Defaults to on; use --skip-line-numbers to disable.)
      -L, --skip-line-numbers
                          Don't write line number for errors.
      -n, --unbuffered    Flush buffer after each query.
      --column-names      Write column names in results.
                          (Defaults to on; use --skip-column-names to disable.)
      -N, --skip-column-names
                          Don't write column names in results.
      --sigint-ignore     Ignore SIGINT (CTRL-C).
      -o, --one-database  Ignore statements except those that occur while the
                          default database is the one named at the command line.
      --pager[=name]      Pager to use to display results. If you don't supply an
                          option, the default pager is taken from your ENV variable
                          PAGER. Valid pagers are less, more, cat [> filename],
                          etc. See interactive help (\h) also. This option does not
                          work in batch mode. Disable with --disable-pager. This
                          option is disabled by default.
      -p, --password[=name]
                          Password to use when connecting to server. If password is
                          not given it's asked from the tty.
      -P, --port=#        Port number to use for connection or 0 for default to, in
                          order of preference, my.cnf, $MYSQL_TCP_PORT,
                          /etc/services, built-in default (3306).
      --prompt=name       Set the mysql prompt to this value.
      --protocol=name     The protocol to use for connection (tcp, socket, pipe,
                          memory).
      -q, --quick         Don't cache result, print it row by row. This may slow
                          down the server if the output is suspended. Doesn't use
                          history file.
      -r, --raw           Write fields without conversion. Used with --batch.
      --reconnect         Reconnect if the connection is lost. Disable with
                          --disable-reconnect. This option is enabled by default.
                          (Defaults to on; use --skip-reconnect to disable.)
      -s, --silent        Be more silent. Print results with a tab as separator,
                          each row on new line.
      -S, --socket=name   The socket file to use for connection.
      --server-public-key-path=name
                          File path to the server public RSA key in PEM format.
      --get-server-public-key
                          Get server public key
      --ssl-mode=name     SSL connection mode.
      --ssl-ca=name       CA file in PEM format.
      --ssl-capath=name   CA directory.
      --ssl-cert=name     X509 cert in PEM format.
      --ssl-cipher=name   SSL cipher to use.
      --ssl-key=name      X509 key in PEM format.
      --ssl-crl=name      Certificate revocation list.
      --ssl-crlpath=name  Certificate revocation list path.
      --tls-version=name  TLS version to use, permitted values are: TLSv1, TLSv1.1,
                          TLSv1.2
      --ssl-fips-mode=name
                          SSL FIPS mode (applies only for OpenSSL); permitted
                          values are: OFF, ON, STRICT
      -t, --table         Output in table format.
      --tee=name          Append everything into outfile. See interactive help (\h)
                          also. Does not work in batch mode. Disable with
                          --disable-tee. This option is disabled by default.
      -u, --user=name     User for login if not current user.
      -U, --safe-updates  Only allow UPDATE and DELETE that uses keys.
      -U, --i-am-a-dummy  Synonym for option --safe-updates, -U.
      -v, --verbose       Write more. (-v -v -v gives the table output format).
      -V, --version       Output version information and exit.
      -w, --wait          Wait and retry if connection is down.
      --connect-timeout=# Number of seconds before connection timeout.
      --max-allowed-packet=#
                          The maximum packet length to send to or receive from
                          server.
      --net-buffer-length=#
                          The buffer size for TCP/IP and socket communication.
      --select-limit=#    Automatic limit for SELECT when using --safe-updates.
      --max-join-size=#   Automatic limit for rows in a join when using
                          --safe-updates.
      --show-warnings     Show warnings after every statement.
      -j, --syslog        Log filtered interactive commands to syslog. Filtering of
                          commands depends on the patterns supplied via histignore
                          option besides the default patterns.
      --plugin-dir=name   Directory for client-side plugins.
      --default-auth=name Default authentication client-side plugin to use.
      --binary-mode       By default, ASCII '\0' is disallowed and '\r\n' is
                          translated to '\n'. This switch turns off both features,
                          and also turns off parsing of all clientcommands except
                          \C and DELIMITER, in non-interactive mode (for input
                          piped to mysql or loaded using the 'source' command).
                          This is necessary when processing output from mysqlbinlog
                          that may contain blobs.
      --connect-expired-password
                          Notify the server that this client is prepared to handle
                          expired password sandbox mode.
    
    Default options are read from the following files in the given order:
    /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
    The following groups are read: mysql client
    The following options may be given as the first argument:
    --print-defaults        Print the program argument list and exit.
    --no-defaults           Don't read default options from any option file,
                            except for login file.
    --defaults-file=#       Only read default options from the given file #.
    --defaults-extra-file=# Read this file after the global files are read.
    --defaults-group-suffix=#
                            Also read groups with concat(group, suffix)
    --login-path=#          Read this path from the login file.
    
    Variables (--variable-name=value)

     

     

     

     

     

     

    展开全文
  • NULL 博文链接:https://bicashy.iteye.com/blog/1522713
  • 本文主要给大家介绍了关于使用Shell脚本循环读取文件每一行的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。 一、使用for循环 for line in `cat filename` do echo $line done ...
  • Shell脚本执行mysql的几种方式(转) Shell脚本执行mysql的几种方式(转) 对于自动化运维,诸如备份恢复之类的,DBA经常需要将SQL语句封装到shell脚本.本文描述了在Linux环境下mysql数据库中,shell脚本下调用 ... ...
  • 2 )再执行exp2,如果它的判断结果成立,则执行循化体中的语句,否则结束整个for循环; 3)执行循环体后再执行exp3; 4)重复执行步骤2)和3),直到exp2的判断结果不成立,就结束循环。 上面的步骤中,第二步和第...
  • 今天小编就为大家分享一篇hive-shell批量命令执行脚本的实现方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
  • Shell脚本循环:重复执行命令

    千次阅读 2021-05-08 22:09:59
    Shell脚本循环:重复执行命令1.for循环语法:for 变量名称 in 变量值列表do命令DoneFor根据变量值列表中的内容,重复执行命令,直到变量值列中的所有内容都取值完后结束。取值列表的类型:可以是特定文本文件,...
  • 当变量值在列表里,for循环执行一次所有命令,使用变量名获取列表中的当前取值。命令可为任何有效的shell命令和语句。in列表可以包含替换、字符串和文件名。 in列表是可选的,如果不用它,for循环使用命令行的位置...
  • 多线程执行for循环shell脚本

    万次阅读 多人点赞 2017-12-29 15:22:48
    需求:并发检测1000台web服务器状态(或者并发为1000台web服务器分发文件等...思路:一个for循环1000次,顺序执行1000次任务。 实现: #!/bin/bash start_time=`date +%s` #定义脚本运行的开始时间 for ((i=
  • 本发明公开了一种限制shell 脚本并行执行 的方法,应用于linux 和unix 平台,包括:当有 shell 脚本需要执行时,脚本模块处理器向管道 写入请求;令牌模块处理器在管道另一端顺序读 取所述请求,当有令牌空闲时,将...
  • 今天小编就为大家分享一篇shell在指定目录下批量执行sql脚本的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
  • 使用FTP定时批量下载指定文件的shell脚本,具体实例介绍如下所示,需要的朋友参考下吧
  • shell按日期循环执行脚本

    千次阅读 2019-04-30 17:12:04
    #!/usr/bin/env bash for ((i=7;i>0;i–)); do date= date -d "$i days ago" +"%Y%m%d" echo ${date} bash ./bin/脚本名.sh ${date} done
  • 主要介绍了Shell脚本中引用、调用另一个脚本文件的2种方法,本文介绍了两种方法的语法,然后给出实际使用实例和一些要注意的地方,需要的朋友可以参考下
  • 在运行脚本时重复执行一系列的命令是很常见的,这时我们就需要使用循环语句来达到这个目的。一、for命令格式:for 变量 in 列表;do循环体donefor命令会遍历列表中的每一个值,并且在遍历完成后退出循环。列表形式有...
  • for循环编写乘法口诀表的几种方式,当做for循环语句练习即可 脚本1: [root@linus ~]# cat test.sh #!/bin/bash for i in {1..9} do for o in `seq $i` do echo -n $o*$i=$[$i*$o] done echo done 执行效果: ...
  • 主要介绍了Shell脚本中获取进程ID的方法,我想要知道运行中脚本子shell的进程id,我该如何在shell脚本中得到PID,阅读本文即可找到你想要答案,需要的朋友可以参考下
  • shell循环执行脚本

    千次阅读 2018-08-17 11:57:26
    shell循环执行脚本 2017年08月24日 15:28:18 阅读数:215 for i in {1..10}  do  echo "Welcome $i times"  eoo$i.sh  done
  • shell脚本for循环Continuing on from our previous tutorials, let’s understand the for loop in shell scripts today. We’ve already covered the while loop previously and the for loop has similar usage ...
  • 主要介绍了批量复制及执行命令shell脚本,本文通过列举几个示例给大家详细介绍,对大家的工作或学习具有一定的参考借鉴价值,需要的朋友可以参考下
  • 在开发中,怎样编写脚本输入开始月份、结束月份自动跑数呢? 对shell中getopts不懂的请查看我以前博客 shell中的getopt 提供以下脚本供参考: #!/bin/sh #************************...#*** 程序功能: 按天循环导入分...
  • shell脚本 ping所有网段ip 当局域网内,网络设备ip不知,可以用此脚本ping可以更改[ping指定网段ip 1s一个ip是否通畅
  • Shell 循环执行3次命令

    2021-05-13 19:11:09
    #!... doecho 'Execute 3 times'echo $ipybot --nostatusrc --outputdir /root/.jenkins/workspace/User/report/ --include usertest /root/.jenkins/workspace/User-200sleep 5sdone1.shell格式...
  • 1、问题 我们一般很多时候会需要在ubuntu终端上打印当前运行app的日志,我们一般常见的做法是 1)、获取包名 打开当前运行的app,然后输入如下命令,然后在...通过执行脚本文件获取包名,然后再执行pidcat.py packageNam

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 76,443
精华内容 30,577
关键字:

循环执行shell脚本