[Tutorial] Cron + Various seedbox scripts.
Register

We are the best invite forum on the internet! Here you will find free invites, free seedboxes, free bonuses, and much more. Our members know the true meaning of sharing and have created a truly global bittorent community! Our site has the most up to date information on all private trackers and our members will guide you and introduce you to this truly secretive and enlightened club. Ready to get started? Register now!


Results 1 to 2 of 2
  1. #1

    Join Date
    Jun 2012
    Location
    Canada
    Posts
    154

    Default [Tutorial] Cron + Various seedbox scripts.

    Hello,
    This is my first tutorial here, just thought I would share some of my handy seedbox scripts.. I am a Software Engineer, and I do Linux scripting as a hobby, and as a part of my day job (I automate a lot of our build / test / install procedures). If you have any script requests / modifications, let me know and I may be of help. Also, please let me know if I made any typo's, I had to make some modifications on the fly to make them more generic.

    First and most important, Cron (scheduler) is awesome. SSH into your server under the user you want cron to run, and execute the following command, then paste the code. IMPORTANT: Some cron have a bug, you must insert a blank line after your command.

    • crontab -e

    Code:
    */2 * * * * find /home/seed/script/ -name "*.sh" -print0 | xargs -0 -P 0 -n 1 bash
    Now, any scripts (ending in .sh) you place in your special folder, will automatically run every 2 minutes!

    So here are some quick n dirty sample scripts I have used on my seedbox running Ubuntu and on my Windows 7 client computer.


    • clean_name.sh: remove common windows garbage chars / spaces, then moves the torrents to your rtorrent watch directory

    Code:
    #!/bin/bash
    cd /home/seed/tor/
    rename 's/\ /_/g' ./*
    rename 's/[\(\)\-=\+]//g' ./*
    rename 's/\[//g' ./*
    rename 's/\]//g' ./*
    chmod 777 ./*
    mv ./* /home/seed/watch/

    • log_ram.sh: Log the current free ram + datestamp to a file, helpful for VPS seedboxes to monitor your ram usage for a day while downloading.

    Code:
    #!/bin/bash
    LOGFILE=/home/seed/mem.txt
    DD=`date +%D-%H:%M:%S`
    FREE=`free | grep Mem | awk '{print $4}'`
    echo $FREE $DD >> $LOGFILE

    • check_reboot.sh: Quick way to reboot server, restart rTorrent, or clear rTorrent cache, all you need to do is scp an empty file to your home directory.

    Code:
    #!/bin/bash
    REBOOT_FILE=/home/seed/reboot.txt
    RESTART_FILE=/home/seed/restart.txt
    CLEAR_FILE=/home/seed/clear.txt
    SESSION_FOLDER=/home/seed/.sesson/
    
    if [ -e $REBOOT_FILE ]; then
        rm $REBOOT_FILE
        shutdown -r now
    fi
    
    if [ -e $RESTART_FILE ]; then
        rm $RESTART_FILE
        kill -15 `pgrep rtorrent`
    fi
    
    if [ -e $CLEAR_FILE ]; then
        rm $CLEAR_FILE
        kill -15 `pgrep rtorrent`
        rm $SESSION_FOLDER/*
    fi




    • start_rtorrent.sh: Start your rTorrent process, while allowing you to bring it to the foreground later.
    • apt-get install dtach (to install it)
    • dtach -a /tmp/rtorrent.dtach (to connect at a later time)

    Code:
    #!/bin/bash
    LOGFILE=/home/seed/rtorrent.log
    running=$(pgrep rtorrent | tr -d ' ')
    if [ -z "$running" ]; then
        echo "Restarting rTorrent" | tee -a $LOGFILE
        date >> $LOGFILE
        TERM=xterm dtach -n /tmp/rtorrent.dtach /usr/local/bin/rtorrent 2>&1 >> $LOGFILE
    fi

    • check_complete.sh: A simple folder watcher script, which emails you when folder contents change. Does NOT require .rtorrent.rc changes (eg: trigger script on torrent complete)
    • requires the free mailsend utility

    Code:
    #!/bin/bash
    # Detect file/folder changes to a specific folder
    # Email alerts containing list of additions using Gmail SMTP, create a new gmail account that is solely used to SEND messages.
    # Also includes in the email, the ammount of free disk space remaining.
    
    FROM="yournewgmailaccount@gmail.com"
    TO="yourpersonalemail@youremail.com"
    USER="yournewgmailaccount"
    KEY="yournewgmailaccount_password"
    SUBJECT="Download Completed!"
    CHANGES="change_detected.txt"
    WATCH_FOLDER="/home/seed/complete"
    SERVER="smtp.gmail.com"
    PORT=465
    OLD=".complete_old"
    NEW=".complete_new"
    LOG="/home/seed/mailsend.log"
    
    if [ -e $NEW ]; then
        mv $NEW $OLD
    fi
    ls $WATCH_FOLDER > $NEW
    if [ -e $OLD -a -e $NEW ]; then
        diff $OLD $NEW | grep ">" | sed -e "s/>/COMPLETE:/" > $CHANGES
    fi
    if [ -s $CHANGES ]; then
        echo `df -h | grep simfs | awk '{print $4 " of " $2 " free space remaining"}'` >> $CHANGES
        cat $CHANGES >> $LOG
        /usr/local/bin/mailsend -to $TO -from $FROM -ssl -smtp $SERVER -port $PORT -sub "$SUBJECT" +cc +bc -v -auth-login -user $USER -pass $KEY -attach "$CHANGES,text/plain,i" >> $LOG 2>&1
    fi
    rm $CHANGES 2> /dev/null
    Windows Scripts assume that the .bat files resides in a folder with WinScp.com and WinScp.exe. Create a saved session named "seedbox_session" with saved password.


    • upload_torrents.bat: Automatically upload torrents to seedbox with a single click.

    Code:
    winscp.com /console /command "open seedbox_session "option batch on" "option confirm off" "cd /home/seed/tor" "put *.torrent" exit
    if errorlevel 1 goto ERROR
    echo Success!
    rem uncomment either of these lines if you wish
    rem move *.torrent c:\torrent_archive
    rem del /Q *.torrent
    goto END
    
    :ERROR
    echo Error!
    
    :END
    pause

    • upload_script.bat: Quickly upload a script (ensure line ending is unix! use a quality text editor like notepad++)

    Code:
    winscp.com /console /command "open seedbox_session "option batch on"  "option confirm off" "cd /home/seed/scripts" "put *.sh" exit
    if errorlevel 1 goto ERROR
    echo Success!
    goto END
    
    :ERROR
    echo Error!
    
    :END
    pause

    • get_complete.bat: Download all your complete files from your seedbox, while first giving you a list of files/folders with disk usage. lcd = local folder, cd = remote. Note, this also deletes the file off the server, if you don't like that behavior, remove -delete from "get" command.

    Code:
    winscp.com /console /command "open seedbox_session" "option batch off"  "option confirm off" "lcd C:\Downloads" "cd /home/seed/complete" "call echo Files To  Download:" "call du -ch" "get -delete *" exit
    if errorlevel 1 goto ERROR
    echo Success
    goto END
    
    :ERROR
    echo Error!
    
    :END
    pause
    Hope that helps some of you automate your life!
    Last edited by ihatespam; September 12th, 2012 at 06:27 PM. Reason: highlight note in red


  2. To remove ads become VIP. Inquire about advertising here.
  3. #2

    Join Date
    Jun 2012
    Location
    Canada
    Posts
    154

    Default

    Sorry for the typo in restart script. Fixed now.

    If your not running as root.. You would need to "sudo shutdown -r now" and add
    user ALL=(ALL) NOPASSWD: /sbin/shutdown
    To /etc/sudoers

Similar Threads

  1. Replies: 36
    Last Post: 6 Days Ago, 10:49 AM
  2. [Tutorial] Kimsufi 2G / Seedbox - VPN
    By Esteben13 in forum Seedbox Tutorials
    Replies: 159
    Last Post: 6 Days Ago, 10:24 AM
  3. Any good tutorials on making seedboxes?
    By agent0 in forum Help
    Replies: 3
    Last Post: August 26th, 2010, 03:00 AM
  4. Replies: 11
    Last Post: September 25th, 2009, 02:36 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •