Find the answer to your Linux question:
Results 1 to 5 of 5
Hello all, I am facing one basic problem i don`t know why ? here is my problem I written script like as follows while [ 1 ] do sone=17:00 send=19:00 ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    45

    How to check my conditions..!!!

    Hello all,

    I am facing one basic problem i don`t know why ? here is my problem

    I written script like as follows

    while [ 1 ]
    do

    sone=17:00
    send=19:00

    check=`uptime | cut -c2,3,4,5,6`

    # check will give the current time

    here i want to check the " is $check is in between the $sone and $send"

    done

    how ?

    please help ...!!!

  2. #2
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    I would change the variables into numbers by removing the colons.

    Code:
    #!/bin/bash -vx
    
    sone=1700
    send=1900
    
    check="`date +%H%M`"
    
    if [ "$check" -ge "$sone" -a "$check" -le "$send" ]
       then echo "Yes"
       fi
    EDIT: I would use the date command to get the current time.

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    45

    check

    thanks

    what is -vx in the starting ?

    and I need to check for 24 hour how i need to write the conditions

    I mean i am going to declare 24 strings like as follows

    sone=0000
    oneend= 0200

    stwo=0200
    twoend=0400

    sthree=0400
    threeend=0600

    like this it will go for up to 12x2 = 24

    #ctime current time


    how i need to check the ctime is in between sone and oneend next stwo and twoend next sthree and threeend upto 12


    can i use if or what ?

    please help ...!!!

  4. #4
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    -vx means show the commands as they are being executed. Helps in debugging.

    If you have to break up the time of day into 2 hour increments then a little simple math would do it.

    Code:
    #!/bin/bash -vx
    ctime="`date +%H`"
    nmbr=$(( ($ctime / 2) + 1))
    0000 thru 0159 will return 1
    0200 thru 0259 will return 2
    .
    .
    .
    2200 thru 2359 with return 12

  5. #5
    Just Joined!
    Join Date
    Feb 2008
    Posts
    45

    check my condition

    thanks for the solution

Posting Permissions

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