通过python脚本部署的计划at作业不会附加到同一日志文件

通过python脚本部署的计划at作业不会附加到同一日志文件,python,subprocess,Python,Subprocess,我试图在linux中通过python脚本部署多个“at”作业。 使用下面的代码段可以完美地部署作业 def Deploy_at(): ''' This function will deploy nine "at" jobs running at an interval of one minute to capture swap usage ''' repeat = 1 while repeat <= 9: c1 = 'at,now +

我试图在linux中通过python脚本部署多个“at”作业。 使用下面的代码段可以完美地部署作业

def Deploy_at():
''' This function will deploy nine "at" jobs 
    running at an interval of one minute to capture 
    swap usage '''

    repeat = 1
    while repeat <= 9:
        c1 = 'at,now + %d min' % repeat
        sched_cmd = list(c1.split(','))
        command = "echo repeat >> data_minor.log"

        p = Popen(sched_cmd, stdin=PIPE, stdout=PIPE)
        p.communicate(command)
        repeat += 1
但是,实际命令通过以下作业运行:

command=echo repeat>>data\u minor.log

不将输出记录到data_minor.log。而是创建了9个文件,文件名为data_minor.logmarcinDELIMITER2a97d38f


需要了解为什么将输出记录到多个文件,以及如何将输出记录到单个文件。

终于让我的代码正常工作了。 我就是这样做的

def Deploy_at():
    ''' This function will deploy nine "at" jobs 
    running at an interval of one minute to capture 
        swap usage '''

    repeat = 1
    while repeat <= 9:
        c1 = 'at,now + %d min' % repeat
        sched_cmd = list(c1.split(','))
        command = '/usr/bin/python /home/ricky/python-test/cal_swap.py -m trigger\n'

        p = Popen(sched_cmd, stdin=PIPE, stdout=PIPE)
        p.communicate(command)
        repeat += 1

任何人请…无关:1用于范围1,10:,以形成循环。2.split已返回其周围的列表下拉列表。3您可以使用threading.Timer来延迟命令,而不是at。我看代码中没有提到“data_minor.log”。谢谢@J.F.Sebastian的回答。我的问题只有脚本中使用的函数之一。触发器函数处理将输出写入data_minor.log的操作。我将很快为您发布整个脚本!!!。脚本背后的逻辑是,当满足脚本中定义的阈值时,脚本在作业中部署9以捕获数据并退出。我不想让我的剧本再等9分钟。脚本每10分钟通过cron作业运行一次,因此脚本根据编写的代码决定下一步要做什么。