remotelogin/oper_sys/unix/__init__.py
def tail_file_until(self, filename, start_pattern, callback, copy_pattern='', stop_pattern='', time_to_wait=None,
                        read_from=10, conn=None):
        """ Funtion to tail a text (like a log file) file until a pattern is shown and then call the callback function and return

        @param filename: file path on device that we want to tail to
        @param start_pattern: regex that we want to start copying from. If no stop_pattern, then this will be the stop pattern
        @param copy_pattern: regex to copy lines from
        @param stop_pattern: regex to indicate the last line to copy and return
        @param callback: function name to call when we find the pattern
        @param time_to_wait: optional parameter to define how many seconds to let the tail go on
        @param read_from: number of lines to start the tail from, so when we execute this command we will start x lines from the last

        Return:
            It does not return any value but calls a function when it finishes if it does not time outs first

        Exceptions:
            Raises exception if it times out

        """
        log.debug('Tailing File {0} for pattern "{1}" for {2}'.format(filename, stop_pattern, str(time_to_wait)))

        if not stop_pattern:
            cmd = """sh -c '{0} -f -n {1} {2} | awk "/{3}/ {{print; exit;}}" ' """.format(
                self.cmd.tail(), read_from, filename, start_pattern)
        else:
            cmd = ("""sh -H -c ''{0} -f -n {1} {2} |
            awk "{{ if (/{3}/ && !triggered) {{ triggered=1; print; }}
                    else {{ if (triggered && /{4}/) {{ print; if (/{5}/) {{ exit; }} }} }} }}"' """.
                   format(self.cmd.tail(self.gnu_path), read_from, filename, start_pattern,
                          copy_pattern, stop_pattern))

        with conn:
            return conn.send_cmd(cmd).expect_prompt(timeout=time_to_wait)
 Funtion to tail a text (like a log file) file until a pattern is shown and then call the callback function and return

        @param filename: file path on device that we want to tail to
        @param start_pattern: regex that we want to start copying from. If no stop_pattern, then this will be the stop pattern
        @param copy_pattern: regex to copy lines from
        @param stop_pattern: regex to indicate the last line to copy and return
        @param callback: function name to call when we find the pattern
        @param time_to_wait: optional parameter to define how many seconds to let the tail go on
        @param read_from: number of lines to start the tail from, so when we execute this command we will start x lines from the last

        Return:
            It does not return any value but calls a function when it finishes if it does not time outs first

        Exceptions:
            Raises exception if it times out

        
Funtion to tail a text (like a log file) file until a pattern is shown and then call the callback function and return
Funtion to tail a text ( like a log file ) file until a pattern is shown and then call the callback function and return
def tail_file_until(self, filename, start_pattern, callback, copy_pattern='', stop_pattern='', time_to_wait=None,
                        read_from=10, conn=None):
        log.debug('Tailing File {0} for pattern "{1}" for {2}'.format(filename, stop_pattern, str(time_to_wait)))
        if not stop_pattern:
            cmd = """sh -c '{0} -f -n {1} {2} | awk "/{3}/ {{print; exit;}}" ' """.format(
                self.cmd.tail(), read_from, filename, start_pattern)
        else:
            cmd = ("""sh -H -c ''{0} -f -n {1} {2} |
            awk "{{ if (/{3}/ && !triggered) {{ triggered=1; print; }}
                    else {{ if (triggered && /{4}/) {{ print; if (/{5}/) {{ exit; }} }} }} }}"' """.
                   format(self.cmd.tail(self.gnu_path), read_from, filename, start_pattern,
                          copy_pattern, stop_pattern))
        with conn:
            return conn.send_cmd(cmd).expect_prompt(timeout=time_to_wait)
def tail_file_until ( self , filename , start_pattern , callback , copy_pattern = '' , stop_pattern = '' , time_to_wait = None , read_from = 10 , conn = None ) : log . debug ( 'Tailing File {0} for pattern "{1}" for {2}' . format ( filename , stop_pattern , str ( time_to_wait ) ) ) if not stop_pattern : cmd = """sh -c '{0} -f -n {1} {2} | awk "/{3}/ {{print; exit;}}" ' """ . format ( self . cmd . tail ( ) , read_from , filename , start_pattern ) else : cmd = ( """sh -H -c ''{0} -f -n {1} {2} |
            awk "{{ if (/{3}/ && !triggered) {{ triggered=1; print; }}
                    else {{ if (triggered && /{4}/) {{ print; if (/{5}/) {{ exit; }} }} }} }}"' """ . format ( self . cmd . tail ( self . gnu_path ) , read_from , filename , start_pattern , copy_pattern , stop_pattern ) ) with conn : return conn . send_cmd ( cmd ) . expect_prompt ( timeout = time_to_wait )
Funtion to tail a text (like a log file) file until a pattern is shown and then call the callback function and return
Funtion to tail a text ( like a log file ) file until a pattern is shown and then call the callback function and return
""" Funtion to tail a text (like a log file) file until a pattern is shown and then call the callback function and return

        @param filename: file path on device that we want to tail to
        @param start_pattern: regex that we want to start copying from. If no stop_pattern, then this will be the stop pattern
        @param copy_pattern: regex to copy lines from
        @param stop_pattern: regex to indicate the last line to copy and return
        @param callback: function name to call when we find the pattern
        @param time_to_wait: optional parameter to define how many seconds to let the tail go on
        @param read_from: number of lines to start the tail from, so when we execute this command we will start x lines from the last

        Return:
            It does not return any value but calls a function when it finishes if it does not time outs first

        Exceptions:
            Raises exception if it times out

        """
self
filename
file path on device that we want to tail to
file path on device that we want to tail to
start_pattern
regex that we want to start copying from. If no stop_pattern, then this will be the stop pattern
regex that we want to start copying from . If no stop_pattern then this will be the stop pattern
callback
function name to call when we find the pattern
function name to call when we find the pattern
copy_pattern
regex to copy lines from
regex to copy lines from
stop_pattern
regex to indicate the last line to copy and return
regex to indicate the last line to copy and return
time_to_wait
optional parameter to define how many seconds to let the tail go on
optional parameter to define how many seconds to let the tail go on
read_from
number of lines to start the tail from, so when we execute this command we will start x lines from the last
Return:
It does not return any value but calls a function when it finishes if it does not time outs first

Raises exception if it times out
number of lines to start the tail from so when we execute this command we will start x lines from the last Return : It does not return any value but calls a function when it finishes if it does not time outs first Raises exception if it times out
conn