Skip to content

Instantly share code, notes, and snippets.

@vdegenne
Last active January 15, 2020 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdegenne/0819880940520aa77f1587e1c8f5b914 to your computer and use it in GitHub Desktop.
Save vdegenne/0819880940520aa77f1587e1c8f5b914 to your computer and use it in GitHub Desktop.
Open the pm2 logs of the current project (current directory)
#!/usr/bin/bash
pm_id=$(node <<EOF
const pm2_processes = `pm2 jlist`;
const pm2_process = pm2_processes.filter(proc => proc.pm2_env.pm_cwd === "`pwd`");
if (pm2_process.length) {
// one process found
console.log(pm2_process[0].pm_id)
process.exit(0);
}
// else // not found
process.exit(1);
EOF
)
if [ $? -ne 0 ]; then
echo "pm2 process not found"
else
pm2 logs $pm_id
fi
@vdegenne
Copy link
Author

This script requires pm2 and nodejs to be installed on the system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment