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

How to check if a line is a complete bash command or not? #95

Open
nhtha opened this issue May 25, 2024 · 1 comment
Open

How to check if a line is a complete bash command or not? #95

nhtha opened this issue May 25, 2024 · 1 comment

Comments

@nhtha
Copy link

nhtha commented May 25, 2024

Dear experts,
How to use bashlex to separate a bash script file into groups of multi-line commands to execute each group with paramiko.exec_command function?
For example, I want to separate the following bash script into 2 groups (multi-line string), first is "data_mp_info=..." command and second is "if .. fi" command:
data_mp_info=$(df -BG | awk '$6 == "/data"')
if [ "$data_mp_info" != "" ]; then
data_mp_size_in_GB=$(echo $data_mp_info | awk '{print $2}' | sed 's/.$//')
data_mp_used_in_GB=$(echo $data_mp_info | awk '{print $3}' | sed 's/.$//')
data_mp_free_in_GB=$(echo $data_mp_info | awk '{print $4}' | sed 's/.$//')
data_mp_used_percent=$(echo $data_mp_info | awk '{print $5}' | sed 's/.$//')
else
data_mp_size_in_GB=-1
data_mp_used_in_GB=-1
data_mp_free_in_GB=-1
data_mp_used_percent=-1
fi

Please advise,
Thank you,
Ha Nguyen

@nhtha
Copy link
Author

nhtha commented May 26, 2024

How to check if a command requires another command, for example the rest commands use variable from the first command?

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