递归文件重命名脚本在crontab中不起作用

时间:2013-05-30 03:32:38

标签: bash cron crontab

Crontab启动脚本,播客正确更新,但没有文件重命名(第一循环)或文件移动(第二循环)。 如果我从命令行运行脚本,那就完美了。

我已添加“echo”行进行故障排除,$ file变量在通过命令行和crontab运行时是一致的。

#/bin/sh

# Mad Money updates at 6:40 pm (timezone?) M-F
# At 6:30 pm CST it was ready to download
# http://podcast.cnbc.com/mmpodcast/lightninground.xml

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
echo "paths"
echo $PATH

podcast_folder=$"/home/zenon/podcasts/MAD_MONEY_W__JIM_CRAMER_-_Full_Episode"
episode_folder=$"/mnt/black-2tb-001/plex-server/shows/Mad-Money/Season-1"

hpodder update
sleep 1

hpodder download
sleep 1

cd ${podcast_folder}

for file in "$podcast_folder"/*.mp4; do
    echo "Processing ${file}"
    #"MadMoney-" Name
    name=${file:60:9}
        echo "podcast name is ${name}"
    #"04" Month
    month=${file:69:2}
        echo "month is ${month}"
    #"18" Day
    day=${file:71:2}
        echo "day is ${day}"
    #"13" yr
    yr=${file:73:2}
        echo "year is 20${yr}"
    title="${name}20${yr}.${month}.${day}.mp4"

        echo "file ${file}"
        echo "title ${title}"

#   cp ${file} ${title}
    mv ${file} ${title}

done

cd ${podcast_folder}


for file in "$podcast_folder"/*.mp4; do
    chown zenon:plex ${file}
    mv ${file} ${episode_folder}
done

# deletes any files older than 9 days
find ${episode_folder} -type f -mtime +9 -exec rm {} \;

exit

这是脚本

的调试输出
cat cron.log 
paths
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
1 podcast(s) to consider

Get: 4 MAD MONEY W/ JIM CRAMER - Full Episode                                  
100%                                                                   1 B/s 0s
0 episode(s) to consider from 1 podcast(s)
0%                                                                     0 B/s 0s
Processing $/home/zenon/podcasts/MAD_MONEY_W__JIM_CRAMER_-_Full_Episode/*.mp4

1 个答案:

答案 0 :(得分:1)

你在第一行有错,你应该改变

#/bin/sh#!/bin/sh