Results 1 to 4 of 4

Thread: Need help for bash loop script

  1. #1

    Default Need help for bash loop script

    I'm trying to create for myself a simple script that downloads the latest torrent for an anime series that I watch. However I'm a freshmen in college and just passed a linux basics class that only touched on shell scripting. The website I download the torrent from releases the latest episode about once per week and each torrent is named in an ascending order according to each episode number (eg. x241.torrent, x242.torrent, x243.torrent, and so on...). I am asking for help on creating a counter that looks for the newest episode every time it successfully completes the entire loop.

    This is the basic layout of the script:

    1. +wait until specified time (hh:mm)
    2. +check for connection
    |--+fail (wait 5 min, then loop back to 2)
    | |--if fail =10, loop back to 1
    3. +count and determine current #
    4. +apply variable to name of torrent to
    | be downloaded (b???.torrent)

    5. +wget exact url
    |--+ if 404 returned, wait 10 min, then loop back to 5
    | |--if fail =10, loop back to 1
    6. +[command line bittorrent client] open torrent
    7. +set save path to /home/.temp
    8. +rm torrent metafile (it's useless at this point)
    9. +once finished, remove torrent from que
    10.+cp download to other dir; rm original from /.temp folder
    11.+loop back to 1

    Since this script will be on my server, making it automatic would be very convenient for me.
    Can I do this?
    Last edited by Entity; 02-Jan-2010 at 05:51.

  2. #2
    DannyTheNinja

    Default

    Mod note: As a forewarning, please don't post URLs to any copyrighted content or metafiles thereof in this thread (or anywhere on ADISC). He's only asked for help with bash scripting, which inherently has nothing to do with illegal downloading. As such, please refrain from torrent-related discussion here.



    Quote Originally Posted by Entity' View Post
    1. +wait until specified time (hh:mm)
    Use cron for that, not bash.


    Quote Originally Posted by Entity' View Post
    2. +check for connection
    |--+fail (wait 5 min, then loop back to 2)
    | |--if fail =10, loop back to 1
    Try pinging a well-known Internet host, like Google or 4.2.2.2 (a Level3 nameserver geocasted IP). Ping on UNIX systems keeps going until you Control-C it, so use -c2 to limit it to two pings.


    Quote Originally Posted by Entity' View Post
    3. +count and determine current #
    This might be a little trickier... maybe have a file in /home/.temp containing the episode number. Read it in at the beginning, and echo out one higher number upon successful completion.


    Quote Originally Posted by Entity' View Post
    4. +apply variable to name of torrent to
    | be downloaded (b???.torrent)
    wget -O target_filename http://url


    Quote Originally Posted by Entity' View Post
    5. +wget exact url
    |--+ if 404 returned, wait 10 min, then loop back to 5
    | |--if fail =10, loop back to 1
    You can't check exactly for a 404 error, but if wget fails for whatever reason the standard array of tests should work.

    Also, how are you getting the URL? Is it auto-generated? Make sure the URL to the file you're downloading is predictable.


    Quote Originally Posted by Entity' View Post
    6. +[command line bittorrent client] open torrent
    bittorrent-console


    Quote Originally Posted by Entity' View Post
    7. +set save path to /home/.temp
    This should be a command-line option to bittorrent-console. Make sure you're saving the filename under some subdirectory with an easy-to-predict name, like "Episode 242."


    Quote Originally Posted by Entity' View Post
    8. +rm torrent metafile (it's useless at this point)
    9. +once finished, remove torrent from [queue]
    Should be taken care of by rming the .torrent and echoing out the next higher episode number to the state file.


    Quote Originally Posted by Entity' View Post
    10.+cp download to other dir; rm original from /.temp folder
    Should be obvious


    Quote Originally Posted by Entity' View Post
    11.+loop back to 1
    Just exit, and wait for cron to run the script next time.

    --Danny

  3. #3

    Default

    Thanks for the help, and bittorrent is not illegal, especially for this. It's the other things that make it illegal.

    As for the forewarning, I have heeded your advice about not posting urls by not listing any specifics (except for the tv show name; which has been fixed) in my original post. But thank you for the word of warning anyway.



    Also, how are you getting the URL? Is it auto-generated?
    Yes. The url I am pointing it to is static up to the point of the actual name of the torrent file where only the numbers inside the name change. Yes it is quite predicable, an it will probably be generated from a list (csv, maybe).



    Just exit, and wait for cron to run the script next time.
    No. I want it to loop so that it will continue with minimal intervention since the server itself will also be unattended. Therefore, it would make sense that it would just do it automatically rather than create a script that would essentially make me do everything manually. Besides having it run as it's own process is more efficient than having something else run it.

    Once again, thank you very much. I do value your help.

  4. #4

    Default

    No. Just set up a cron job. Thats much better than a sleeping bash script.

Similar Threads

  1. EN9800GT Infinite Loop Bug
    By jhgjaesfuiawgef in forum Computers & Gaming
    Replies: 3
    Last Post: 25-Dec-2009, 22:36
  2. Bash xbox?
    By WilliamSoftpaw in forum Computers & Gaming
    Replies: 4
    Last Post: 25-Nov-2009, 07:38
  3. Flash Action Script 2.0
    By game_designer in forum Computers & Gaming
    Replies: 4
    Last Post: 09-Mar-2008, 00:32

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
ADISC.org - the Adult Baby / Diaper Lover / Incontinence Support Community.
ADISC.org is designed to be viewed in Firefox, with a resolution of at least 1280 x 1024.