Bit of a script newbie, I have a mistake in my script that needs fresh eyes.
I am writing a script that will download multiple directories one only and extract content inside them. The script does this by
- creating an array and using variables from that array
- using an sqlite database to ensure that downloading only happens once - essential as this script will run every 30 minutes
- run winrar and ffmpeg to extract the files
The following script works (it runs), but does not do what I want - here's the script
#!/bin/sh
set -x
cd /cygdrive/q/private/deluge/zeroday/
Progs=( * )
for show in "${Progs[@]%*/}"; do
cd ~/scripts/sqlite/
exists=$( sqlite3 dir.db "select count(*) from zero where episode=\"${show}\"" )
if (( exists > 0 )); then
echo "Show already downloaded"
else
~/scripts/synctorrents1.sh
cd /cygdrive/h/Rippers/Zeroday/
dire=( * )
for rip in "${dire[@]%*/}"; do
cd /cygdrive/h/Rippers/Zeroday/${rip}/
"/cygdrive/c/Program Files/WinRAR/unrar" x *.rar
"/cygdrive/c/Program Files/get_iplayer/FFmpeg/ffmpeg-2.2.3-win32-static/bin/ffmpeg.exe" -i "${rip}.mkv"$
mv ${rip}.mp4 /cygdrive/h/Rippers/MB3_Watch/
rm -f ${rip}.mkv
rm -rf /cygdrive/h/Rippers/Zeroday/${rip}/
done
fi
done
exit 0
The script calls another script, which does the downloading using LFTP. My problem is when I ask the script to download one directory, it downloads all directories. Here is that script -
#!/bin/sh
login="xxxx"
pass="xxxx"
host="xxxx"
remote_dir="/media/sdi1/home/macburp/private/deluge/zeroday/"
local_dir="/cygdrive/h/Rippers/Zeroday"
cd /cygdrive/q/private/deluge/zeroday/
Progs=( * )
trap "rm -f /tmp/synctorrent.lock" SIGINT SIGTERM
if [ -e /tmp/synctorrent.lock ]
then
echo "Synctorrent is running already."
exit 1
else
touch /tmp/synctorrent.lock
for show in "${Progs[@]%*/}"; do
lftp -p 22 -u $login,$pass sftp://$host << EOF
set mirror:use-pget-n 7
mirror -c -P1 --log=synctorrents.log $remote_dir/${show}/ local_dir/${show}/
quit
EOF
done
rm -f /tmp/synctorrent.lock
trap - SIGINT SIGTERM
exit 0
fi
This script (obtained from elsewhere) is picky - it doesn't want to work when the script is properly indented, and does not like being edited.
I see that I now need to combine the two scripts, so I've tried this -
#!/bin/sh
set -x
login="xxxx"
pass="xxxxxx"
host="xxxxxxxxxx"
remote_dir="/media/sdi1/home/macburp/private/deluge/zeroday/"
local_dir="/cygdrive/h/Rippers/Zeroday"
cd /cygdrive/q/private/deluge/zeroday/
Progs=( * )
for show in "${Progs[@]%*/}"; do
cd ~/scripts/sqlite/
exists=$( sqlite3 dir.db "select count(*) from zero where episode=\"${show}\"" )
if (( exists > 0 )); then
echo "Show already downloaded"
else
trap "rm -f /tmp/synctorrent.lock" SIGINT SIGTERM
if [ -e /tmp/synctorrent.lock ]
then
echo "Synctorrent is running already."
exit 1
else
touch /tmp/synctorrent.lock
lftp -p 22 -u $login,$pass sftp://$host << EOF
set mirror:use-pget-n 7
mirror -c -P1 --log=synctorrents.log $remote_dir/${show}/ $local_dir/${show}/
quit
EOF
cd /cygdrive/h/Rippers/Zeroday/
dire=( * )
for rip in "${dire[@]%*/}"; do
cd /cygdrive/h/Rippers/Zeroday/${rip}/
"/cygdrive/c/Program Files/WinRAR/unrar" x *.rar
"/cygdrive/c/Program Files/get_iplayer/FFmpeg/ffmpeg-2.2.3-win32-static/bin/ffmpeg.exe" -i "${rip}.mkv" -c:v $
mv ${rip}.mp4 /cygdrive/h/Rippers/MB3_Watch/
rm -f ${rip}.mkv
rm -rf /cygdrive/h/Rippers/Zeroday/${rip}/
done
exit 0
fi
This fails with the following error -
/home/Paul/scripts/sqlite/syncsqlremoterip5.sh: line 44: syntax error: unexpected end of file
Any thoughts oh how to put this right or on how to improve the script would be welcome.