Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Bash scripting contests

  1. #1
    Join Date
    Oct 2012
    Beans
    47
    Distro
    Ubuntu Gnome 13.10 Saucy Salamander

    Bash scripting contests

    I wasn't sure where to put this, so please move it if it needs to be somewhere else.

    When I started using blender, blenderartists.org had an awesome section of its forum where they hosted timed blender competitions. People would pick a topic or object and create the best thing they could in the given time period. It might be a day or two or it might be only 20 minutes. Afterward the community could vote on who's was the best. What I'm wondering is if there is anything like this for shell scripting. I think it would be cool if there were something like that but for bash scripting. It would be a great way for beginners to learn alot about bash as well as for more experienced individuals to just have some fun while scripting. There could even be some really useful/cool scripts that come out of it. I'd like to know if there's anyone else interested in doing this or if it already exists somewhere else??

  2. #2
    Join Date
    Feb 2008
    Beans
    21

    Re: Bash scripting contests

    +1 for this, coz i am bash scripter beginner.

  3. #3
    Join Date
    Apr 2006
    Beans
    23

    Re: Bash scripting contests

    Upvote, I'd love this too!
    I'm always on the lookout for new scripting techniques and tricks, this way we should gather a nice collection of example scripts.

  4. #4
    Join Date
    Nov 2012
    Location
    Halloween Town
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: Bash scripting contests

    The idea sounds great. Maybe something like Beginners Team Programming Challenges Index and Advanced programming exercises.

  5. #5
    Join Date
    Oct 2012
    Beans
    47
    Distro
    Ubuntu Gnome 13.10 Saucy Salamander

    Re: Bash scripting contests

    Sweet, well sounds like we have enough interest to get it started. I'm sure more people will jump on board later. It would be awesome if it got popular enough to have its own subsection of the forum. I think we can either have one thread for the whole thing(very hard to vote) or we can create new threads for each new contest.

    Weekly+ or daily would be the best so that there is still a time crunch to it but so that we don't have to set up IRC channels or anything to moderate the time limit other than when the person posted their submissions.

    Some rules:
    1) no malicous code (rm /* or others that can wreck a system)
    2) explain things with comments, we're all learning and this helps when reading the script (should lose credit toward winning without this)
    3) no exterior programming languages (perl, python, etc., I think sed and awk are okay though)
    4) if you use programs that are not typically installed by default, let it be known in the script and when you post
    5) have some fun, be creative, and judge on creativity as well as function
    Anyone else think of some rules let it be known.

    Lets do it!

    I'll start off the contest with a fairly easy one: the challenge is to duplicate all files of a users home folder to a new users home folder, then remove all the config files and documents, and leave the old user's home folder as it were created from a fresh installation. I'll give everyone 3 days to complete and upload their scripts.

  6. #6
    Join Date
    Apr 2006
    Location
    UK
    Beans
    6,646
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Bash scripting contests

    Moved: not a support request.
    (Good luck with this endeavour)

  7. #7
    Join Date
    Apr 2012
    Beans
    48

    Re: Bash scripting contests

    Where is the LIKE button? I agree with this idea

    A contest like Google Summer of Code maybe...

  8. #8
    Join Date
    Oct 2012
    Beans
    47
    Distro
    Ubuntu Gnome 13.10 Saucy Salamander

    Re: Bash scripting contests

    Here's my script. Wanted to make it good. Got some great practice with various loops and functions as well as putting in failsafes and making it a bit interactive

    Code:
    #!/bin/bash 
    
    #variables to be used...
    
    newuser=              #variable used to create a new user
    currentuser=$HOME     #current user variable, reads $HOME variable
    yesno=                #variable for yes/no answers
    rootid=0          #vairable to determine root status
    newexist=          #used to determine if we are using a new or existing user
    
    #newuser function
    newuser()
    {
    echo "what would you like the new user's name to be"
    read newuser
    echo "the new user will be $newuser"
    echo "creating new user..."
    adduser $newuser
    }
    
    
    #function to ask if the user is new or old
    newold()
    {
    echo "Are you creating a new user or moving files to an existing account"
    echo '[new/existing]'
    read newexist
    if [ "$newexist" = "new" ]; then
    newuser
    else
    echo "what is the name of the account you wish to move files to"
    read newuser
    fi
    }
    
    #this function copies all the user's files over
    moveuser()
    {
    echo "the current user is $currentuser"
    echo "do you wish to move this user to /home/$newuser ?"
    echo "y/n"
    read yesno                             #asks for user input
    if [ "$yesno" = "n" ] || [ "$yesno" != "y" ]                #if the answer is n or not y then ask for new user name
    then
       echo "enter the username of the account to be moved"  
       read currentuser                    #gets user input and puts into currentuser variable
       echo "$currentuser"
       currentuser=/home/$currentuser            #if $currentuser is left as just an inputed name "user" then it will try to use user instead of /home/user so set variable to use /home/$currentuser
       echo "$currentuser"
       echo "this is the right user?"
       echo "[y/n]"
       read yesno
       if [ "$yesno" != "y" ]; then                #this if statement is needed to prevent wrong inputs, eg no instead of n
          echo "you have not entered a valid answer"
          echo "exiting status 1"
          exit 1
       fi
    fi
                                #when the user is set right it now moves all the files over to the new user
    mv "-f" $currentuser/* /home/$newuser        #moves files recursively and forcefully, probably need if we use the adduser method
    echo "files have been moved from $currentuser to $newuser"
    echo "removing old files"
    rm -Rf $currentuser/*
    cd $currentuser                    #moves to the old user's folder
    echo "making new directories"
    mkdir Desktop Documents Downloads Music Pictures Videos  #makes all the default user directories for ubuntu
    echo "changing user permissions"
    chown $newuser /home/$newuser/*            #changes file ownership, otherwise everything is owned by root
    chmod 755 /home/$newuser/*            #changes file permissions, rwx,r-x,r-x, read,write, execute for user and read execute for else
    }
    
    
    #the script
    #start off testing for root, because this cannot be done without it and should exit if you are not root
    
    if [ "$UID" -eq "$rootid" ]                #checks for root
    then
       newold                        #calls newuser function
       moveuser                        #calls move user function
    else                            #If you are not root then it exits
       echo "You are not root. Run the script again with sudo"
       echo "exiting now"
       exit 0
    fi
    
    exit 0

  9. #9
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    1,868
    Distro
    Kubuntu 12.10 Quantal Quetzal

    Re: Bash scripting contests

    Code:
    mv "-f" $currentuser/* /home/$newuser  #moves files recursively and forcefully, probably need if we use the adduser method 
    echo "files have been moved from $currentuser to $newuser" 
    echo "removing old files" 
    rm -Rf $currentuser/*
    • Your "mv" overlooks all the files/directories with a leading dot ("*" doesn't list them, ".*" does...)
    • Then you attempt to erase what? What files do you expect to see in $currentuser since you have moved them elsewhere?
    • Fortunately this doesn't erase the overlooked "dot files" for the very same reason
    • Why all that complexity when you can just rename $currentuser to $newuser?

  10. #10
    Join Date
    Oct 2012
    Beans
    47
    Distro
    Ubuntu Gnome 13.10 Saucy Salamander

    Re: Bash scripting contests

    lol good call on that. I think I missed the mark on that one. I was experimenting with too many things that I'm just learning and I think I've over looked one of the more important aspects of scripting in doing so: keep it simple. Thanks for pointing that out though.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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