Find the answer to your Linux question:
Results 1 to 6 of 6
I think I know what this "should" be doing but it isn't. In fact it is doing the opposite of what I thit it does. Tell me what you think ...
  1. #1
    Linux Newbie
    Join Date
    Jun 2006
    Posts
    139

    Help with a script.....

    I think I know what this "should" be doing but it isn't. In fact it is doing the opposite of what I thit it does.
    Tell me what you think it does:

    cd /opt/scripts
    isitthere="weddown.log"
    if [ -e $isitthere ]
    then rm -f weddown.log
    else /opt/scripts/weddown.sh > /opt/scripts/weddown.log
    fi

    thanks
    Mace

  2. #2
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    what it does is obvious i think.
    i think you should tell us what you are expecting it to do so that people can tell you where th problem is
    Linux and me it's a love story

  3. #3
    Just Joined!
    Join Date
    Feb 2007
    Posts
    4
    what khafa says is true . Are you seeing any discrepancies while executing this script . Let us know.

  4. #4
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    I'm sure you'll want to get down to troubleshooting first, but once you define your variable you can use it across the script to ensure consistency
    Code:
    cd /opt/scripts
    isitthere="weddown.log"
    if [ -e $isitthere ]
     then rm -f $isitthere
     else /opt/scripts/weddown.sh > /opt/scripts/$isitthere
    fi
    The script should check from /opt/scripts/ if there is a logfile present...if it is present it removes it and creates a new one.

    Unfortunately everytime this runs it will replace the previous logfile so it isn't testing for anything useful. weddown.sh if successful will create the log and this check if successful will ignore it and create a new one.

    Perhaps you want to check if the file is missing and run the script if it hasn't run already?
    Code:
    cd /opt/scripts
    isitthere="weddown.log"
    if [ -z $isitthere ]
     then /opt/scripts/weddown.sh > /opt/scripts/$isitthere
    fi
    Also your redirect will overwrite the logfile if it's present. This is probably what you expect anyway but I just thought I'd mention it.

  5. #5
    Linux Newbie
    Join Date
    Jun 2006
    Posts
    139
    Your right it is very simple..much like the author..
    What I am trying to do is have a process run everyother week.
    The process creates the weddown.log
    SO I think it should go to opt/scripts then check for the log, if the log is there
    delete it and finish, if the log is not there then run the next command which when done will create the log.
    Now for the wierd part,
    I have run this on a test machince and it works flawlessly, but I put it into prod and it will not run right.

    Thanks
    Mace

  6. #6
    Linux Newbie
    Join Date
    Jun 2006
    Posts
    139
    btr-

    I hate to raise this again but I was looking at something else and when I was looking at 'if' test conditions I saw the -z was for a zero file size.
    I want to check to see if the file is present and if it is delete it or if it isn't there fall through and run the script.
    Yes I know I'm overwriting the file each time. The file is just a sanity check.
    thanks
    Mace

Posting Permissions

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