duange051858 2014-04-02 09:27
浏览 66

我们可以在Bash脚本中使用PHP吗?

I have a bash script abcd.sh

#!/bin/sh
for i in `seq 8`; do ssh w$i 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'; done &
pid=$!
sleep 1
kill -9 $pid

I want to use PHP in my bash script.

eg: in bash script I want to set value of seq through PHP.

  • 写回答

3条回答 默认 最新

  • dongzhuonao8429 2014-04-02 09:33
    关注

    Mmm, if you are using bash, you should maybe use a bash shebang on line 1 so people know you are expecting bash features to be available. And if you are using bash, you can use a bash sequence anyway:

    #!/bin/bash
    for i in {1..8}; do echo $i; done
    

    Update 1

    If the number of servers is obtained through PHP, you can do something like this:

    numservers=$(php -r 'echo 8;')
    for i in $(seq $numservers); do echo $i; done
    1
    2
    3
    4
    5
    6
    7
    8
    

    Update 2

    Ok, you said the number of servers is dynamic, but then you say it is set in the script (which seems contradictory), but this is what you do:

    numservers=10
    for i in $(seq $numservers); do echo $i; done
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?