2013-05-28 132 views
0

我想在启动我的机器(Linux)时收到一些通知。所以,我创建了一个php脚本,它有一些逻辑,我希望在登录我的机器时在浏览器中看到脚本的输出。不在Linux上执行的PHP脚本启动

我在/etc/rc.local中添加了我的php文件。但启动后我的浏览器不能打开。可能是它无法在启动后立即找到google-chrome的实例。

任何其他建议,以便我可以登录后立即弹出?

我的PHP脚本(tasks.php):

$popUp = "Test task"; 
$popUp = "<html>$popUp</html>"; 
$fp = fopen("<path_to_file>/tasks.htm","w"); 
fwrite($fp,$popUp); 
fclose($fp); 
exec("google-chrome <path_to_file>/tasks.htm"); 

的/etc/rc.local:

#!/bin/sh 
# 
# This script will be executed *after* all the other init scripts. 
# You can put your own initialization stuff in here if you don't 
# want to do the full Sys V style init stuff. 

php <path_to_file>/tasks.php 
+0

尝试给PHP解释器的完整路径/ usr/bin/php /tasks.php –

回答

0

谷歌浏览器无法在系统初始化期间启动 - 首先,窗口系统未准备好,再加上您的帐户(即创建X会话)尚未登录。

但是,您可以编写一个页面,基于PHP脚本的执行(CLI脚本)中,例如,/ tmp目录

$fp = fopen("/tmp/myaccount.tasks.htm","w"); 

那么,当你登录,谷歌浏览器能自动启动,将文件创建为参数。例如。

/usr/bin/google-chrome /tmp/myaccount.tasks.htm 

This link解释了如何在登录时启动程序。 (请参阅~/.config/autostart路径,如果您未在接受的答案底部使用Ubuntu)

0

rc.d脚本不能与你的X环境互动。你可以执行你的php脚本,但是你不能启动chrome。

您可以将所有内容移动到您的X会话启动时自动启动的命令(Gnome,KDE等),并且它将起作用。

或者,您可以运行php脚本,通过rc.d在后台执行任何工作,并通过X会话启动Chrome。

0

将它放入gnome-session-properties,它将在登录时运行。 (显然只有当你使用gnome)

0

我写了我的PHP脚本(tasks.php),它创建了一个html页面。

$popUp = "Test task"; 
$popUp = "<html>$popUp</html>"; 
$fp = fopen("<path_to_file>/tasks.htm","w"); 
fwrite($fp,$popUp); 
fclose($fp); 

并将其添加到/etc/rc.local

#!/bin/sh 
# 
# This script will be executed *after* all the other init scripts. 
# You can put your own initialization stuff in here if you don't 
# want to do the full Sys V style init stuff. 

php <path_to_file>/tasks.php 

对于登录后打开我的html页面中铬,我修改的.config /自动启动/谷歌chrome.desktop文件

[Desktop Entry] 
Type=Application 
Terminal=false 
# Exec=/opt/google/chrome/google-chrome --no-startup-window 
Exec=/opt/google/chrome/google-chrome <path_to_file>/tasks.htm 
Name=Google Chrome