LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-06-2022, 12:05 AM   #1
Faki
Member
 
Registered: Oct 2021
Posts: 574

Rep: Reputation: Disabled
Reading telemetry data and applying an action


I have the following line that reads telemetry data from a logfile when File: or + is encountered. I am setting the variable action to either continue or break, then running the command after the last + entry. It seems a bit confusing when the action gets executed upon reaching (*). What can I do to make the intent clear?

Code:
  
  action="continue"

  while IFS= read -r telemetry; do

    attrib="${telemetry%[[:blank:]]*}" 
    
    case $attrib in
     ("File:")
               # "File:" field name has been reached.
               field="File" ; action="break" ;;
     ("+")
               # Detected the + continuation character
               [[ "$field" == "File" ]] && action="break" ;;
     (*)
               # action="continue"
               #   Ends current iteration, resuming at next iteration.
               #   Read next line in logfl, because "File" not yet reached.
               # action="break"
               #   Ends current iteration, exiting from the while loop.
               #   Exit logfl reading after end of field "File".
               $action ;;
    esac

  done < "$logfl"
 
Old 06-06-2022, 05:55 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,735

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
The *) matches anything so your loop will break for any line after action=break but you have set action="break" for both File and +) cases. If you want to break at a + then why not just break at the +) case.

Quote:
after the last + entry.
If you have multiple lines that are the same in the log file then without knowing all the details would not this find the first occurrence and not the last?
 
Old 06-06-2022, 01:21 PM   #3
Faki
Member
 
Registered: Oct 2021
Posts: 574

Original Poster
Rep: Reputation: Disabled
The action=break does not execute the action, only when reaching *) do the commands continue and break execute.

One can either have

Code:
File: Value
or

Code:
File: Value
+ Value
+ Value
+ Value
The task is to capture the values for the File field.

If + is encountered, I will read through all subsequent values until the last + in encountered.

Last edited by Faki; 06-06-2022 at 01:43 PM.
 
Old 06-06-2022, 02:34 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,735

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
Does it work as expected?
 
Old 06-06-2022, 02:39 PM   #5
Faki
Member
 
Registered: Oct 2021
Posts: 574

Original Poster
Rep: Reputation: Disabled
I feel it is implemented in a weird way.
 
Old 06-06-2022, 02:44 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,735

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
If it is commented enough then you should be able to come back 2 years from now and be able to understand how it works. You could do the same thing with an if-then-else too.
 
  


Reply

Tags
bash, execute



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtualbox user data collection or Telemetry joseph123 Linux - Software 1 01-03-2020 02:51 AM
LXer: GitLab pulls U-turn on plan to crank up usage telemetry after both staff and customers cry foul LXer Syndicated Linux News 1 11-01-2019 10:51 AM
[SOLVED] Every two minutes rsyslog outputs - rsyslogd: action 'action 3' resumed (module 'builtin:omfile') [v8.32.0 try http://www.rsyslog.com/e/2359 Toadman Linux - Software 9 09-01-2018 12:41 PM
php form action : second action ?? esteeven Programming 7 05-08-2015 08:06 AM
KDE 3.5 KIOSK [Action Restrictions] not applying to profile ianz Linux - Desktop 2 05-21-2009 02:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration