#!/bin/bash
export DISPLAY=:0
export LANG=ru_RU.UTF-8
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
i='129439' #параметр обозначающий порог свободного места на диске в МБ
FREE=$(df -m | grep "/1TB" | awk '{print $4}')
while [ "$i" -le "$FREE" ] #запись пока есть свободное место на диске
do
echo "Запись нового файла: " $(date +%Y-%m-%d_%H-%M-%S)".mkv"
if ! [ `ps -ef| grep -E "ffmpeg" | wc -l ` -gt 1 ]
then ffmpeg -i http://192.168.0.4:8000/stream.mjpg -to 0:10 \
-vf "drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf: text='%{localtime\:%X}': fontcolor=black@0.8: x=640: y=10" "/1TB/.zm/move/$(date +%Y-%m-%d_%H-%M-%S).mkv" 2>/dev/null
fi
FREE=$(df -m | grep "/1TB" | awk '{print $4}') #проверим сколько осталось свободного места после записи файла
if [ "$i" -gt "$FREE" ];
then
#ищем самый старый файл, за последние пять дней
# var_d=$(find /1TB/.zm/move/ -type f -name '*.mkv' -mtime -5 | head -n 1)
find /1TB/.zm/move/ -type f -name '*.mkv' -printf '%T+ %p\n' | sort | head -n1 | awk '{print $2}' > /tmp/rmM
for r in $(cat /tmp/rmM); do echo " rm move $r"; rm $r; done
FREE=$(df -m | grep "/1TB" | awk '{print $4}') #проверим сколько осталось свободного места
fi
done
суббота, 26 октября 2019 г.
пятница, 25 октября 2019 г.
RHVoice только если есть кому слушать и не мешает смотреть кино
Выполнять озвучивание погоды вечерами только при условии
1. не запущен проигрыватель Коди
2. прошло менее 31 минуты поле последнего обнаружения движения датчиком
nano /sh/rec-stream.sh
#!/bin/bash
echo "`date +%H\ %M\ %S\ %N` bash start" >> /var/www/html/mrtg/pir.txt
#if ping -c 1 172.28.253.4 2>&1> /dev/null
# then ssh lv@172.28.253.4 '/sh/rec-stream.sh' &
# echo "`date +%H\ %M\ %S\ %N` lv rec stream start [OK]"
#fi
#if ping -c 1 192.168.0.11 2>&1> /dev/null
# then ssh evg@192.168.0.11 '/sh/rec_stream.sh' &
# echo "`date +%H\ %M\ %S\ %N` asus rec stream start [OK]" >> /var/www/html/mrtg/pir.txt
#fi
#if ls /tmp/ | grep -oE "*.mp4" &>/dev/null
# then rm /tmp/*.mp4
#fi
#echo "`date +%H\ %M\ %S\ %N` rm .mp4 [OK]"
DATA=$(date +%Y-%m-%d_%H-%M-%S_%N)
echo "`date +%H\ %M\ %S\ %N` ffmpeg rec [OK]" >> /var/www/html/mrtg/pir.txt
#ffmpeg -i http://127.0.0.1:8000/stream.mjpg -to 0:02 -c:v copy -c:a copy /tmp/$DATA.mp4 2> /dev/null
#echo "`date +%H\ %M\ %S\ %N` ffmpeg stop [OK]"
#if ls /var/www/html/mrtg/ | grep -oE "cam1.jpg" &>/dev/null
# then rm /var/www/html/mrtg/cam1.jpg
#fi
#echo "`date +%H\ %M\ %S\ %N` bash rm jpg [OK]"
ffmpeg -f MJPEG -y -i http://127.0.0.1:8000/stream.mjpg \
-r 1 -vframes 1 -q:v 1 /var/www/html/mrtg/cam1.jpg 2> /dev/null
echo "`date +%H\ %M\ %S\ %N` frames [OK]" >> /var/www/html/mrtg/pir.txt
convert /var/www/html/mrtg/cam1.jpg -background none -fill black -box 'white' -gravity South \
-pointsize 20 -annotate +0+1050 $DATA /var/www/html/mrtg/cam.jpg
echo "`date +%H\ %M\ %S\ %N` image convert [OK]" >> /var/www/html/mrtg/pir.txt
if ping -c 1 192.168.0.11 2>&1> /dev/null
then scp /var/www/html/mrtg/cam.jpg evg@192.168.0.11:/1TB/.zm/v/$DATA.jpg 2>&1 > /dev/null &
echo "`date +%H\ %M\ %S\ %N` scp 11 jpg [OK]" >> /var/www/html/mrtg/pir.txt
date +%s > /tmp/time0
scp /tmp/time0 evg@192.168.0.11:/tmp/time0
fi
#if ping -c 1 172.28.253.4 2>&1> /dev/null
# then scp /var/www/html/mrtg/cam.jpg lv@172.28.253.4:/a/$DATA.jpg 2>&1 > /dev/null &
# echo "`date +%H\ %M\ %S\ %N` scp 4 jpg [OK]" >> /var/www/html/mrtg/pir.txt
#fi
nano /sh/mint_pir.sh
#!/bin/bash
TIME0=$(cat /tmp/time0)
TIME1=$(date +"%s")
TIME2=$(echo "$TIME1-$TIME0" |bc)
TIME3='1860'
#TIME3='60'
#-eq - равно
#-lt - меньше
#-le - меньше или равно
#-ge - больше или равно
#-gt - больше
#-ne - не равно или нет
#
echo "$TIME2"
if [ $TIME2 -le $TIME3 ] &>/dev/null
then /sh/RHvoice_time.sh
# echo " прошло менее 31 мин"
fi
crontab -e
*/15 19-22 * * 1-5 if ! ps aux|grep -v color |grep -o "/kodi/kodi.bin" &> /dev/null; then /sh/mint_pir.sh; fi
1. не запущен проигрыватель Коди
2. прошло менее 31 минуты поле последнего обнаружения движения датчиком
nano /sh/rec-stream.sh
#!/bin/bash
echo "`date +%H\ %M\ %S\ %N` bash start" >> /var/www/html/mrtg/pir.txt
#if ping -c 1 172.28.253.4 2>&1> /dev/null
# then ssh lv@172.28.253.4 '/sh/rec-stream.sh' &
# echo "`date +%H\ %M\ %S\ %N` lv rec stream start [OK]"
#fi
#if ping -c 1 192.168.0.11 2>&1> /dev/null
# then ssh evg@192.168.0.11 '/sh/rec_stream.sh' &
# echo "`date +%H\ %M\ %S\ %N` asus rec stream start [OK]" >> /var/www/html/mrtg/pir.txt
#fi
#if ls /tmp/ | grep -oE "*.mp4" &>/dev/null
# then rm /tmp/*.mp4
#fi
#echo "`date +%H\ %M\ %S\ %N` rm .mp4 [OK]"
DATA=$(date +%Y-%m-%d_%H-%M-%S_%N)
echo "`date +%H\ %M\ %S\ %N` ffmpeg rec [OK]" >> /var/www/html/mrtg/pir.txt
#ffmpeg -i http://127.0.0.1:8000/stream.mjpg -to 0:02 -c:v copy -c:a copy /tmp/$DATA.mp4 2> /dev/null
#echo "`date +%H\ %M\ %S\ %N` ffmpeg stop [OK]"
#if ls /var/www/html/mrtg/ | grep -oE "cam1.jpg" &>/dev/null
# then rm /var/www/html/mrtg/cam1.jpg
#fi
#echo "`date +%H\ %M\ %S\ %N` bash rm jpg [OK]"
ffmpeg -f MJPEG -y -i http://127.0.0.1:8000/stream.mjpg \
-r 1 -vframes 1 -q:v 1 /var/www/html/mrtg/cam1.jpg 2> /dev/null
echo "`date +%H\ %M\ %S\ %N` frames [OK]" >> /var/www/html/mrtg/pir.txt
convert /var/www/html/mrtg/cam1.jpg -background none -fill black -box 'white' -gravity South \
-pointsize 20 -annotate +0+1050 $DATA /var/www/html/mrtg/cam.jpg
echo "`date +%H\ %M\ %S\ %N` image convert [OK]" >> /var/www/html/mrtg/pir.txt
if ping -c 1 192.168.0.11 2>&1> /dev/null
then scp /var/www/html/mrtg/cam.jpg evg@192.168.0.11:/1TB/.zm/v/$DATA.jpg 2>&1 > /dev/null &
echo "`date +%H\ %M\ %S\ %N` scp 11 jpg [OK]" >> /var/www/html/mrtg/pir.txt
date +%s > /tmp/time0
scp /tmp/time0 evg@192.168.0.11:/tmp/time0
fi
#if ping -c 1 172.28.253.4 2>&1> /dev/null
# then scp /var/www/html/mrtg/cam.jpg lv@172.28.253.4:/a/$DATA.jpg 2>&1 > /dev/null &
# echo "`date +%H\ %M\ %S\ %N` scp 4 jpg [OK]" >> /var/www/html/mrtg/pir.txt
#fi
nano /sh/mint_pir.sh
#!/bin/bash
TIME0=$(cat /tmp/time0)
TIME1=$(date +"%s")
TIME2=$(echo "$TIME1-$TIME0" |bc)
TIME3='1860'
#TIME3='60'
#-eq - равно
#-lt - меньше
#-le - меньше или равно
#-ge - больше или равно
#-gt - больше
#-ne - не равно или нет
#
echo "$TIME2"
if [ $TIME2 -le $TIME3 ] &>/dev/null
then /sh/RHvoice_time.sh
# echo " прошло менее 31 мин"
fi
crontab -e
*/15 19-22 * * 1-5 if ! ps aux|grep -v color |grep -o "/kodi/kodi.bin" &> /dev/null; then /sh/mint_pir.sh; fi
среда, 23 октября 2019 г.
RHVoice
nano /sh/RHvoice_pogoda.sh
#!/bin/bash
# Санкт-Петербург
URLW1='https://neva.today/pogoda/'
wget -q -O- "$URLW1" > /tmp/pogoda_w
TEMP=$(cat /tmp/pogoda_w | grep "Сейчас" | grep -oE "[+-]*.[0-9]")
WETE=$(cat /tmp/pogoda_w | grep "acronym" | grep -oE "title*.*" | tail -n 1 | grep -oE "[а-яА-Я].*.[0-9]*." | sed 's/">/\ /g' | sed 's/<\/acronym>/ /g' | sed 's/<\/div>/ /g' | awk '{print $2,$3,$4,$5,$6,$7,$8,$9}')
echo "$TEMP" > /tmp/pogoda_temp1
echo "$WETE" > /tmp/pogoda_temp2
echo "Температура $TEMP, ветер $WETE"
#!/bin/bash
# Санкт-Петербург
URLW1='https://neva.today/pogoda/'
wget -q -O- "$URLW1" > /tmp/pogoda_w
TEMP=$(cat /tmp/pogoda_w | grep "Сейчас" | grep -oE "[+-]*.[0-9]")
WETE=$(cat /tmp/pogoda_w | grep "acronym" | grep -oE "title*.*" | tail -n 1 | grep -oE "[а-яА-Я].*.[0-9]*." | sed 's/">/\ /g' | sed 's/<\/acronym>/ /g' | sed 's/<\/div>/ /g' | awk '{print $2,$3,$4,$5,$6,$7,$8,$9}')
echo "$TEMP" > /tmp/pogoda_temp1
echo "$WETE" > /tmp/pogoda_temp2
echo "Температура $TEMP, ветер $WETE"
воскресенье, 20 октября 2019 г.
service_motion.sh
nano service_motion.sh:
-----------------------------------------------------------------
#!/bin/bash
while true; do
#P=$(ps aux | grep -v color | grep -E "service-pir.sh" | grep -E "T" | awk '{print $2}' | head -n 1)
#kill -9 $P
if [ `ps -ef| grep -E "*rec_pir.py" | wc -l ` -gt 1 ]
then
echo " is running"
else truncate -s 0 /tmp/p1s
ps aux |grep -v color|grep -v grep | grep "/py/rec_pir.py" | awk '{print $2}' > /tmp/p1s
for i in $(cat /tmp/p1s); do echo " kill $i"; kill -9 $i; done
ps aux|grep -v color|grep -v grep|grep "/py/rec_pir.py"
/usr/bin/python3 /py/rec_pir.py &
echo " restart"
# if [ `ps -ef| grep -E "*camera.py" | wc -l ` -gt 1 ]
# then
# echo " is running camera.py "
# PS1=$(ps aux | grep -E "*camera.py" | grep -v color | grep -v bash | grep -v grep | awk '{print $2}')
# echo " $PS1"
# kill -9 $PS1
# sleep 1
# /usr/bin/python3 /py/rec_pir.py &
# echo " restart"
# fi
fi
sleep 10
done
--------------------------------------------------------------------------
nano ps_kill_motion.sh:
truncate -s 0 /tmp/p1s
ps aux |grep -v color|grep -v grep | grep "/py/rec_pir.py" | awk '{print $2}' > /tmp/p1s
for i in $(cat /tmp/p1s); do echo " kill $i"; kill -9 $i; done
ps aux|grep -v color|grep -v grep|grep "/py/rec_pir.py"
--------------------------------------------------------------------------
-----------------------------------------------------------------
#!/bin/bash
while true; do
#P=$(ps aux | grep -v color | grep -E "service-pir.sh" | grep -E "T" | awk '{print $2}' | head -n 1)
#kill -9 $P
if [ `ps -ef| grep -E "*rec_pir.py" | wc -l ` -gt 1 ]
then
echo " is running"
else truncate -s 0 /tmp/p1s
ps aux |grep -v color|grep -v grep | grep "/py/rec_pir.py" | awk '{print $2}' > /tmp/p1s
for i in $(cat /tmp/p1s); do echo " kill $i"; kill -9 $i; done
ps aux|grep -v color|grep -v grep|grep "/py/rec_pir.py"
/usr/bin/python3 /py/rec_pir.py &
echo " restart"
# if [ `ps -ef| grep -E "*camera.py" | wc -l ` -gt 1 ]
# then
# echo " is running camera.py "
# PS1=$(ps aux | grep -E "*camera.py" | grep -v color | grep -v bash | grep -v grep | awk '{print $2}')
# echo " $PS1"
# kill -9 $PS1
# sleep 1
# /usr/bin/python3 /py/rec_pir.py &
# echo " restart"
# fi
fi
sleep 10
done
--------------------------------------------------------------------------
nano ps_kill_motion.sh:
truncate -s 0 /tmp/p1s
ps aux |grep -v color|grep -v grep | grep "/py/rec_pir.py" | awk '{print $2}' > /tmp/p1s
for i in $(cat /tmp/p1s); do echo " kill $i"; kill -9 $i; done
ps aux|grep -v color|grep -v grep|grep "/py/rec_pir.py"
--------------------------------------------------------------------------
stream_mjpg.py
Преобразовать html для блога:
http://www.elliotswan.com/postable/
bash:
#!/bin/bash
echo " Преобразовать html код"
echo " например для blogger.com"
echo " * * * нажать Enter чтобы продолжить * * *"
echo " Вставить html код..."
read T
truncate -s 0 /tmp/0.html
nano /tmp/0.html
sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g' /tmp/0.html > /tmp/1.html
cat /tmp/1.html
nano stream_mjpg.py
-----------------------------------------------
import picamera
import io
import logging
import socketserver
import datetime as dt
from threading import Condition
from http import server
PAGE="""\
<html>
<head>
<title>Raspberry Pi - My Camera</title>
</head>
<body>
<center><h1>Raspberry Pi - My Camera</h1></center>
<center><img src="stream.mjpg" width="960" height="580"></center>
</body>
</html>
"""
class StreamingOutput(object):
def __init__(self):
self.frame = None
self.buffer = io.BytesIO()
self.condition = Condition()
def write(self, buf):
if buf.startswith(b'\xff\xd8'):
self.buffer.truncate()
with self.condition:
self.frame = self.buffer.getvalue()
self.condition.notify_all()
self.buffer.seek(0)
return self.buffer.write(buf)
class StreamingHandler(server.BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.send_response(301)
self.send_header('Location', '/index.html')
self.end_headers()
elif self.path == '/index.html':
content = PAGE.encode('utf-8')
self.send_response(200)
self.send_header('Content-Type', 'text/html')
self.send_header('Content-Length', len(content))
self.end_headers()
self.wfile.write(content)
elif self.path == '/stream.mjpg':
self.send_response(200)
self.send_header('Age', 0)
self.send_header('Cache-Control', 'no-cache, private')
self.send_header('Pragma', 'no-cache')
self.send_header('Content-Type', 'multipart/x-mixed-replace; boundary=FRAME')
self.end_headers()
try:
while True:
with output.condition:
output.condition.wait()
frame = output.frame
self.wfile.write(b'--FRAME\r\n')
self.send_header('Content-Type', 'image/jpeg')
self.send_header('Content-Length', len(frame))
self.end_headers()
self.wfile.write(frame)
self.wfile.write(b'\r\n')
except Exception as e:
logging.warning(
'Removed streaming client %s: %s',
self.client_address, str(e))
else:
self.send_error(404)
self.end_headers()
class StreamingServer(socketserver.ThreadingMixIn, server.HTTPServer):
allow_reuse_address = True
daemon_threads = True
with picamera.PiCamera() as camera:
output = StreamingOutput()
camera.rotation = 180
camera.color_effects = (128,128)
camera.contrast = 60
camera.brightness = 80
camera.iso = 600
camera.resolution = (1920, 1080)
camera.framerate = 29
camera.start_recording(output, format='mjpeg')
try:
address = ('', 8000)
server = StreamingServer(address, StreamingHandler)
server.serve_forever()
finally:
camera.stop_recording()
http://www.elliotswan.com/postable/
bash:
#!/bin/bash
echo " Преобразовать html код"
echo " например для blogger.com"
echo " * * * нажать Enter чтобы продолжить * * *"
echo " Вставить html код..."
read T
truncate -s 0 /tmp/0.html
nano /tmp/0.html
sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g' /tmp/0.html > /tmp/1.html
cat /tmp/1.html
nano stream_mjpg.py
-----------------------------------------------
import picamera
import io
import logging
import socketserver
import datetime as dt
from threading import Condition
from http import server
PAGE="""\
<html>
<head>
<title>Raspberry Pi - My Camera</title>
</head>
<body>
<center><h1>Raspberry Pi - My Camera</h1></center>
<center><img src="stream.mjpg" width="960" height="580"></center>
</body>
</html>
"""
class StreamingOutput(object):
def __init__(self):
self.frame = None
self.buffer = io.BytesIO()
self.condition = Condition()
def write(self, buf):
if buf.startswith(b'\xff\xd8'):
self.buffer.truncate()
with self.condition:
self.frame = self.buffer.getvalue()
self.condition.notify_all()
self.buffer.seek(0)
return self.buffer.write(buf)
class StreamingHandler(server.BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.send_response(301)
self.send_header('Location', '/index.html')
self.end_headers()
elif self.path == '/index.html':
content = PAGE.encode('utf-8')
self.send_response(200)
self.send_header('Content-Type', 'text/html')
self.send_header('Content-Length', len(content))
self.end_headers()
self.wfile.write(content)
elif self.path == '/stream.mjpg':
self.send_response(200)
self.send_header('Age', 0)
self.send_header('Cache-Control', 'no-cache, private')
self.send_header('Pragma', 'no-cache')
self.send_header('Content-Type', 'multipart/x-mixed-replace; boundary=FRAME')
self.end_headers()
try:
while True:
with output.condition:
output.condition.wait()
frame = output.frame
self.wfile.write(b'--FRAME\r\n')
self.send_header('Content-Type', 'image/jpeg')
self.send_header('Content-Length', len(frame))
self.end_headers()
self.wfile.write(frame)
self.wfile.write(b'\r\n')
except Exception as e:
logging.warning(
'Removed streaming client %s: %s',
self.client_address, str(e))
else:
self.send_error(404)
self.end_headers()
class StreamingServer(socketserver.ThreadingMixIn, server.HTTPServer):
allow_reuse_address = True
daemon_threads = True
with picamera.PiCamera() as camera:
output = StreamingOutput()
camera.rotation = 180
camera.color_effects = (128,128)
camera.contrast = 60
camera.brightness = 80
camera.iso = 600
camera.resolution = (1920, 1080)
camera.framerate = 29
camera.start_recording(output, format='mjpeg')
try:
address = ('', 8000)
server = StreamingServer(address, StreamingHandler)
server.serve_forever()
finally:
camera.stop_recording()
rec_pir_sensor.py
import RPi.GPIO as GPIO
import time
import subprocess
GPIO.setmode(GPIO.BCM)
#PIR
GPIO.setup(17, GPIO.IN)
try:
time.sleep(2) # to stabilize sensor
while True:
if GPIO.input(17):
print("Motion Detected...")
rc = subprocess.call("/sh/rec-stream.sh")
## time.sleep(5)
print(" ...")
# time.sleep(0.1)
time.sleep(0.5)
except:
GPIO.cleanup()
import time
import subprocess
GPIO.setmode(GPIO.BCM)
#PIR
GPIO.setup(17, GPIO.IN)
try:
time.sleep(2) # to stabilize sensor
while True:
if GPIO.input(17):
print("Motion Detected...")
rc = subprocess.call("/sh/rec-stream.sh")
## time.sleep(5)
print(" ...")
# time.sleep(0.1)
time.sleep(0.5)
except:
GPIO.cleanup()
rec stream mjpg
#!/bin/bash
echo "`date +%H\ %M\ %S\ %N` bash start"
#if ping -c 1 172.28.253.4 2>&1> /dev/null
# then ssh lv@172.28.253.4 '/sh/rec-stream.sh' &
# echo "`date +%H\ %M\ %S\ %N` lv rec stream start [OK]"
#fi
if ping -c 1 192.168.0.11 2>&1> /dev/null
then ssh evg@192.168.0.11 '/sh/rec_stream.sh' &
echo "`date +%H\ %M\ %S\ %N` asus rec stream start [OK]"
fi
#if ls /tmp/ | grep -oE "*.mp4" &>/dev/null
# then rm /tmp/*.mp4
#fi
#echo "`date +%H\ %M\ %S\ %N` rm .mp4 [OK]"
DATA=$(date +%Y-%m-%d_%H-%M-%S_%N)
echo "`date +%H\ %M\ %S\ %N` ffmpeg rec [OK]"
#ffmpeg -i http://127.0.0.1:8000/stream.mjpg -to 0:02 -c:v copy -c:a copy /tmp/$DATA.mp4 2> /dev/null
#echo "`date +%H\ %M\ %S\ %N` ffmpeg stop [OK]"
#if ls /var/www/html/mrtg/ | grep -oE "cam1.jpg" &>/dev/null
# then rm /var/www/html/mrtg/cam1.jpg
#fi
#echo "`date +%H\ %M\ %S\ %N` bash rm jpg [OK]"
ffmpeg -f MJPEG -y -i http://127.0.0.1:8000/stream.mjpg \
-r 1 -vframes 1 -q:v 1 /var/www/html/mrtg/cam1.jpg 2> /dev/null
echo "`date +%H\ %M\ %S\ %N` frames [OK]"
convert /var/www/html/mrtg/cam1.jpg -background none -fill black -box 'white' -gravity South \
-pointsize 20 -annotate +0+1050 $DATA /var/www/html/mrtg/cam.jpg
echo "`date +%H\ %M\ %S\ %N` image convert [OK]"
if ping -c 1 192.168.0.11 2>&1> /dev/null
then scp /var/www/html/mrtg/cam.jpg evg@192.168.0.11:/1TB/.zm/v/$DATA.jpg 2>&1 > /dev/null &
echo "`date +%H\ %M\ %S\ %N` scp 11 jpg [OK]"
fi
if ping -c 1 172.28.253.4 2>&1> /dev/null
then scp /var/www/html/mrtg/cam.jpg lv@172.28.253.4:/a/$DATA.jpg 2>&1 > /dev/null &
echo "`date +%H\ %M\ %S\ %N` scp 4 jpg [OK]"
fi
--------------------------------------------------------------
nano rec_stream.sh asus
#!/bin/bash
if ! ps aux | grep -v color | grep -v grep | grep -E ffmpeg &> /dev/null
then DATA=$(date +%Y-%m-%d_%H-%M-%S_%N)
ffmpeg -i http://192.168.0.4:8000/stream.mjpg \
-to 0:10 -c:v copy -c:a copy /1TB/.zm/v/$DATA.mp4 2> /dev/null
fi
echo "`date +%H\ %M\ %S\ %N` bash start"
#if ping -c 1 172.28.253.4 2>&1> /dev/null
# then ssh lv@172.28.253.4 '/sh/rec-stream.sh' &
# echo "`date +%H\ %M\ %S\ %N` lv rec stream start [OK]"
#fi
if ping -c 1 192.168.0.11 2>&1> /dev/null
then ssh evg@192.168.0.11 '/sh/rec_stream.sh' &
echo "`date +%H\ %M\ %S\ %N` asus rec stream start [OK]"
fi
#if ls /tmp/ | grep -oE "*.mp4" &>/dev/null
# then rm /tmp/*.mp4
#fi
#echo "`date +%H\ %M\ %S\ %N` rm .mp4 [OK]"
DATA=$(date +%Y-%m-%d_%H-%M-%S_%N)
echo "`date +%H\ %M\ %S\ %N` ffmpeg rec [OK]"
#ffmpeg -i http://127.0.0.1:8000/stream.mjpg -to 0:02 -c:v copy -c:a copy /tmp/$DATA.mp4 2> /dev/null
#echo "`date +%H\ %M\ %S\ %N` ffmpeg stop [OK]"
#if ls /var/www/html/mrtg/ | grep -oE "cam1.jpg" &>/dev/null
# then rm /var/www/html/mrtg/cam1.jpg
#fi
#echo "`date +%H\ %M\ %S\ %N` bash rm jpg [OK]"
ffmpeg -f MJPEG -y -i http://127.0.0.1:8000/stream.mjpg \
-r 1 -vframes 1 -q:v 1 /var/www/html/mrtg/cam1.jpg 2> /dev/null
echo "`date +%H\ %M\ %S\ %N` frames [OK]"
convert /var/www/html/mrtg/cam1.jpg -background none -fill black -box 'white' -gravity South \
-pointsize 20 -annotate +0+1050 $DATA /var/www/html/mrtg/cam.jpg
echo "`date +%H\ %M\ %S\ %N` image convert [OK]"
if ping -c 1 192.168.0.11 2>&1> /dev/null
then scp /var/www/html/mrtg/cam.jpg evg@192.168.0.11:/1TB/.zm/v/$DATA.jpg 2>&1 > /dev/null &
echo "`date +%H\ %M\ %S\ %N` scp 11 jpg [OK]"
fi
if ping -c 1 172.28.253.4 2>&1> /dev/null
then scp /var/www/html/mrtg/cam.jpg lv@172.28.253.4:/a/$DATA.jpg 2>&1 > /dev/null &
echo "`date +%H\ %M\ %S\ %N` scp 4 jpg [OK]"
fi
--------------------------------------------------------------
nano rec_stream.sh asus
#!/bin/bash
if ! ps aux | grep -v color | grep -v grep | grep -E ffmpeg &> /dev/null
then DATA=$(date +%Y-%m-%d_%H-%M-%S_%N)
ffmpeg -i http://192.168.0.4:8000/stream.mjpg \
-to 0:10 -c:v copy -c:a copy /1TB/.zm/v/$DATA.mp4 2> /dev/null
fi
среда, 2 октября 2019 г.
ban ip iptables bash
#!/bin/bash
# clear
if cat /var/log/auth.log | grep -oE "ailed|Bad protocol" &> /dev/null;
then sudo iptables -F
## ip error auth
cat /var/log/auth.log | grep -E "ailed|Bad protocol" >> /tmp/banip
#
sed '/ailed/d' /var/log/auth.log > /tmp/aut && mv /tmp/aut /var/log/auth.log
sed '/Bad protocol/d' /var/log/auth.log > /tmp/aut && mv /tmp/aut /var/log/auth.log
cat </tmp/ip-allow-log;
192.168.1.2
9.2.
1.1.
EOF
for IP1 in $(cat /tmp/ip-allow-log); do echo "ignore $IP1"; sed "/$IP1/d" /tmp/banip > /tmp/banip1 && mv /tmp/banip1 /tmp/banip; done
sudo /etc/init.d/rsyslog restart
#
cat /tmp/banip | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}' | sort | uniq > /tmp/ban-ip
##
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
## port 22,80,443
PORT='22,80,443'
## ip
cat </tmp/ip-allow16;
5.1.0.0
5.1.0.0
8.3.0.0
8.2.0.0
EOF
for IP in $(cat /tmp/ip-allow16); do echo "ACCEPT $IP"; sudo iptables -A INPUT -i ens2 -s $IP/16 -p tcp -m multiport --dport $PORT -j ACCEPT; done
##cat </tmp/ip-allow24;
##172.28.253.0
##172.28.253.0
##EOF
##for IP in $(cat /tmp/ip-allow24); do echo "ACCEPT $IP"; sudo iptables -A INPUT -i ens2 -s $IP/24 -j ACCEPT; done
cat </tmp/ip-allow32;
192.168.1.3
192.168.1.4
EOF
for IP in $(cat /tmp/ip-allow32); do echo "ACCEPT $IP"; sudo iptables -A INPUT -i ens2 -s $IP/32 -j ACCEPT; done
## read line
echo "`cat /tmp/ban-ip | wc -l` количество IP"
## ban ip
for IP in $(cat /tmp/ban-ip); do echo "Banning IN $IP"; sudo iptables -A INPUT -i ens2 -s $IP/32 -j DROP; done
for IP in $(cat /tmp/ban-ip); do echo "Banning OUT $IP"; sudo iptables -A OUTPUT -o ens2 -d $IP/32 -j DROP; done
sudo iptables -A INPUT -i ens2 -p tcp -m multiport --dport 80,443 -j ACCEPT
sudo iptables -A INPUT -i ens2 -j DROP
#echo " read table"
#read TM
#sudo iptables-save
echo "`date -R` update ban" >> /var/log/ban-ip.txt
cp /var/log/ban-ip.txt /var/www/html/ban-ip.txt
fi
# clear
if cat /var/log/auth.log | grep -oE "ailed|Bad protocol" &> /dev/null;
then sudo iptables -F
## ip error auth
cat /var/log/auth.log | grep -E "ailed|Bad protocol" >> /tmp/banip
#
sed '/ailed/d' /var/log/auth.log > /tmp/aut && mv /tmp/aut /var/log/auth.log
sed '/Bad protocol/d' /var/log/auth.log > /tmp/aut && mv /tmp/aut /var/log/auth.log
cat <
192.168.1.2
9.2.
1.1.
EOF
for IP1 in $(cat /tmp/ip-allow-log); do echo "ignore $IP1"; sed "/$IP1/d" /tmp/banip > /tmp/banip1 && mv /tmp/banip1 /tmp/banip; done
sudo /etc/init.d/rsyslog restart
#
cat /tmp/banip | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}' | sort | uniq > /tmp/ban-ip
##
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
## port 22,80,443
PORT='22,80,443'
## ip
cat <
5.1.0.0
5.1.0.0
8.3.0.0
8.2.0.0
EOF
for IP in $(cat /tmp/ip-allow16); do echo "ACCEPT $IP"; sudo iptables -A INPUT -i ens2 -s $IP/16 -p tcp -m multiport --dport $PORT -j ACCEPT; done
##cat <
##172.28.253.0
##172.28.253.0
##EOF
##for IP in $(cat /tmp/ip-allow24); do echo "ACCEPT $IP"; sudo iptables -A INPUT -i ens2 -s $IP/24 -j ACCEPT; done
cat <
192.168.1.3
192.168.1.4
EOF
for IP in $(cat /tmp/ip-allow32); do echo "ACCEPT $IP"; sudo iptables -A INPUT -i ens2 -s $IP/32 -j ACCEPT; done
## read line
echo "`cat /tmp/ban-ip | wc -l` количество IP"
## ban ip
for IP in $(cat /tmp/ban-ip); do echo "Banning IN $IP"; sudo iptables -A INPUT -i ens2 -s $IP/32 -j DROP; done
for IP in $(cat /tmp/ban-ip); do echo "Banning OUT $IP"; sudo iptables -A OUTPUT -o ens2 -d $IP/32 -j DROP; done
sudo iptables -A INPUT -i ens2 -p tcp -m multiport --dport 80,443 -j ACCEPT
sudo iptables -A INPUT -i ens2 -j DROP
#echo " read table"
#read TM
#sudo iptables-save
echo "`date -R` update ban" >> /var/log/ban-ip.txt
cp /var/log/ban-ip.txt /var/www/html/ban-ip.txt
fi
Подписаться на:
Сообщения (Atom)
h265.sh
#!/bin/bash file="../mp4" if [ -d $file ]; then echo " Директория существует :-) " for i in *.mp4; do f...
-
30 мая воплотилась в жизнь давняя мечта -- покататься на лодке. Плюс к тому в тот же день я попробовал свои силы в тире. Не разочаровался в ...
-
подпроцесс новый сценарий post-removal возвратил код ошибки 1 ls /var/lib/dpkg/info | grep "mail.ru-cloud" mail.ru-cloud.list ...