简体   繁体   中英

Recursive File Renaming script doesn't work from crontab

Crontab launches the script, the podcast updates correctly, but none of the file renaming (1st loop) or file moving (2nd loop). If I run the script from the command-line, works perfectly.

I have added the "echo" lines to troubleshoot, the $file variable is consistent when run through command-line and 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

here is the debugging output from the script

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

you have a mistake in the first line, you should change

#/bin/sh to #!/bin/sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM