作为一个脚本新手,我的脚本中有一个错误,需要重新审视。
我正在编写一个脚本,只下载多个目录中的一个,并提取其中的内容。这个脚本是由完成的
- 创建数组并使用该数组中的变量
- 使用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
任何关于如何纠正这一点或如何改进剧本的想法都将受到欢迎。
#!/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;
**fi**
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;
**fi**
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
我假设这就是代码的布局方式。你需要为你的"if"关闭"fi"。此外,看看TLDP,它在我刚开始的时候对我帮助很大。