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

pd: Linux pipeline debug - preserves intermediate outputs in a linux terminal pipeline command #741

Open
1 task
irthomasthomas opened this issue Mar 16, 2024 · 1 comment
Labels
CLI-UX Command Line Interface user experience and best practices linux Linux notes tools links shell-script shell scripting in Bash, ZSH, POSIX etc

Comments

@irthomasthomas
Copy link
Owner

TITLE: ketancmaheshwari/pd: Linux pipeline debug

DESCRIPTION: "pd.sh : preserve intermediate outputs in a Linux terminal pipeline command

In a typical Linux terminal piped command, the intermediate outputs (and errors, if any) are lost. This tool preserves intermediate outputs and errors for inspection and/or debugging. It decomposes each stage of the pipeline as a separate command and places it in a shell script. It then runs the script with user permission. It prints the exit status of the commands and saves standard output and error in numbered files inside a created dir with a random name.

Usage Examples:

$ ./pd.sh 'ls -lr |  grep \$(date +%b)'
Want to run now? [y/N] y
1. Exit status of ls -lr is 0
2. Exit status of grep Jun is 0
The stdouts and stderrs are in [./2qg65f.dir](./2qg65f.dir) dir

In a debugging scenario, a quick way to run this is to use !!, the bash shorthand to print last command run, for instance:

$ ps aux | grep -v grep | grp -i -e \$USER
...some error...
$ ./pd.sh "!!"
./pd.sh "ps aux | grep -v grep | grp -i -e \$USER"
Want to run now? [y/N] y
1. Exit status of ps aux is 0
2. Exit status of grep -v grep is 0
3. Exit status of grp -i -e ketan is 127
The stdouts and stderrs are in [./omzele.dir](./omzele.dir) dir

But this is same as tee

Yes. Except that it preserves standard errors of the intermediate commands (in addition to stdout) and is relatively easy to read compared to interjecting tee commands at each stage of the pipeline.

Known Limitations

No way to escape the shell expansion in the quick !! way. One has to manually escape the $ using \, for instance in the following pipeline the awk will run without $1 because bash expansion eats $1:

$ free -m|grep Mem:|awk '{print \$4}'
$ ./pd.sh "!!"
./pd.sh "free -m|grep Mem:|awk '{print \$4}'" #should be \\\$4
Want to run now? [y/N] y
1. Exit status of free -m is 0
2. Exit status of grep Mem: is 0
3. Exit status of awk {print } is 0
The stdouts and stderrs are in [./4cs37n.dir](./4cs37n.dir) dir

URL: https://github.com/ketancmaheshwari/pd

Suggested labels

@irthomasthomas irthomasthomas added CLI-UX Command Line Interface user experience and best practices linux Linux notes tools links shell-script shell scripting in Bash, ZSH, POSIX etc labels Mar 16, 2024
@irthomasthomas
Copy link
Owner Author

Related content

#24

Similarity score: 0.86

#56

Similarity score: 0.86

#22

Similarity score: 0.85

#730

Similarity score: 0.85

#6

Similarity score: 0.85

#102

Similarity score: 0.84

@irthomasthomas irthomasthomas changed the title ketancmaheshwari/pd: Linux pipeline debug pd: Linux pipeline debug - preserves intermediate outputs in a linux terminal pipeline command Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI-UX Command Line Interface user experience and best practices linux Linux notes tools links shell-script shell scripting in Bash, ZSH, POSIX etc
Projects
None yet
Development

No branches or pull requests

1 participant