2014-12-04 109 views
0

所需信息: 我正在使用家庭PC網絡服務器運行此操作,Fedora 20使用httpd從yum回購。 我把我的.cgi文件的基本版本從:http://www.instructables.com/id/Simple-linux-commands-from-a-web-page/,一直試圖根據我的需要進行修改。通過CGI運行服務器端Bash腳本

我的問題 - 我可以非常輕鬆地將cgi腳本與/ usr/bin文件夾中的任何腳本一起運行uname,lspci,ls以及簡單顯示文本。 但是,我不能運行一個實際上做了什麼的腳本。例如,我無法讓cgi運行「rhythmbox-client --next」來跳過Rhythmbox Media Player中的歌曲。

我的意圖是:我爲我的朋友ventrilo服務器運行'音樂機器人',並且我想給他們(密碼保護)的方式從網絡訪問機器人,更改歌曲,將歌曲添加到播放隊列等等。

的功能(其中沒有我可以開始工作),我需要的是: 下一首樂曲(Rhythmbox的客戶端---接着) 一首歌曲(Rhythmbox的客戶端--previous) 將歌曲添加到隊列(Rhythmbox的(rhythmbox客戶端 - 打印播放) 顯示計算機上的歌曲列表(ls/home/user) /音樂| grep「.mp3」)

盡我所能,我不能得到任何這些東西的工作。我也嘗試使用Banshee而不是rhythmbox,具有相同的問題。

假設執行命令的腳本部分如下: echo「」 echo「Elite Music Bot控制面板」 PATH =「/ bin:/ usr/bin:/ usr/ucb:/ USR的/ opt/BIN」 出口$ PATH 回聲 「」 回聲 「」

# test if any parameters were passed 
if [ $CMD ] 
then 
    case "$CMD" in 
    BotInfo) 
    echo "<pre>" 
     /bin/BotInfo 
    echo "System Name:" `/bin/uname -n` 
     echo "</pre>" 
     ;; 

    next) 
     echo "Skipped to the next song." 
     /bin/rhythmbox-client --next 
     ;; 

    back) 
     echo "Repeating the previous song. <pre>" 
     /bin/rhythmbox-client --previous 
     echo "</pre>" 
     ;; 

playing) 
     echo "The current song playing is... <pre>" 
     rhythmbox-client --print-playing 
     echo "</pre>" 
     ;; 

queue) 
     echo "The requested song has been added to the queue. <pre>" 
     rhythembox-client --enqueue $QUEUE_SONG 
     echo "</pre>" 
     ;; 

     rating) 
      echo "The rating of the current song has been set to $RATING. <pre>" 
      /bin/rhythmbox-client --set-rating $RATING 
      echo "</pre>" 
      ;; 
ls) 
    echo "<pre>" 
    list=`ls /home/USER/Music | grep ".mp3"` 
    echo "$list" 
    echo "</pre>" 
    ;; 
    *) 
     echo "Unknown command $CMD<br>" 
     ;; 
    esac 
fi 

非常第一個是一個簡單的腳本顯示系統時間(日期),cpuinfo中,meminfo中,ECT和它的工作。其他人卻沒有。

我已經嘗試運行的bash命令,

echo "$(command)" 

用於打印扮演我試着做它喜歡:

playing=`rhythmbox-client --print-playing` 
echo "$playing" 

我也嘗試創建一個腳本,該腳本:

#!/bin/bash 
echo "This command worked!" 
rhythmbox-client --next 

我命名的rhynext,使用chmod + x和移動到/ usr/bin中,當它的工作原理終端中運行,告訴c當gi做/ usr/bin/rhynext它什麼都不做。

請幫忙。

我非常聰明,可以反向工程代碼,如果你可以簡單地給我一個單獨的片段/代碼的例子,我將很有可能將它轉換爲我的用途。提前致謝。

編輯:當作爲apache用戶運行Banshee的'next'腳本時..

sudo -u apache /usr/bin/next 
[sudo] password for OMMITED: 
Unhandled Exception: System.UnauthorizedAccessException: Access to the path "/usr/share/httpd/.config" is denied. 
    at System.IO.Directory.CreateDirectoriesInternal (System.String path) [0x00000] in <filename unknown>:0 
    at System.IO.Directory.CreateDirectory (System.String path) [0x00000] in <filename unknown>:0 
    at System.IO.DirectoryInfo.Create() [0x00000] in <filename unknown>:0 
    at (wrapper remoting-invoke-with-check) System.IO.DirectoryInfo:Create() 
    at System.IO.Directory.CreateDirectoriesInternal (System.String path) [0x00000] in <filename unknown>:0 
    at System.IO.Directory.CreateDirectory (System.String path) [0x00000] in <filename unknown>:0 
    at Hyena.Paths.InitializePaths() [0x00000] in <filename unknown>:0 
    at Hyena.Paths.set_ApplicationName (System.String value) [0x00000] in <filename unknown>:0 
    at Banshee.ServiceStack.Application.InitializePaths() [0x00000] in <filename unknown>:0 
    at Booter.Booter.Main() [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.UnauthorizedAccessException: Access to the path "/usr/share/httpd/.config" is denied. 
    at System.IO.Directory.CreateDirectoriesInternal (System.String path) [0x00000] in <filename unknown>:0 
    at System.IO.Directory.CreateDirectory (System.String path) [0x00000] in <filename unknown>:0 
    at System.IO.DirectoryInfo.Create() [0x00000] in <filename unknown>:0 
    at (wrapper remoting-invoke-with-check) System.IO.DirectoryInfo:Create() 
    at System.IO.Directory.CreateDirectoriesInternal (System.String path) [0x00000] in <filename unknown>:0 
    at System.IO.Directory.CreateDirectory (System.String path) [0x00000] in <filename unknown>:0 
    at Hyena.Paths.InitializePaths() [0x00000] in <filename unknown>:0 
    at Hyena.Paths.set_ApplicationName (System.String value) [0x00000] in <filename unknown>:0 
    at Banshee.ServiceStack.Application.InitializePaths() [0x00000] in <filename unknown>:0 
    at Booter.Booter.Main() [0x00000] in <filename unknown>:0 
+1

你試過到stderr重定向到文件(查看是否出現任何錯誤消息)? – syme 2014-12-04 20:10:44

+1

'/ bin/rhythmbox-client'可能希望連接到當前用戶的rhythmbox dbus接口,這個cgi將無法做到這一點。您可能需要手動公開正確的dbus會話。 – 2014-12-04 20:24:45

+0

當您測試它時,以apache用戶身份運行腳本(例如'sudo -u www-data。/ yourscript')。 – 2014-12-04 20:35:07

回答

0

問題從Rhythmbox的客戶端朵朵希望連接到當前用戶的DBUS會議收集的Rhythmbox信息/發出命令。 (感謝Etan Reisner指出)

在小小的在線挖掘之後,我找到了解決方案。創建2個文件,一個用於在登錄時將當前用戶的dbus會話地址保存到臨時文件中,另一個用於調用dbus地址並通過它發送CGI命令。

文件1:將所需的文件夾中,添加啓動項,使運行(chmod + x)的名字 「Get.DBus.sh」

#!/bin/bash 
set | grep DBUS_SESSION_BUS_ADDRESS > ~/.DBUS_temp 

文件2:請可執行文件,移動到/ usr /箱,使運行(chmod + x)的名稱爲 「Run.DBus.sh」

#!/bin/bash 
source /home/USER/.DBUS_temp 
export DBUS_SESSION_BUS_ADDRESS 
$* 

變化在CGI從所需命令的執行命令..

command) 
    /bin/command 
;; 

TO

command) 
/bin/RunDBus.sh /bin/command 
;; 

問題解決了。所有命令按預期工作。

感謝大家的幫助,永遠不會有,雖然這是一個問題的DBus XD

相關問題