无法从Makefile执行shell命令

时间:2017-02-20 08:59:04

标签: linux shell makefile kill

我有makefile这个问题。当我执行此命令时:

  

kill $(ps aux | grep'[p] ython service / logdata.py'| awk'{print $ 2}')

从终端

它工作正常。但是使用makefile中的这个规则:

stop:
    kill $(ps aux | grep '[p]ython service/logdata.py' | awk '{print $2}')

我收到此错误:

kill 

Usage:
 kill [options] <pid> [...]

Options:
 <pid> [...]            send signal to every <pid> listed
 -<signal>, -s, --signal <signal>
                        specify the <signal> to be sent
 -l, --list=[<signal>]  list all signal names, or convert one to a name
 -L, --table            list all signal names in a nice table

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see kill(1).
makefile:19: recipe for target 'stop' failed
make: *** [stop] Error 1

我已经检查过grep输出不是空的。

提前谢谢。

1 个答案:

答案 0 :(得分:3)

from py4j.protocol import Py4JJavaError def path_exist(sc, path): try: rdd = sc.textFile(path) rdd.take(1) return True except Py4JJavaError as e: return False 在makefile中有特殊含义,你需要加倍才能将它传递给shell。

days = 5
x = 0
files = []

while x < days:
    filedate = (date.today() - timedelta(x)).isoformat()
    path = "s3n://example/example/"+filedate+"/*.json"
    if path_exist(sc, path):
        files.append(path)
    else:
        print('Path does not exist, skipping: ' + path)
    x += 1

rdd = sc.textFile(",".join(files))                      
df = sql_context.read.json(rdd, schema)