Network drive in Fedora

AlphaTrinityAlphaTrinity North Wales, PA
edited June 2008 in Science & Tech
I am in a Linux (specifically Fedora 8) class in college right now, and our "final project" is it come up with a script that does something useful. At work I just learned how to map network drives using a Windows environment by using, for example:

net use J: \\server\sales

I thought maybe a good "final project" in my class would be doing the Linux equivalent of that script. Is there such a thing in Fedora 8?

Comments

  • kryystkryyst Ontario, Canada
    edited May 2008
    I don't know what level your at, but a script that does that would hardly seem worthy of a final project, I would imagine that your final project shouldn't be something you can google and get copy/paste answer for from the first hit.

    Plus that command differs depending on if if you are mapping to a windows share or a *nix share so it's not really a script that you'd be working with. It'd be more just submitting a new mount point to your mtab file.
  • edited May 2008
    kryyst wrote:
    I don't know what level your at, but a script that does that would hardly seem worthy of a final project, I would imagine that your final project shouldn't be something you can google and get copy/paste answer for from the first hit.

    Plus that command differs depending on if if you are mapping to a windows share or a *nix share so it's not really a script that you'd be working with. It'd be more just submitting a new mount point to your mtab file.

    I have to agree. Doesn't sound like much of a project to me. What was the assignment exactly im sure the teacher didn't just say "do something with linux."
  • AlphaTrinityAlphaTrinity North Wales, PA
    edited May 2008
    Here's the final project guidelines: Your course project will involve the development of a shell script that automates a UNIX/Linux system administration task. Each student will choose a system administration task that can be automated and then research various web sites, technical publications, and books to learn how to program a workable shell script.

    I thought that automatically mapping network drives would be a good administrative task since I do that at work already. Maybe I can go further with the project and make a logon script that will call a script linked to the user name that will then have all of the network drives that specific user needs. I agree that it's a simple project, but I think that's the point; it's not a very in depth class, more like a general study of Linux.
  • kryystkryyst Ontario, Canada
    edited May 2008
    But you don't need to make a script to do that, you can have it do it automatically at boot. Even at it's most basic level if you don't want to automount paths for some reason at boot time. You could just alias that command to something simpler. If you've got your heart set on it, don't let us stop you. But I honestly don't see that as being in need of a script. If you look at the windows version of it (and the *nix version isn't much different if you haven't googled the commands yet) a windows script to do it would just be this:

    a file called mapper.bat
    echo off
    @echo off
    net use j: \\server\share$

    Not really much of a project.

    What about;
    A script that runs rsync to backup your existing system to an external device. That would be something more useful.
    A script that runs hourly and requeue's any network printers.
    A script for removing a user, that first backs up his home directory to backup directory then deletes the user, his home directory and removes him from any lists/groups he's in.
    A script that does a software update check and then emails the admin of available updates.
    A script that goes through user folders looks for .mp3's for example and deletes them - if MP3's are something you don't want users storing on the network.
  • AlphaTrinityAlphaTrinity North Wales, PA
    edited May 2008
    kryyst wrote:
    A script that goes through user folders looks for .mp3's for example and deletes them - if MP3's are something you don't want users storing on the network.

    I like that one, and I can definitely see that being used in the real world. Thanks for the advice.
  • AlphaTrinityAlphaTrinity North Wales, PA
    edited June 2008
    Okay I'm finally going to get to working on this project on Tuesday! Been so busy that this week is the first chance I'm getting to work on it (it's due Thursday :eek: )

    Is there any advice you guys can give me? Or I guess you would rather wait until I've already exhausted google...

    Thanks again for the idea kryyst; my professor agreed with you all that mapping a network drive was a bit too simple, but said I could have still done it. I like the .mp3 network erase though, so I'll stick with it.
  • RobRob Detroit, MI
    edited June 2008
    Hello,

    Attached are some scripts I've been working on, with a couple warnings.

    1. Don't blindly run these, it may cause damage.

    2. It's not even half done, and doesn't do anything yet.

    Which is a good thing, because I wouldn't want to hand you your final. I just wrote this off the top of my head. I haven't had time to finish or even test run any of it, but there's a lot of examples in here that you will need in the real world.

    These are used to manage web servers. A good project would be to write a simple script that added domains to a web server by creating the required directories and config files.

    If you really want to stay with .mp3's here's your project.

    updatedb; for i in `locate *.mp3` ; do echo removing $i ; rm -f $i ; done

    Here's another that takes longer

    for i in `find /. -name '*.mp3'`; do echo removing $i ; rm -f $i ; done

    Notice the for loop? If you pass too many arguments to a command it may cause it to exit. For example,

    rm -f `locate *.mp3`

    Is a very very bad thing to get into the habit of.

    Have fun. Scripting is probably the most important thing you can learn to administrate linux machines. You will want to bookmark this site as well
    http://tldp.org/LDP/abs/html/

    *edit start with the adddomain file and work from there. Some of the other scripts are just generic for my environment.
  • kryystkryyst Ontario, Canada
    edited June 2008
    Those will remove files named .mp3.

    Perhaps it would be more beneficial to move them into a 'holding' folder first then you can approve any deletions and see who put them there by looking at the user perms. You could also get more tricky and check to see if there is some commonality to the construction of an .mp3 files header. Then do a find to actually look into the header of files for that chunk of data and flags it as well.

    Happy scripting.
  • AlphaTrinityAlphaTrinity North Wales, PA
    edited June 2008
    So far I've found how to delete all files inside a 'holding' folder.

    find /holding -type f -exec /bin/rm -f {} \;

    At least..I think that's right.
    I can't find a way to move all .mp3s on the network to that folder though. I've found scripts that will backup files on a local machine, but not through the network. Maybe it's too complicated?
  • RobRob Detroit, MI
    edited June 2008
    Hello,

    This should find all files defined (default *.mp3)
    It will move them to a holding location, and email the admin a list of files found. Also, it will delete the old files in the holding cell. The rest should be understandable by reading the code.

    Please don't copy this and hand it in. If anything, see how I did it and write it in your own style. I doubt your code looks quite like mine, you teacher can probably already spot your 'style'
    #!/bin/bash
    
    #Variables
    
    #Is mail enabled?  Do we want a notice? 0=off 1=on
    MAILER=1
    
    #Our admins email
    ADMINEMAIL=someone@somewhere.change
    
    #Should we delete old files? 0=off 1=on
    DELETEME=1
    
    #How old should the files be in days?  Default 7 days
    OLDAGE=7
    
    #Where to hold the files
    HOLDING="/usr/local/holding-cell/"
    
    #What files to find
    FILES='*.mp3'
    
    #Do we update our database or is it in cron? 0=off 1=on
    UPDATED=1
    
    #/Variables 
    
    OURDATE=`date +%Y-%m-%d-%H`
    
    #Check and see if our holding area exists and create it
    if [ ! -d $HOLDING ]
    then
      echo "Holding area not found, creating $HOLDING"
      mkdir -p $HOLDING
    fi
    
    #Update our database if it's not in cron so we find new files quickly
    if [ $UPDATED == 1 ]
    then
      echo "Updating our file database this may take some time, disable if this is in a cron task"
      updatedb
    fi
    
    #Make a list of our files, excluding the ones in jail already
    locate -i $FILES | grep -v $HOLDING > $HOLDING/found-$OURDATE
    
    #Email the list to our admin for review
    if [ $MAILER == 1 ]
    then 
      echo "Emailing files list to admin"
      cat $HOLDING/found-$OURDATE | mail -s"Found $FILES on `hostname` $OURDATE" $ADMINEMAIL
    fi
    
    #Run our list of files
    for i in `cat $HOLDING/found-$OURDATE`
    do
    
    #Make sure it really is a file and we didn't screw up our $FILES
      if [ -f $i ]
      then
        
    #Who's your daddy, Get our users name or number
    BADUSER=`ls -l $i | awk '{print $3}'`
    
    #See if they have been bad before
        if [ ! -d $HOLDING/$BADUSER ]
        then
          echo "Creating a holding cell for $BADUSER"
          mkdir -p $HOLDING/$BADUSER
        else
          echo "Holding cell exists for $BADUSER"
        fi
    
    #Touch the file, this changes the mtime so we can track how long it's been in holding
        touch $i
    
    #Move the files, making a backup if they exist already with the same name
        echo "Moving $i"
        mv --backup=numbered $i $HOLDING/$BADUSER/
    
      fi
    done
    
    #Find old files and prune them, if selected
    if [ $DELETEME == 1 ]
    then
    
    #Make sure $OLDAGE is set and is a number so we don't user error something
      if [ $OLDAGE -gt 0 ]
      then
        for i in `find $HOLDING/. -mtime +$OLDAGE -type f`
        do
          echo "deleting $i"
          rm -f $i
        done
      fi
    
    fi
    
    exit 0
    
  • AlphaTrinityAlphaTrinity North Wales, PA
    edited June 2008
    I think the project went pretty well :)

    I basically took your script and some other stuff I found online..crunched it all together and then cleaned it up with my personal touch.

    Thanks a lot for the idea kryyst, and thanks a lot for the script that saved me hours and hours of time Rob. I even credited you in my report as IC Rob ;)
  • kryystkryyst Ontario, Canada
    edited June 2008
    No problem, glad your project was a success.
Sign In or Register to comment.