Hi!
Ich hab im Internet ein nettes Script gefunden, dass meine Qnap 253 pro entsprechend der programmierten Aufnahmen automatisch hoch und runterfahren soll.
https://tvheadend.org/boards/4/topics/15826
(Es ist das 2. Script)
Leider funktioniert das Script nicht auf meiner Qnap:
Bash
#!/bin/bash# BASIC SETTINGS change at wish# Settings you have to look at# TvHeadend login and passwordtvh_login=YOUR_LOGIN_NAMEtvh_password=YOUR_PASSWORD# (post recording) process activity to be checked, leave blank to deactivateprocess_check=(PROCESS_A PROCESS_B)# Settings you might look at# portnumbers to be checked for user activity (tvheadend 9981 + 9982 and samba 445)port_numbers=(9981 9982 445)# minimum time in seconds needed for consecutive shutdown AND startupsafe_margin_shutdown=600# minimum time in seconds needed to start up the computer properlysafe_margin_startup=180# minimum time in minutes not to shutdown after last user activity (watching tv/recording, up-/downloading files, booting the system)idle_time_shutdown=30# maximum time in hours not to wake up for updating EPGepg_hours=48# interval in seconds the script will check if the system should be shutdownscript_int=60# END OF BASIC SETTINGS keep out from here ;-)# retrieve IP_address tvheadend servertvh_ip=$(hostname -i | awk '{print $1}')# set languageexport LANG=C# set session startuptime_boot_sec=$(cat /proc/uptime | awk -F ' ' '{print$1}' | awk -F '.' '{print$1}')boot_time=$(($(date +%s)-uptime_boot_sec))# initial values do not changerecording=1# check for shutdownuntil [ $recording -eq 0 ];do# initial values do not changerecording=0shutdown_timer=$idle_time_shutdownping_array=()# countdown to shutdownuntil [ $shutdown_timer -eq 0 ];doshutdown_timer=$((shutdown_timer-1))# check for server connection tvheadend samba or any other server according to settings abovestatus_netstat=1until [ $status_netstat -eq 0 ];dostatus_netstat=0sleep $script_intfor i in $( echo "${port_numbers}"); doport_no=$ifor i in $(echo $(netstat -n | grep -i "ESTABLISHED" | grep "$tvh_ip:$port_no" | awk -F ':' '{print ":"$2}' | sed 's/:'$port_no'\|[ ]//g')); doshutdown_timer=$idle_time_shutdownstatus_netstat=1ping_array[$(echo "${#ping_array}")]=$idonedoneping_array=($(echo "${ping_array}" | sed 's/[ ]/\n/g' | awk '!a[$0]++' ))donefor i in $(echo "${ping_array}"); doif [ $( ping -c1 $i | grep "received" | awk -F ',' '{print $2}' | awk '{print $1}' ) -eq 0 ]; thenping_array=($(echo "${ping_array/$i/}"))fidoneif [ $(echo "${#ping_array}") -eq 0 -a $boot_time -lt $(($(date +%s)-idle_time_shutdown*60)) ]; thenshutdown_timer=0fiif [ $(curl -s --user $tvh_login:$tvh_password http://127.0.0.1:9981/status.xml | grep "subscriptions" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}') -ne 0 -a $shutdown_timer -eq 0 ]; thenshutdown_timer=1fidone# check for active post recording processestotal_processes=0for i in $( echo "${process_check}"); docounter=$( ps -A | grep "$i" | wc -l )total_processes=$((total_processes+counter))doneif [ $total_processes -ne 0 ]; thenrecording=$((recording+1))fi# check for active usersif [ $(who | wc -l) -ne 0 ]; thenrecording=$((recording+1))fi# retrieve and calculate wake up dataif [ $(curl -s --user $tvh_login:$tvh_password http://127.0.0.1:9981/status.xml | grep "subscriptions" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}') -eq 0 ]; thenwake_after_min=$((epg_hours*60))if [ $(curl -s --user $tvh_login:$tvh_password 127.0.0.1:9981/status.xml | grep "next" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}' | wc -l) -gt 0 ]; thenwake_after_min_temp=$(curl -s --user $tvh_login:$tvh_password 127.0.0.1:9981/status.xml | grep "next" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')if [ $wake_after_min -gt $wake_after_min_temp ]; thenwake_after_min=$wake_after_min_tempfifielsewake_after_min=0fiwake_after_secs=$((wake_after_min*60))# check safe margin shutdownif [ $safe_margin_shutdown -gt $wake_after_secs ]; thenrecording=$((recording+1))fidone# set RTC wake up timestop_date=$(date +%s)wake_date=$((stop_date+wake_after_secs-safe_margin_startup))echo 0 > /sys/class/rtc/rtc0/wakealarmecho $wake_date > /sys/class/rtc/rtc0/wakealarm# shutdown computersudo shutdown -h now
Aktuell hänge ich bei Zeile 46
Bash
# check for server connection tvheadend samba or any other server according to settings above
status_netstat=1
until [ $status_netstat -eq 0 ];do
status_netstat=0
sleep $script_int
for i in $( echo "${port_numbers[*]}"); do
port_no=$i
for i in $(echo $(netstat -n | grep -i "ESTABLISHED" | grep "$tvh_ip:$port_no" | awk -F ':' '{print ":"$2}' | sed 's/:'$port_no'\|[ ]//g')); do
shutdown_timer=$idle_time_shutdown
status_netstat=1
ping_array[$(echo "${#ping_array[*]}")]=$i
done
done
ping_array=($(echo "${ping_array[*]}" | sed 's/[ ]/\n/g' | awk '!a[$0]++' ))
done
for i in $(echo "${ping_array[*]}"); do
if [ $( ping -c1 $i | grep "received" | awk -F ',' '{print $2}' | awk '{print $1}' ) -eq 0 ]; then
ping_array=($(echo "${ping_array[*]/$i/}"))
fi
done
if [ $(echo "${#ping_array[*]}") -eq 0 -a $boot_time -lt $(($(date +%s)-idle_time_shutdown*60)) ]; then
shutdown_timer=0
fi
if [ $(curl -s --user $tvh_login:$tvh_password http://127.0.0.1:9981/status.xml | grep "subscriptions" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}') -ne 0 -a $shutdown_timer -eq 0 ]; then
shutdown_timer=1
fi
done
Alles anzeigen
Da wird mir ein Syntax Error ausgegeben.
Bin leider ein Linux Neuling. Kann mir jemand helfen das zu fixen? - Ich denke an dem Code hätte mehr Leute interesse.
Danke und LG