-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron-yt-playlist.sh
41 lines (33 loc) · 1.01 KB
/
cron-yt-playlist.sh
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
#!/bin/bash
# Directory where the script and JSON file are located
SCRIPT_DIR="$HOME/cronjobs/yt-playlist-downloader"
CRON_ERROR_LOG="$SCRIPT_DIR/yt-playlist-errors-log.txt"
# Change to the script directory
cd "$SCRIPT_DIR"
# Function to attempt WiFi connection
attempt_wifi_connection() {
local tries=3
local interval=5
local connected=false
for (( i=1; i<=tries; i++ )); do
nmcli connect dev wifi wifiname password ********
sleep $interval
if nmcli -t -f WIFI g | grep -q 'enabled'; then
connected=true
break
fi
done
echo $connected
}
# Check for WiFi connection
if ! nmcli -t -f WIFI g | grep -q 'enabled'; then
if [[ $(attempt_wifi_connection) == "false" ]]; then
echo "$(date): WiFi is not connected." >>"$CRON_ERROR_LOG"
exit 1
fi
fi
# Execute download script
bash "$SCRIPT_DIR/playlist-downloader.sh" 2>>
>(while read -r line; do echo "$(date): $line"; done >> "$CRON_ERROR_LOG")
#shutdown after completion
shutdown now