从后台

时间:2015-09-16 18:42:02

标签: python linux printing background message

当我连接到ppp网络时,我创建了一个python程序。应用程序请求www.noip.com将任何新IP链接到我在其网站上创建的主机。

/etc/ppp/ip-up.d/noip.sh  #this script calls my python app 

当我连接到ppp时,脚本运行正常,python应用程序被触发并且确实在www.noip.com上更改了我的IP地址,但是我无法仅使用print将消息打印到控制台。我的应用程序中有一些print语句只有在我从命令行运行应用程序时才有效./myapp.py

如果从后台调用我的python应用程序,如何显示消息?

这是我的Python代码:

#!/usr/bin/python     

import requests                                                                 
import netifaces as ni

user = 'xxxxxxx'                                                          
pswd = 'xxxxxxx'                      

ni.ifaddresses('ppp0')                        
ip = ni.ifaddresses('ppp0')[2][0]['addr']        
myhostname = 'xxxxxxx'                                                  

payload = {'hostname' : myhostname , 'myip' : ip}
r = requests.get("http://dynupdate.no-ip.com/nic/update", params=payload, auth=(user,pswd))

print " "                                                                       
if "good" in r.text:                                                            
        print "Hello ", user, "!"        
        print "your IP was successfully updated to:", ip        
        print myhostname, "is up and running!"                                  
if "nochg" in r.text:                                                           
        print "Hello", user, "!"                                                
        print "Your IP", ip, "is still active, no change needed"                
if "nohost" in r.text:                                                          
        print "The given Host name", myhostname, "does not exist under specified account"
        print "Please review your Host name and try again"                      
if "badauth" in r.text:                                                 
        print "Login and/or Username incorrect"                                 
        print "Please correct your credentials and try again"           
if "911" in r.text:                                                     
        print "Sorry for the incovenience but we are experiencing some problems right now"
        print "Please try again later"                                          
print "noip.com says:", r.text                                                  
print " "  

1 个答案:

答案 0 :(得分:0)

最简单的方法是将输出转到noip.sh

中的文件

python myapp.py > /tmp/myapp.out

然后当你想看到输出时,

tail -f /tmp/myapp.out