Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:save-session fails to execute properly when executing from shell script #591

Open
marknuzz opened this issue Dec 29, 2018 · 2 comments
Open

Comments

@marknuzz
Copy link

marknuzz commented Dec 29, 2018

Operating system: Mac 10.14.2
version: 0.8.4

My script, setup-lnav.sh:

lnav -nq -d ./lnav.err \
    -c ":load-session" \
    # ...snip...
    -c ":save-session" \
    $1

in lnav.err (note the different session file names, the saved file ending with 50485.json is not actually saved to disk):

2018-12-29T00:32:23.635 I command_executor.cc:87 Executing: load-session
2018-12-29T00:32:23.636 I session_data.cc:382 loading bookmark db: /Users/personaluse/.lnav/log_metadata.db
2018-12-29T00:32:23.636 E sql_util.cc:541 duplicate column name: comment
2018-12-29T00:32:23.636 E session_data.cc:390 unable to upgrade bookmark table -- duplicate column name: comment
2018-12-29T00:32:23.636 E sql_util.cc:541 duplicate column name: tags
2018-12-29T00:32:23.636 E session_data.cc:390 unable to upgrade bookmark table -- duplicate column name: tags
2018-12-29T00:32:23.708 I session_data.cc:894 loading session file: /Users/personaluse/.lnav/view-info-a76db86f5ee4cb84f01d84aee2854c09.ts1546068702.ppid50454.json

2018-12-29T00:32:23.719 I command_executor.cc:87 Executing: save-session
2018-12-29T00:32:23.779 I session_data.cc:1446 Saved session: /Users/personaluse/.lnav/view-info-a76db86f5ee4cb84f01d84aee2854c09.ts1546068743.ppid50485.json

When running the same command in-line without a bash script, the command is run, the session is updated, and everything works as expected:

2018-12-29T00:36:51.991 I command_executor.cc:87 Executing: load-session
2018-12-29T00:36:51.992 I session_data.cc:382 loading bookmark db: /Users/personaluse/.lnav/log_metadata.db
2018-12-29T00:36:51.992 E sql_util.cc:541 duplicate column name: comment
2018-12-29T00:36:51.992 E session_data.cc:390 unable to upgrade bookmark table -- duplicate column name: comment
2018-12-29T00:36:51.992 E sql_util.cc:541 duplicate column name: tags
2018-12-29T00:36:51.992 E session_data.cc:390 unable to upgrade bookmark table -- duplicate column name: tags
2018-12-29T00:36:52.268 I session_data.cc:894 loading session file: /Users/personaluse/.lnav/view-info-a76db86f5ee4cb84f01d84aee2854c09.ts1546068782.ppid48983.json

2018-12-29T00:36:52.280 I command_executor.cc:87 Executing: save-session
2018-12-29T00:36:52.343 I session_data.cc:1446 Saved session: /Users/personaluse/.lnav/view-info-a76db86f5ee4cb84f01d84aee2854c09.ts1546069011.ppid48983.json

To attempt to minimize variables, I am running the script from the same working directory the script is in.

Is there a potential workaround in the meantime? Thanks!

@marknuzz
Copy link
Author

I think I misunderstood how sessions work. So it seems they are tied to the pid of the executing shell. What I'm looking to do is to ensure that after my script is run, the next time I open the given logfile, regardless of shell pid, I will have that filter command.

I'm thinking my next best option is to use a kludgey solution of running the filters as part of my "view logs" script, with the filter parameters being read by that script at runtime, from a parameters file which will be written to from my setup-lnav script.

In any case, would it be reasonable to add a bit to the documentation of save-session and load-session, explaining that the sessions are locked to the current shell pid?

@marknuzz
Copy link
Author

For anyone curious, here's what I ended up doing in my script:

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

APP_PID=$(node $DIR/android/get-pid.js)
echo "Launching lnav with logs filtered on app pid: $APP_PID"
lnav -c ":load-session" \
     -c ":reset-session" \
     -c ":filter-in (?<timestamp>\\d{2}-\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}.\\d{3}) (\\s?${APP_PID}) .*" \
     -c ":save-session" \
     "${DIR}/../data/logs/pangea-android-logcat.log"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant