我有一個小腳本來啟動 Fluidsynth 伺服器,然後將其連接到我的 rasberry 上的 MIDI 裝置(作業系統是 raspbianstretch lite)。
echo "Starting"
fluidsynth -is -a alsa --gain 3 /usr/share/sounds/sf2/Nice-Keys-B-Plus-JN1.4.sf2 &
echo "Fluidsynth started"
while true; do aconnect -o; if [[ $(aconnect -o ) = *FLUID* ]]; then break; fi; sleep 2; done
aconnect 20:0 128:0
echo "Connected"
條件之外的 aconnect -o 用於調試。
當我正常執行時(./startup_fluid_synth.sh)它工作正常:https://pastebin.com/kU0wDu3w
我的 crontab -e 說:
@reboot /home/pi/startup_fluid_synth.sh >> /home/pi/fluid.log
現在,當我重新啟動 pi 時,腳本會啟動,但日誌清楚地顯示應該滿足條件,但實際上並沒有滿足:https://pastebin.com/FnxMKBkF
知道為什麼會這樣嗎?
更新: 錯誤日誌顯示:
/home/pi/startup_fluid_synth.sh: 4: /home/pi/startup_fluid_synth.sh: [[: not found
cron 是否有可能不知道 [[ ]] 指令?
答案1
將 #!/bin/bash 新增至 .sh 檔案解決了該問題。
#!/bin/bash
echo "Starting"
/usr/bin/fluidsynth -is -a alsa --gain 3 /usr/share/sounds/sf2/Nice-Keys-B-Plus-JN1.4.sf2 &
echo "Fluidsynth started"
while true; do /usr/bin/aconnect -o; if [[ $(/usr/bin/aconnect -o ) = *FLUID* ]]; then break; fi; sleep 2; done
/usr/bin/aconnect 20:0 128:0
echo "Connected"