November 10, 2009

  • More *nix Scripting

    I’ve been meaning to post this for a while, but ever time I think of it, I’m at home and I can’t get to this script–incompatibility with Snow Leopard and our network.

    The trick that made this script useful for me (and saved me from having tor really think outside of the box) was basename

    I know I need to comment this script so they know who to come sue when it doesn’t work and actually explain what the hell is going on here, but I wanted to hear from my *nix versed readers.

    I’m also considering x-posting to [info]unixadmin for recommendations on how to clean up the script or what kind of things I should add. For instance, a suggestion was made to check for 0 byte files. Also, it seems like on the day, just echo didn’t produce a blank line. I considered echo n but I didn’t think that would work either.

    Nevertheless, here’s my latest script made public for review, critique and criticism.


    #! /bin/bash

    for x in `ls |grep backup`

    do
    echo Creating DB `basename $x .backup`
    createdb -E SQL-ASCII -O libsoft `basename $x .backup`


    echo restoring `basename $x .backup`
    pg_restore --no-owner -d `basename $x .backup` $x

    echo NEXT
    done

Comments (13)

  • @drax0r - I think your computer is broke. This is twice in so many days that you’ve had the same comment. Perhaps you ought to get your b0x3n checked out. I hear the swine flu is going around. Nasty bug that.

  • What in the hell are you trying to do, and who is your audience? 

  • @drax0r - I’m trying to make my life easier. As for my audience, I haven’t had a significant following since I quit writing a couple of months ago. I put this on my blog because it is my blog and I wanted to write about this.

  • Ok, emo boy.
    What is the specific purpose of the script, and who will be running it?

  • @drax0r - I’m his audience. I think it creates an SQL database entry for every file in the current folder that contains “backup” somewhere in its name, which is a lot quicker than having to enter each file individually.  I don’t know SQL though so I might be wrong.

  • @anaraug - Wow. You’re good.

    @drax0r - What anaraug said. (He saved he having to type it up)

  • @anaraug - Since this is software made by my company and we don’t allow any third party development, I’m good on the case-sensitivity of the file extension. And actually, I see a typo in my post. There should be no “4″ on the end of that.

  • Also I’d use regex instead of ls | grep
    “for x in *” would have ls built in, and grep does nothing but regex on the ls.  Unless I’m missing the boat on some feature of grep or ls that I didn’t know about.

    so

    for x in *backup*

    should work unless I’m mistaken.

    Also I would suggest case-desensitizing “backup”, but this might not be a problem for you.

    something like

    for x in *[Bb]ackup*

    or

    for x in *[Bb][Aa][Cc][Kk][Uu][Pp]*

    if really necessary (there’s got to be a cleaner way to do that, but that’s what comes to mind first.)

  • @ProfessorTom - That’s good then, just make sure to leave backup lowercase if you or anyone else has to fix something manually.  Mostly the anyone else is who I’d worry about.

  • @anaraug - Yeah, I think this post would have made more sense had I commented my script first (which I need to do.)

  • i decided to follow a cut –

    oye

    i think i’m turning Japanese~a -

    - i really think so…

    (so lost)

    was thinking i should have gone to the books post – then – i remembered – i’m illiterate

  • @pamilvr - Yeah, you should have went for the book post.

Post a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *