Paste #129396

   
pasted on 15.11.2019 12:42
  • Edit to this paste
  • Print
  • Raw
  • Compare with paste
    #  
  • Toggle line numbers
  • Syntax highlighting  
Text paste
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
#!/bin/bash

URL1="file:///srv/web/control_1.html"
#URL2="file:///srv/web/control_22.html"

function start_ff() {
	pos=0
	URL=$URL1
	if [ $1 = "monitor2" ]; then
		pos=2000
		URL=$URL2
	fi

	DISPLAY=:0.0 firefox -new-instance -P $1 -new-window $URL &
        sleep 5
        PID=$!
        sleep 5
        WID=$(DISPLAY=:0.0 wmctrl -lp | grep $PID | cut "-d " -f1)
        sleep 5
        DISPLAY=:0.0 wmctrl -i -r $WID -N $1
        DISPLAY=:0.0 wmctrl -i -r $WID -e '0,'"$pos"',200,250,250'
        DISPLAY=:0.0 wmctrl -i -r $WID -b add,fullscreen
}

function restart_ff () {
MONITOR_PID=$(DISPLAY=:0.0 wmctrl -lp | grep "$1" | awk '{print $3;}')
if [ ! -z $MONITOR_PID ]; then
	kill -TERM $MONITOR_PID
	sleep 5
	start_ff $1;
fi
}

#НАЧИНАЕМ ТУТ

a=$(uptime | awk '{print $3;}')
if [ $a = "0" ] || [ $a = "1" ]; then sleep 20; fi

#Убить окно с именем firefox если таковое имеется
FF_PID=$(DISPLAY=:0.0 wmctrl -lp | grep "irefox" | awk '{print $3;}')
if [ ! -z $FF_PID ]; then kill -TERM $FF_PID; fi

#Проверить существует ли окно monitor1, если нет - запустить, отпозиционировать
WID=$(DISPLAY=:0.0 wmctrl -lp | grep "monitor1" | awk '{print $3;}')
if [ -z $WID ]; then
	start_ff "monitor1";
fi

##Проверить существует ли окно monitor2, если нет - запустить, отпозиционировать
#WID=$(DISPLAY=:0.0 wmctrl -lp | grep "monitor2" | awk '{print $3;}')
#if [ -z $WID ]; then
#	start_ff "monitor2";
#fi

#Здесь всё уже запущено, проверяем куку на предмет подвисаний браузера, если подвис - киляем, перезапускаем

cookie1=$(dirname $(lsof | grep firefox | grep '/home/user/.mozilla/firefox' | grep monitor1 | head -n1 | awk '{print $9;}'))
cookie1="$cookie1/cookies.sqlite"


#cookie2=$(dirname $(lsof | grep firefox | grep '/home/user/.mozilla/firefox' | grep monitor2 | head -n1 | awk '{print $9;}'))
#cookie2="$cookie2/cookies.sqlite"

time_cookie1=$(sqlite3 $cookie1 "select value from moz_cookies where name=\"time_monitor_new\";")
#time_cookie2=$(sqlite3 $cookie2 "select value from moz_cookies where name=\"time_monitor_new\";")
echo $time_cookie1

time_now_hour=$(date +%H)
time_now_min=$(date +%M)
time_now_sec=$(date +%S)

time_cookie1_arr=(${time_cookie1//-/ })
#time_cookie2_arr=(${time_cookie2//-/ })

time_cookie1_hour=${time_cookie1_arr[0]}
time_cookie1_min=${time_cookie1_arr[1]}
time_cookie1_sec=${time_cookie1_arr[2]}

#time_cookie2_hour=${time_cookie2_arr[0]}
#time_cookie2_min=${time_cookie2_arr[1]}
#time_cookie2_sec=${time_cookie2_arr[2]}

time_now_hour=`echo "$time_now_hour" | awk '{print $1 + 0}'`
time_now_min=`echo "$time_now_min" | awk '{print $1 + 0}'`
time_now_sec=`echo "$time_now_sec" | awk '{print $1 + 0}'`

time_cookie1_hour=`echo "$time_cookie1_hour" | awk '{print $1 + 0}'`
time_cookie1_min=`echo "$time_cookie1_min" | awk '{print $1 + 0}'`
time_cookie1_sec=`echo "$time_cookie1_sec" | awk '{print $1 + 0}'`

#time_cookie2_hour=`echo "$time_cookie2_hour" | awk '{print $1 + 0}'`
#time_cookie2_min=`echo "$time_cookie2_min" | awk '{print $1 + 0}'`
#time_cookie2_sec=`echo "$time_cookie2_sec" | awk '{print $1 + 0}'`

let c=$time_now_min-$time_cookie1_min

if [ $time_now_hour -ne $time_cookie1_hour ] ||
   [ $c -gt 10 ]; then
	restart_ff "monitor1"
fi

#let c=$time_now_min-$time_cookie2_min
#
#if [ $time_now_hour -ne $time_cookie2_hour ] ||
#    [ $c -gt 10 ]; then
#	restart_ff "monitor2"
#fi
Add Comment
Author