有点脚本新手,我的脚本中有一个错误需要重新审视。
我正在编写一个脚本,它将仅下载多个目录并提取其中的内容。该脚本通过
- 创建一个数组并使用该数组中的变量
- 使用 sqlite 数据库确保下载只发生一次 - 必不可少,因为此脚本将每 30 分钟运行一次
- 运行 winrar 和 ffmpeg 提取文件
以下脚本有效(它运行),但没有做我想要的 - 这是脚本
#!/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
该脚本调用另一个脚本,该脚本使用 LFTP 进行下载。我的问题是当我要求脚本下载一个目录时,它会下载所有目录。这是那个脚本 -
#!/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
这个脚本(从其他地方获得)很挑剔 - 当脚本正确缩进时它不想工作,并且不喜欢被编辑。
我看到我现在需要组合这两个脚本,所以我尝试了这个 -
#!/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
这失败并出现以下错误 -
/home/Paul/scripts/sqlite/syncsqlremoterip5.sh: line 44: syntax error: unexpected end of file
欢迎任何关于如何正确处理或如何改进脚本的想法。