Menu

update the motd file with current hub info

Scripting
Paul
2003-03-23
2003-03-23
  • Paul

    Paul - 2003-03-23

    [quick shoutout to Rob1n and joohn, and the other contributors, your work is appreciated, thank you]

    I took the liberty of modifying hartsan's total share and uptime algorithm just a bit and put it in the hub_timer sub. every 15 minutes (unless you changed the default timer) it changes the motd file to reflect current settings, so new users get some fairly current info when they logon.

    I was thinking about putting it in the new_user_connected sub so it would give exactly up to date info, but it has to lock access to the motd file while updating it so i think that would cause problems, not sure...

    works under opendchub-0.7.8 (!nuke patch only), RH 8 and is installed in  /root/.opendchub/ (u'll have to change that dir in the script if you installed it somewhere else)

    ===========================

    sub hub_timer()
    {
    my($user_count) = odch::count_users();
    my($total_share) = odch::get_variable("total_share");
    my($total_tb) = int($total_share/(1024*1024*1024*1024) * 100) / 100;
    my($average_share) = $total_share / $user_count;
    my($average_gigs) = int($average_share/(1024*1024*1024) * 100) / 100;

    my($uptime) = odch::get_variable("hub_uptime");
    my($minutes) = int($uptime / 60);
    my($hours) = int($minutes / 60);
    my($days) = int($hours / 24);

    if($days > 0)
    {
    $hours = int($hours % 24);
    }
    if(($days > 0) or ($hours > 0))
    {
    $minutes = int($minutes % 60);
    }

    open(fileOUT, ">/root/.opendchub/motd");
    flock(fileOUT, 2);

    print fileOUT "\n";
    print fileOUT "welcome to hub bleh\n";
    print fileOUT "\n";
    print fileOUT "\n";
    print fileOUT "\n";
    print fileOUT "\n";
    print fileOUT "Uptime -> $days day(s) $hours hour(s) and $minutes minute(s)\n";
    print fileOUT "UserCount -> $user_count\n";
    print fileOUT "TotalShare -> $total_tb TBs\n";
    print fileOUT "AvgShare -> $average_gigs Gigs per user\n";
    print fileOUT "\n";

    close(fileOUT);
    }

    ===========================

     
    • Kent Nilsson

      Kent Nilsson - 2003-03-23

      Some ideas....
      Why not let the script grab the timer value and send a message to the user (private or in main). That way you won't need any file access.

      Or if you wanna get fancy have the script read a template file with variables to replace (like %TIME) when loaded and when given a certain command (loadwelcome for example).
      Then replace the variables with appropriate values in new_user_connected and send the message..
      This would mean file access only once (and readonly so the lock could be shared, not that I believe that file performace is a problem here) .
      This would allow you to use cool stuff like "Hello %NAME, you are sharing %SHARE. This hub has been running for %UPTIME hours".

      A useful thing would be to replace
        ">/root/.opendchub/motd"
      with
        "$ENV{HOME}/.opendchub/motd"
      so the script is independent of which user is it running as.

      Happy hacking
      /Kent

       

Log in to post a comment.