前提
さくらレンタルサーバー スタンダードプラン
cronでスクリプト実行
参考サイト
https://qiita.com/dev_colla/items/6ab765fc6daf2c2a2baa
実現したいこと
cronでスクリプトの重複起動を禁止したいと思っています。
sshからスクリプトを実行すると重複起動が禁止されているのを確認できますがcronから実行すると
スクリプトが実行していない状態でも重複判定されて実行できません。
何が原因なのでしょうか?
該当のソースコード
import discord from discord.ext import commands # 2重起動を防ぐ from os import path import subprocess file_name = path.basename(__file__) p1 = subprocess.Popen(["ps", "-ef"], stdout=subprocess.PIPE) p2 = subprocess.Popen(["grep", file_name], stdin=p1.stdout, stdout=subprocess.PIPE) p3 = subprocess.Popen(["grep", "python"], stdin=p2.stdout, stdout=subprocess.PIPE) p4 = subprocess.Popen(["wc", "-l"], stdin=p3.stdout, stdout=subprocess.PIPE) p1.stdout.close() p2.stdout.close() p3.stdout.close() output = p4.communicate()[0].decode("utf8").replace('\n','') if int(output) != 1: print("重複起動") exit() # 実行スクリプト bot = commands.Bot(command_prefix="/",intents=discord.Intents.all()) @bot.event async def on_ready(): channel_sent = bot.get_channel(1012237139729199136) await channel_sent.send("完了") token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx' bot.run(token)
各変数の値を確認する必要があると思います。
まずは、 output には何が入っていますか?
回答1件