我遇到过代码
if [ $# -eq 1 ]; then
echo "usage: Phar ~/flashmem ~/archive"
exit
fi
Run Code Online (Sandbox Code Playgroud)
我从未见过[$#-eq 1]; 之前和我似乎无法找到意义
我启动并运行了第一个hubot,并根据现有示例编写了前几个脚本。我想与hubot集成的现有工作流程实质上是基于几个shell脚本,每个脚本执行一项任务。该任务可能相对复杂(git / svn签出,使用gcc编译代码并运行它)。如何使用Hubot执行bash脚本?我看到了这个问题,但是它只解决诸如的简单命令ls。我试过了
build = spawn 'source', ['test.sh']
build.stdout.on 'data', (data) -> msg.send data.toString()
build.stderr.on 'data', (data) -> msg.send data.toString()
Run Code Online (Sandbox Code Playgroud)
没有任何运气:
Hubot> execvp(): Permission denied
Run Code Online (Sandbox Code Playgroud)
我检查了明显的内容(-rwxr-xr-x权限),并export HUBOT_LOG_LEVEL="debug"。我与拥有bash脚本的同一用户一起运行hubot。谢谢。
我想知道在UNIX/Linux中同时执行一系列命令的好习惯.假设我有一个程序program_a,它需要一个参数.我已经在文件中逐行存储了参数.所以我写道:
while read line
do
./program_a line > $line.log 2>&1
done < parameter_file
Run Code Online (Sandbox Code Playgroud)
问题是program_a的执行需要很长时间.因为每个参数的program_a的每次执行都是独立的,所以我认为这些执行可以同时运行.我不知道它是否涉及多线程或其他技术.以下是我的想法.使用&在后台运行每个执行.
while read line
do
./program_a line $line.log 2>&1 &
done < parameter_file
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来启动多个任务?
我想通过python将shell命令的输出保存到文本文件中.这是我实际的,非常基本的python代码:
编辑 这里是最后的脚本,谢谢你的帮助:)
import subprocess
ip_adress_4 = 0
pr = open("pointer_record.txt", "w")
while (ip_adress_4 < 255):
ip_adress_4 = ip_adress_4 + 1
ip_adress = '82.198.205.%d' % (ip_adress_4,)
subprocess.Popen("host %s" % ip_adress, stdout=pr, shell=True)
Run Code Online (Sandbox Code Playgroud) 我正在使用linux来创建一个使用各种命令的shell服务.我有不同的内置命令,其中一个是"历史".我有一个reshist()函数来重置包含用户输入的输入的数组.我还想使用系统命令execvp()以及多个管道操作.
reshist()函数和多管道操作在不在一起时效果很好,但是当我同时使用它们时,会导致execvp()"坏地址"错误.
我知道reshist()函数在列表中添加输入不正常,但这不是什么大问题.问题是我收到错误的原因.
可能是什么原因?有什么更好的想法让它们一起工作?
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdbool.h>
#include <sys/types.h>
#include <signal.h>
#include <errno.h>
#define MAX_BUFFER 129 // max line buffer
#define MAX_ARGS 32 // max # args
#define SEPARATORS " \t\n" // token sparators
char *args[MAX_ARGS];
int print[16];
int get[16];
int fd[2];
char histarr[10][129]; // History array
char histel[129];
void reshist(void)
{
//HISTORY RESORTING
int counter = 0;
while (counter …Run Code Online (Sandbox Code Playgroud) 这是一个后续的问题 这篇文章.
我想最终得到一个数组,包含<description>xml的所有元素.
array[0] = "<![CDATA[A title for .... <br />]]>"
array[1] = "<![CDATA[A title for .... <br />]]>"
Run Code Online (Sandbox Code Playgroud)
...
file.xml:
<item>
<description><![CDATA[A title for the URLs<br /><br />
http://www.foobar.com/foo/bar
<br />http://bar.com/foo
<br />http://myurl.com/foo
<br />http://desiredURL.com/files/ddd
<br />http://asdasd.com/onefile/g.html
<br />http://second.com/link
<br />]]></description>
</item>
</item>
<description> ...</description>
<item>
Run Code Online (Sandbox Code Playgroud) 我这样做(例如:):
grep a text.txt > file.log
Run Code Online (Sandbox Code Playgroud)
我可以生成file.log,只要它找到了"a".我应该把它放入if吗?怎么样?有人可以举个例子吗?此时这将生成空白文件.
例如,在空目录中尝试以下命令:
$ for i in *; do echo $i; done
*
Run Code Online (Sandbox Code Playgroud)
有没有办法抑制打印输出*?
我有一个脚本,检查是否PPTP VPN正在运行,如果没有它重新连接PPTP VPN,当我手动运行该脚本让它执行罚款,当我设置一个cron作业,没有运行
* * * * * /bin/bash /var/scripts/vpn-check.sh
Run Code Online (Sandbox Code Playgroud)
脚本来了:
#!/bin/sh
/bin/ping -c3 192.168.17.27 > /tmp/pingreport
result=`grep "0 received" /tmp/pingreport`
truncresult="`echo "$result" | sed 's/^\(.................................\).*$$'`"
if [[ $truncresult == "3 packets transmitted, 0 received" ]]; then
/usr/sbin/pppd call home
fi
Run Code Online (Sandbox Code Playgroud) 我有这样的特定文件结构
>ID1
data about ID1....
................
................
>ID2
data about ID2....
................
................
................
................
>ID3
data about ID3....
................
................
...............
>ID1
data about ID1....
................
>ID5
data about ID5....
................
................
Run Code Online (Sandbox Code Playgroud)
我想删除这些重复的ID块.例如,在上述情况下,它是ID1.应该注意的是,只有ID部分相同,之后的数据可能不同.但是,我想保留第一个并删除所有其他的.我怎样才能以shell脚本的方式做到这一点?
shell ×10
bash ×7
linux ×3
c ×1
coffeescript ×1
exec ×1
grep ×1
hubot ×1
if-statement ×1
parameters ×1
python ×1
unix ×1
xml ×1