2014-01-17 41 views
0

我已经编写了一个脚本来找出当前正在系统上运行的进程以及它们的项目名称。但是在执行脚本之后,得到状态代码= 0的太多行作为输出。可以请任何人帮我解决这个问题对于脚本编程来说是新的。基本脚本

#!/bin/bash 
dsjob -lprojects >ProjectName.txt #Fetching the datastage project name running on the    server     

ps -ef | grep DSD.RUN | cut -d" " -f21 > Currentjoblog.txt #this will contains the  current running job on the server 

for i in $(< ProjectName.txt);do 
dsjob -ljobs $i > $i.txt 
for j in $(< $i.txt);do 
cat $Currentjoblog.txt | while read LINE 
do 
if [ x$j == x$LINE ] ;then 
    echo "$i-------$LINE" 
fi 
done <"$CurrentJoblog.txt" 
done 
done 
+0

测试字符串'X $ VAR = xstring'是只在非常老的shell中需要,这很可能不会识别'=='的有效性(它们通常在'test'(又名'''命令要求'=')的系统上运行。 –

回答

2

首先,你并不需要使用临时文件:

dsjob -lprojects|while read l1; do 
    dsjob -ljobs $l1|while read l2; do 
     # you could use $l2 here 
     # ... 
    done 
done 

这里是如何读取命令输出或文件内容在Bash中循环提醒:here

否则:

cat $Currentjoblog.txt | while read LINE 
do 
    # ... 
done <"$CurrentJoblog.txt" 

此语法错误。您可以读取cat的输出,也可以通过重定向来阅读文件内容,但不能同时阅读(请参阅我的上一个链接以获取正确的语法)。

否则:

if [ x$j == x$LINE ] ;then 
    # ... 
fi 

你必须保护你的变量用双引号,当你使用命令test[ syntaxe代替[[。我也认为前面的操作数是x是错误的;)

这里提醒您需要(或不是)用双引号保护变量:here

0

也许你想使用pgrep“查找或信号流程基础上的姓名和其他”

例如:使用成语

$> pgrep $(dsjob -lprojects)