Infinite "while" loop subshell loses current date variable

I have a simple script to log network connectivity to a set of systems.
However, as expected the date appended to the log never changes because the new variable is lost when the loop starts again. Can someone clue me in on how to get around this issue?
#!/bin/bash
LOG=/tmp/netlog
when=`/bin/date`
while true;
do
for server in srv1 srv2 srv3 srv4 srv5;
do
ping -c 1 $server > /dev/null
if [ $? -ne 0 ]; then
echo "$server-DOWN!" $when >> $LOG.$server
# mail
else
echo "$server-UP!" $when >> $LOG.$server
fi
done
done

esa wrote:Jason, from my experience, [] with quotes around variables is generaly more cross-over compatible (bsd'ish, deb'ish, rh'ish) than [[]] without quoting of variables.
More than once i've had unexpected behaviour caused by using [[ condition ]].
That's why you'd use /bin/bash instead of /bin/sh .. (or rather /usr/bin/env bash - OpenBSD has bash in /usr/local/bin) - [[ is bash specific.
http://mywiki.wooledge.org/Bashism
Last edited by Alad (2015-05-21 13:01:27)

Similar Messages

  • How to out from infinite while loop in sub VI

    Dear Sir,
    how to out from infinite while loop in sub VI from main VI
    attached photo for solution but I can't understand it and i can't find the function in photo 
    please help
    Attachments:
    stop_subVI_frm_main.JPG ‏36 KB

    Asking how to get out of an infinite loop is like asking how to find the end of a circle. I'm not trying to be sarcastic but by definition, if there is a way out of the loop, then it is not infinite. I think what you are asking is how to avoid creating an infinite loop. Is there something about the suggestions you have been given that you do not like? My favorite suggestion is the notifier but maybe you just need an example. Turn on context help and read about the notifier functions in the code below.
    This is your top level VI
    And this is your subVI
    If this seems too complex then a global variable will work too. But what seems simpler can cause much more complex bugs. You can code fast and spend lots of time debugging or you can code slow and spend less time debugging. Personally I perfer writing productive code than looking for bugs any time.
    =====================
    LabVIEW 2012

  • Infinite While-loop!

    Hey there! I'm trying to do some data input validation but I haven't been able to figure it out. First I need to check if the user entered anything, that one works. Then I need to check if what the user entered was a number. But I'm getting an infinite while loop in when I try to validate if the first character entered is a letter. . . .
    Thanks for your help!
    public class methods
    public static void main(String args[]) throws IOException
      String input ="";
      int qoh=0;
      boolean error=true;
      Scanner keyboard = new Scanner (System.in);
      //while (error)
                    //   error=true;
                            while (error==true)
                                System.out.print("\nEnter Quantity on Hand: ");
                                input = keyboard.nextLine();
                                if (input.length() <1)
                                    System.out.println("\n**ERROR06** - Quantity on hand must be between 0 and 500");
                                    error=true;
                                    System.out.println(qoh);
                                    System.out.println(input);
                                else
                                    error=false;
                            error = true;
                            while (error==true)
                                if (Character.isLetter(input.charAt(0)))
                                    System.out.println("\n**ERROR06** - Quantity on hand must be between 0 and 500");
                                    error=true;
                                    System.out.println(qoh);
                                    System.out.println(input);
                                else
                                    qoh = Integer.parseInt(input);
                                    error=false;
            }

    1. add in breakpoints to your program.
    Eg. put print statements before and after loops to confirm which loop is producing the inf loop error.
    also add in print statements in your if and else blocks.
    2. You should consider using keyboard.next() instead of nextLine()
    Eg. how are you going to handle "500 orange crush"?
    3. I have a feeling that the real problem lies at the 2nd loop where you tried to do a parseInt
    What happens if you have "5lmao" charAt(0) check is passed, but it wont produce a int will it?
    You might want to loop through every char in the input string to confirm they are a number.
    4. I suggest
    If(input.length() > 0) error = false
    else print msg
    OR
    assume no errors before loop.
    if(length() <1) error=true
    else error = false
    5. use the keyword "break". By that i mean set up your loop to be infinite loops, use the break operator under specified condition (error=false)
    I didn't identify the error for you, but i'd say the above methods should help you with your problem

  • Create current date variable at universe level

       Hi Everyone
    I have created report regarding to daily car sales. However there is records registered for further months, 2015 December for instance.
    Actually they are error records, but I can't delete them since data transfer is realizing automatically and updates hourly.
    That is why I have decided to use prompt for report: date is less or equal to current date. But couldn't find way how to create current date variable.
    Please help with this.
    Regards...

    Yes.
    Create an object called Today as:
    cast(convert(char(10),getdate(),23) as datetime)
    Note that it will not parse because it does not reference a table. Don't associate it with a table just to get it parsing as you will then have that table in every query that uses the Today object, whether you want it or not!
    It will work fine when you use it in your query. In your example, create a condition of Ship Date Less Than Or Equal To Today where Ship Date and Today are the names of the two objects. This will then translate into SQL as:
    WHERE orders.ship_date <= cast(convert(char(10),getdate(),23) as datetime)
    This will parse because the table orders is in the statement.
    I hope that is clear.
    Regards,
    Mark

  • UI flickrs continously jdk1.7.25 EventdispatchThread's pumpEventsForFilter goes to infinite while loop

    I am migrating a project from Java 1.3 to Java 1.7 update 25 and there is one search button functionality in which search is performed correctly but the UI flickers continuously because EventdispatchThread's pumpEventsForFilter goes to infinite while loop.
    This same code works correctly in java 1.3.
    Below is the part of the code related to searchbutton. Can you please suggest regarding this because the issue is within java api and not sure how to solve this.
    SearchButton.java:
    private JButton searchButton; 
    private String textsearchButton = 
          search.util.Language.getString("buttonStartSearch"); 
    searchButton = new JButton(textsearchButton); 
    buttonPanel.add(searchButton); 
    searchButton.addActionListener(this); 
    searchButton.addActionListener(actionListener); 
    actionListener.actionPerformed( 
                   new ActionEvent( 
                      searchButton, 
                      ActionEvent.ACTION_PERFORMED, 
                      "toFront")); 
                actionListener.actionPerformed( 
                   new ActionEvent( 
                      searchButton, 
                      ActionEvent.ACTION_PERFORMED, 
                      "searchComplete")); 
    setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 
        if (hasSearch) { 
                actionListener.actionPerformed( 
                   new ActionEvent( 
                      searchButton, 
                      ActionEvent.ACTION_PERFORMED, 
                      "searchComplete")); 
             else { 
                actionListener.actionPerformed( 
                   new ActionEvent( 
                      searchButton, 
                      ActionEvent.ACTION_PERFORMED, 
                      "search")); 
    searchButton.setEnabled(!hasSearch && hasCriterions()); 
    public void actionPerformed(ActionEvent ae) { 
          Object source = ae.getSource(); 
          else if (source == searchButton) 
             startSearch(); 
          else if (source == exportButton) 
             exportSearch(); 
          else { // ActionEvents from the panels occur 
             changesOccured(); 
    EventDispatchThread:
    void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) { 
            addEventFilter(filter); 
            doDispatch = true; 
    //This while goes to infinite loop 
           [b] [color=red]while (doDispatch && !isInterrupted() && cond.evaluate()) { 
                pumpOneEventForFilters(id); 
            }[/color][/b] 
            removeEventFilter(filter); 

    Please provide your code example as SSCCE . I'm not going to spent time guessing what your application code (other than shown) meigt do or not do.
    bye
    TPD

  • Stuck inside an infinite While Loop :-/

    Hi all,
    When I write this program using the top-down structural method, it runs fine but when I use the call method inside the while loop, it doesn't test the "if" condition. It becomes a never-ending loop. :-/
    import java.util.Random;
    public class WhileLoop {
          public static void main(String[] args) {
            int random1;
            Random die1 = new Random();
            random1 = die1.nextInt(6) + 1;
            WhileLoop r = new WhileLoop();
            while (random1 != 5) {
              if (random1 != 5) {
               r.doRandom();
              if (random1 == 5) {
                System.out.println("you win! ");
             int random1;
          public void doRandom() {
             Random die1 = new Random();
             random1 = die1.nextInt(6) + 1;
             System.out.println("random1 = " + random1);
      }If I replace the line " r.doRandom(); " with " random1 = die1.nextInt(6) + 1; System.out.println("random1 = " + random1); " the program will check the "if" condition and stops when it finds the number 5. What's wrong with my code?
    Thanks for your help.

    DrLaszloJamf wrote:
    {color:#3D2B1F }You have two, unrelated variables that happen to both be named random1.{color}Opps! Must have missed it. Using two unrelated variables with the same name was, unintentional ~ //yea, right (blush). Thanks for pointing it out. :-)
    Encephalopathic wrote:
    you never change random1 from within the while loop. You think you do, but it's a different random1 that you're changing, a non-static one that is an instance variable.okay~ but does it mean that 'random1' from the method within the while-loop cannot be used for comparison purpose? I tried using a 'return' value from the doRandom method and use that value inside the "if" condition, but it also does not terminate the loop. The only way it's going to work is by using the solution DrLaszlo gave? Is there any other way to do this by using a call method?
    Thanks!

  • How do I make one while loop that runs 1 piece of data at a time?

    I have a question about a while loop.  Currently, I have 4 or 5 dynamic data lines that I would like to run through a while loop that will tell me if the data is within a certain range or not.  However, the ranges are different for each piece of data, and I dont know how to do each one separately.  Do I have to make 5 different while loops? Thanks!

    pg22aw wrote:
    I have a question about a while loop.  Currently, I have 4 or 5 dynamic data lines that I would like to run through a while loop that will tell me if the data is within a certain range or not.  However, the ranges are different for each piece of data, and I dont know how to do each one separately.  Do I have to make 5 different while loops? Thanks!
    Do you want to compare the value with a defined value and also the ranges for the 5 data is different?. What are you doing in the while loop. If the data is in an array of dynamic data you can seperate the amplitude value and check the whole array of value with the ranges that is also build same as the data theh you will get the output as a boolean array.
    The best solution is the one you find it by yourself

  • AI Read is executing only once in a while loop instead of continuously scanning the channels

    The ultimate goal is to sample 15 channels (1 at 20kHz, 9 at 1000Hz, and 5 at 100Hz). Since only one scan rate is possible, I would like to reduce the data (for both displaying and saving purposes). The decimate function does not seem to work correctly.
    Attached is the current subroutine used to 'decimate' the data. It seems to work on the first loop iteration, as seen by the data block with correct time stamps and data values, but with each additional iteration, all values are zero. Why is only one scan being used in the displaying of data?
    Attachments:
    Acquire_N_ScansNM4.llb ‏76 KB

    When you call AI Clear, the DAQ session is over. You will not get any new data by calling AI Read after an AI Clear. Move your AI Clear to the right of your while loop such that it runs after the while loop completes. Don't forget to wire an error cluster or DAQ session ID to AI Clear from inside the while loop to create the data dependency. Also, consider adding a shift register for the error cluster and some way to exit the loop on an error.
    Remember that Alliance Members are here to help. We do this stuff every day.
    Daniel L. Press
    PrimeTest Corp.
    www.primetest.com

  • How can I make a while loop wait 10 seconds before iterations​?

    I am using labview to for an osmosis system that measures the amout of water lost from the reading on a scale.  
    I currently have the program displaying the data from 3 scales every second.
    I also need to calculate the flux through the membrane over time.
    I do this with a function that takes a change in the scale reading over time (with a shift register) followed by a series of mathematical conversions.
    The readings from the scale display OK every second, but I need to have at least 10 seconds between flux calculations.
    So my question is, how do I make a the shift register take one value from the scale, then wait 10 seconds before taking the second value?  That way I have the mass of water lost over a 10 msecond period.  
    Below is my current while loop for Flux using shift registers from data from 3 scales.  
    Any helkp would be great!
    Also, I'm new at LabVIEW...

    Bob_Schor wrote:
    Do you understand how Dataflow (a key idea behind LabVIEW) works?  If you put a Wait (ms) function (on the Timing Palette) with 10000 (10,000 milliseconds = 10 seconds) inside your While Loop, the principles of Data Flow will require all of the functions inside the While (specifically the Wait function) to finish their execution before the loop can run again.  As everything else in the loop takes approximately 0 seconds, this will make your loop run once every 10 seconds.
    Bob Schor
    I do not think that is a good idea. 
    The inner loop should be in sync with the outer loop, not run independent on it's own timer.
    If the inner loop is running independently you run the risk of using stale data.
    Actually  altenbach is right the inner loop does not need to be a for loop at all, but rather just a case like my suggestion (without the for loop) and the shift registers should be out on the main loop.
    My suggestion was a quick solution going by what little bit of the block diagram I could see, but if the entire code was posted I am sure we would see where more improvements could be made and possibly even a better solution.

  • Current date in xslt mapping

    Hi,
    I've tried to get the current date in my xslt mapping.
    I've used the following xslt coding:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">
    <xsl:template match="/">
    <xsl:variable name="now" select="current-date()"/>
    </xsl:template>
    </xsl:stylesheet>
    In stylus studio everything is OK and i retrieve the current date.
    When i import the xslt in the mapping tool and test the mapping i get the following error:
    javax.xml.transform.TransformerException: com.sap.engine.lib.xml.util.NestedException: Function with name 'current-date' not found in context library. at com.sap.engine.lib.jaxp.TransformerImpl.transform(TransformerImpl.java:251)
    While directly using the current date functionality within the message mapping everything is OK too.
    Does anyone know which date-functionality is used within the message mapping within the Integration Builder and/or wich mapping to be used in xslt for a working scenario?
    Thnx in advance!

    Ok thnx, these anwers where very helpfull for me to solve this problem.
    I've awarded points for all your answers.
    For anyone interested later on, I needed the date in my XSLT mapping in the following format ddMMMyy.
    Finnally I used the following xslt to achieve this:
         <xsl:template name="currentDate" xmlns:cal="java:java.util.GregorianCalendar">
              <xsl:variable name="now" select="cal:getInstance()" />
              <xsl:variable name="day" select="cal:get($now, 5)" />
              <xsl:variable name="month" select="cal:get($now, 2) + 1" />
              <xsl:variable name="year" select="substring(string(cal:get($now, 1)), 3, 2)" />
              <xsl:variable name="month">
                   <xsl:choose>
                        <xsl:when test="$month=1">Jan</xsl:when>
                        <xsl:when test="$month=2">Feb</xsl:when>
                        <xsl:when test="$month=3">Mar</xsl:when>
                        <xsl:when test="$month=4">Apr</xsl:when>
                        <xsl:when test="$month=5">May</xsl:when>
                        <xsl:when test="$month=6">Jun</xsl:when>
                        <xsl:when test="$month=7">Jul</xsl:when>
                        <xsl:when test="$month=8">Aug</xsl:when>
                        <xsl:when test="$month=9">Sep</xsl:when>
                        <xsl:when test="$month=10">Oct</xsl:when>
                        <xsl:when test="$month=11">Nov</xsl:when>
                        <xsl:when test="$month=12">Dec</xsl:when>
                        <xsl:otherwise>INVALID MONTH</xsl:otherwise>
                   </xsl:choose>
              </xsl:variable>
              <xsl:choose>
                   <xsl:when test="$day &lt; 10">
                        <xsl:value-of select="concat(concat(concat('0',$day), $month), $year)"/>
                   </xsl:when>
                   <xsl:otherwise>
                        <xsl:value-of select="concat(concat($day, $month), $year)"/>
                   </xsl:otherwise>
              </xsl:choose>
         </xsl:template>

  • While Loop in DI

    <p>Hi, </p><p>I need to load a set of 40 text files into SQL Server using the DI ETL process. </p><p>I created the while loop, but at the While loop editor, I put my variable and it does not work.</p><p>For example, I created my global variable for the $filename, and counter as $counter. </p><p>At the while loop editor on top, I put in ($counter < 40), then I have my necessary file for it to load</p><p>the data, but it does not load and gave no error when i did the validation.  The job will say it run sucessfully, but it loads no data into SQL table. </p><p>My question is does anyone knows the  correct syntax for the while loop in DI when you have </p><p>40 files to load? </p><p>&#160;</p>

    Hi,
    I am busy loading multiple flat files into my Oracle Database. I have defined a File Format for this and it works fine. However, there is a FILE_NAME field in my table, which should contain the name of the file where a specific record was loaded from.
    My question is, how do I store the file name in a variable so that i can use it to fill the FILE_NAME field in my table? I have defined my global variable $FileName but I don't know how to write the script to fill this variable.
    Your assistance will be highly appreciated.
    Ndahafa

  • Waveform charts slowed down control system while loop

    Hi
    In my application, I have control system which i acquire data, process and output the result. I placed some waveform charts in the while loop where i acquire data, process and output. This made while loop to miss data points( late). Is this because waveform charts store data as time passes?

    Waveform charts store data in a history buffer of configurable size. You can change it to a smaller number.
    What is the size of the history buffer?
    How many charts are you updating in your loop?
    What else is happening in your loop?
    How are you updating them (wire, local variable, value property, etc).
    How fast is your loop rate?
    Are your plots simple (thin lines) or fancy (e.g. large dots and thick lines)?
    Is autoscaling on or off?
    Are the charts set to "synchronous display" by accident?
    How many traces are on your chart?
    What is your LabVIEW version?
    What is your OS?
    Do you have overlapping elements on the front panel?
    Could you attach a simplified version of your code so we have a better idea what you're actually doing?
    LabVIEW Champion . Do more with less code and in less time .

  • How can I make a while loop wait for input boolean?

    Hi.
    I'm trying to control a robotic arm with labview for my undergrad dissertation, and I have a decent polar coordinate control panel made, but there is one problem; it checks for changes in the coordinates every five seconds, while I want it to only check on the touch of a button (ie, go!, I've changed your coordinates!). The changes are calculated with a while loop comparing the last value of theta, x and z in a while loop with the current one. I can't find a way of putting that into a case structure. If there is a way of making the while loop progress at the push of a button, I think it would work. The VI's attached below.
    Thanks in advance for any help.
    Cathal Scanlon
    ps, sorry about the mess, I'm going to reorganise the while loop into 2 if I can get the control button working.
    Message Edited by CatScan on 02-08-2007 02:45 PM
    Attachments:
    Polar coord assignment1.vi ‏142 KB

    Have you tried using an event structure? To use one, right click on the structure to add an event. Set the event as whatever button you wish to monitor and set the event to "Value Change". If you put this inside a while loop any time the button is pressed, the event structure will run the contents inside the loop. There are a number of options to have the event structure activate.
    *** Warning! I'm probably the last guy you want answering your labVIEW questions, but I figured I might be able to help.

  • Use the LabView time delay in a while loop instead of using the instrument inherent time loop.

    I have a zes lmg500 that I use. It has the option of continues measuring data, with a user control cycle loop (still using a while loop but the delay is coming from the instrument). The problem is that the loop time is not constant. Can I use a very short time (100ms) as the instrument cycle time but use a longer time delay in the while loop that collect the data?
    I know many instrument offer the same abilities, so the question is relevant to all of them.
    Thanks for any help
    Solved!
    Go to Solution.

    Does that measurement VI have built-in wait functionality and a timeout?
    If not, then you are simply polling the VI at 1 kHz, but I suspect that this is not the case or your Waveform Chart probably wouldn't look as you expect (getting 0's put in everytime measurement data is not available).
    I expect that if you have the instrument set up to send data at a fixed time interval (i.e. 100 ms), all the data that it is sending you will end up residing in your serial buffer (or the instrument driver will have taken it out and put it in another internal buffer), so if you come back to read it 1 sec later, then you will have 10 data points to go through.  Whether you can read them all at once with the read VI or have to call it a whole bunch of times until empty I can't say.
    What is your objective?

  • While loop inside a event structure

    Dear
    I have no much concepts on event structure.
    Let's assume there is a dialog box with Okay and Cancel button.
    I put the event structure for Okay and Cancel button.
    In Okay event, there is a while loop for detecting some data continuously.
    In this case, I want to use Cancel button to stop the while loop during the detection.
    How can I do to receive signal from the Cancel button?
    Thank you in advance.

    I'm not sure that the event structure should be used to handle that situation : while the OK event is executing, either the Front panel is locked and new occuring event will be stored until the OK event is completed (so the Cancel button action will not be detected !) or the Front panel is unlocked (see below *) and the Cancel button action will stop the loop, but the Cancel button event case will not be executed, since the event has already been processed in the OK case !
    You should probably use a single button to run/stop the loop, as shown in the attachment
    * While editing the event case, unmark the "Lock front panel for this event complete" at the bottom. But of course, the code in the cancel case will not run, since the event occuredMessage Edité par chilly charly le 03-31-2007 05:27 PM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Event button.vi ‏11 KB

Maybe you are looking for

  • How can I allocate memory at runtime?

    Hi, I have declared a an array of objects like. private SampeObject [] channelAccounts = null; How can I allocate the memory at runtime(dynamically) ? I tried with channelAccounts = new SObject(); But its giving runtime null pointer exception. Can an

  • Regex for Java comments

    Hi everyone, Can anyone be so kind and post the simplest working regex pattern that matches all Java comments (multi-line, not in quoted strings, etc). I'm starting to use (Java) REs and have been fighting with various combinations of |s, $s, \\*s, P

  • Multiple cost of sales account

    In OBYC GBB system picks up the COGS account where the entry needs to get posted at the time of GI (MIGO), is there any way to get G/l (COGS) accounts getting posted with ignoring valuation class which gets maintained in material master and by taking

  • Photoshop vs Elements 6 comparison?

    Anyone know if a comparison exists between the two pieces of software? I use an older Photoshop, but want to know which features I would loose if I downgraded to the new Elements. Thanks!

  • Lion not booting

    Hello everyone. I've been a Mac user since 2007. To describe the problem, it begins with me being a MobileMe user which brought the following: I needed to "migrate" to iCloud. Although I still have a few months until my subscription has ended, I'm ge