- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个从守护程序服务器调用函数的脚本。守护进程服务器每次完成其工作时都会生成一个输出。守护进程主要从外部服务器下载文件。守护程序源代码已关闭(由外部公司编码)。
完成文件下载后的守护程序输出示例:
Saved to /home/ubuntu/Daemon/downloads/download_1024000003.pdf
我正在使用的脚本从一个 TXT 文件中获取下载的 ID,从用户字段中获取 PC 的用户名,并将它们放入一个数组中,然后从守护进程中调用它们获取文件,然后在txt文件。
日志样本应该是:
Documnent ID= 3
From User = DomainCon
Saved to /home/ubuntu/Daemon/downloads/download_1024000003.pdf
我面临的问题是,保存到/home/ubuntu/Daemon/downloads/download_1024000003.pdf 守护程序服务器每次下载完成时生成的 TXT 有时会丢失。 p>
问题示例:
Documnent ID= 2
From User = DomainCon
Documnent ID= 3
In Chat = DomainCon
ANSWER 78
Saved to /home/ubuntu/Daemon/downloads/download_1024000003.pdf
日志文件中的输出应该是:
Documnent ID= 2
From User = DomainCon
ANSWER 96
Saved to /home/ubuntu/Daemon/downloads/download_1024000002.pdf
Documnent ID= 3
In Chat = DomainCon
ANSWER 78
Saved to /home/ubuntu/Daemon/downloads/download_1024000003.pdf
这是我正在使用的脚本,包括注释:
for i in range(len(ids)):\\ ids is the array that contains the documents that should be downloaded.
cmdping = "sleep 5; echo load_document "+ids[i][0]+"| nc -w 4 127.0.0.1 1234 | tee >> "+logtxt \\ Perpare the Echo command to the daemon to start the download tee to save the output of the daemon into the log text
print("\033[1;31m~~~Documnent~~~NB~~~"+str(i+1)+"\033[1;m")
print ("Documnent ID= "+ids[i][0])\\ Just Print on screen for Debbuging Purpose
print ("From User= "+ids[i][1])\\Just Print on screen for Debbuging Purpose
logfile = open(logtxt, "a") \\ Open the TXT where the log is gonna be saved.
logfile.write("Documnent ID= "+ids[i][0]+"\n")\\Write the Document ID in the File.
logfile.write("From User = "+ids[i][1]+"\n")\\\\Write the From User in the File.
logfile.close()\\Close the logfile
if (i==len(ids)-1):
p=subprocess.Popen(cmdping, shell=True, stderr=subprocess.PIPE)\\ Start the proccess that was prepared before.
#time.sleep(1)
check=""
s=1
skip=0
while (s==1):
check=checkfile(srcdir)
if (check!="no"):
s=2
if(check=="skip"):
skip=1
if(skip!=1):
if(checksize(srcdir+check) == "done"):
print(check+"\n \033[1;32mFinished Downloading moving to the next download\033[1;m")
p.terminate()
user_dir=rootdir+"/document/"+ids[i][1];
checkandcopy(download,user_dir)
最佳答案
您可以考虑改用套接字。这里有一些灵感:
import re
import socket
for i, (doc_id, user) in enumerate(ids):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("\033[1;31m~~~Documnent~~~NB~~~"+str(i+1)+"\033[1;m")
s.connect(('127.0.0.1', 1234))
s.sendall('load_document {}\n'.format(doc_id))
buf = []
while True:
r = s.recv(4096).strip()
print('Got {} for socket'.format(r))
buf.append(r)
if r.endswith('.pdf'):
print('Done')
break
result = '\n'.join(buf)
s.close()
with open(logtxt, 'a') as f:
f.write('Document ID= {}\n'.format(doc_id))
f.write('From User = {}\n'.format(user))
f.write('{}\n'.format(result))
filename = re.search('Saved to (.+)$', result).group(1)
checkandcopy(filename, userdir)
关于python - 守护程序输出未写入 TXT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35310784/
我知道我要求太多,但也许你也可以帮助解决这个问题。 a.txt 包含单词,b.txt 包含字符串。 我想知道 b.txt 中有多少个字符串以 a.txt 中的单词结尾 例子:一个.txt apple
这个问题在这里已经有了答案: erge text files ordered by numerical filenames in Bash (3 个答案) 关闭 4 年前。 我有一个文件夹,其中包含
我在一个目录中有几个平面文件 (.txt)。所有这些文件的格式都是 *.txt.txt,所以我想将其重命名为 *.txt?有什么简单的方法可以一起重命名? 当我尝试 ren *.txt.txt *.t
这个问题在这里已经有了答案: How can I use a file in a command and redirect output to the same file without trunc
您是否有任何理由应该或不应该允许访问 javascript 或 css 文件?特别是常见的文件,如 jquery。 最佳答案 人们普遍认为,搜索引擎每天为给定站点分配一定数量的带宽或 URL。因此,一
Closed. This question is off-topic。它当前不接受答案。 想要改善这个问题吗? Update the question,所以它是用于堆栈溢出的on-topic。 已关闭
这是相同的代码。我面临的问题是,我无法在任何文件上写入任何内容。请帮忙解决这个问题 #include #include int main() { FILE *fe; FILE *fo;
我想要特定于域的 robots.txt,到目前为止这有效: RewriteRule ^robots\.txt$ robots/%{HTTP_HOST}.txt [L] 但我希望有一个后备方案,因此如果
我正在调试一些构建成功运行的 SQL 命令的代码。 然而,在查询结束时,查询结果似乎被写入了一个文本文件。 完整的查询如下 echo SELECT DATE,DATETABLE,DATE,APPDAT
这个问题已经有答案了: difference between grep Vs cat and grep (5 个回答) 已关闭 8 年前。 我看到一个例子,其中有人这样做: cat source.tx
我想将表中的数据从以 csv 格式存储的文本文件插入到 sql server 表中。为此,我正在使用批量插入语句。现在我需要在“From”子句中指定文件名。我不想在那里使用网络位置或本地位置。我想将我
假设我有一个测试文件夹 (test.domain.com) 并且我不希望搜索引擎在其中抓取,我是否需要在测试文件夹中有一个 robots.txt 或者我可以只放置一个 robots.txt在根目录中,
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 9年前关闭。 Improve this q
这个问题在这里已经有了答案: order of directives in robots.txt, do they overwrite each other or complement each ot
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 8年前关闭。 Improve this
已关闭。这个问题是 not about programming or software development 。目前不接受答案。 这个问题似乎不是关于 a specific programming
在过去的几年中,当我引用“名字”字段的文本框控件时,我一直使用 FirstNameTxt 命名约定。但是,我注意到大多数其他开发人员倾向于使用命名约定 txtFirstName 哪个是最好的约定?为什
我只想允许目录 /minsc 中的一个文件,但我想禁止该目录的其余部分。 现在 robots.txt 中是这样的: User-agent: * Crawl-delay: 10 # Directorie
我正在编写一个将 youtube.com 映射到另一个域的代理服务器(因此用户可以轻松地从德国等国家/地区访问 youtube,而无需审查搜索结果和视频)。 不幸的是,我的 robots.txt 中存
我没有编程技能,但有一项非常具体的任务:我必须将一个庞大的文本文件拆分成多个,并在特定的文本标记 (@) 处拆分它们。我决定尝试使用 Powershell 脚本来完成此任务。 到目前为止,这就是我想出
我是一名优秀的程序员,十分优秀!