1
我目前正在使用一個小小的bash腳本在屏幕會話中啓動.py文件並可以使用幫助。在屏幕會話中啓動Pythonscript
我有這2個文件:
test.py(位於/家庭/開發/測試/):
import os
print("test")
os.system("ping -c 5 www.google.de>>/home/developer/Test/test.log")
test.sh(位於/家庭/開發商/ ):
#!/bin/bash
Status="NULL"
if ! screen -list | grep -q "foo";
then
Status="not running"
else
Status="running"
fi
echo "Status: $Status"
read -p "Press [Enter] key to start/stop."
if [[ $Status == "running" ]]
then
screen -S foo -p 0 -X quit
echo "Stopped Executing"
elif [[ $Staus == "not running" ]]
then
screen -dmS foo sh
screen -S foo -X python /home/developer/Test/test.py
echo "Created new Instance"
else
exit 1
fi
它的工作原理intendet,直到它有又名啓動python腳本。這條線:
screen -S foo -X python /home/developer/Test/test.py
在我的正常shell中運行時,我得到:
test
sh: 1: cannot create /home/developer/Test/test.log: Permission denied
我的問題:
- 我理解權限被拒絕案件的原因(可與sudo)但我如何給予權限和更有趣的是,我向誰授予權限? (python?| screen?| myuser?)
- 是否可以創建一個新腳本運行正確的新實例?
- 你能想到一個更好的方法來執行一個python腳本,它必須每天運行,但是啓動和停止並且不會阻塞shell嗎?
之前最初創建test.log中得到它在你的幫助了很多的工作,謝謝:) – Lyux