Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is there any way to remotely debug shell scripts? I know we can do the same for executables using gdbserver and ddd.
I was successful attaching the shell script in remote Linux box to gdbserver. But when I invoked ddd using arguments 'bashdb' and tried to debug it, it doen't seem to work..
You could try setting up a vncserver on the remote server and run the whole debugging session via VNC. That way you have an almost complete GUI session, just as when sitting in front of that server physically. Can be a bit slow, but should work otherwise.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Shell scripts cannot be debugged using a debugger, bash lacks the capabilities to provide the hooks for a debugger. (You can debug the bash executable that is, but that is not your goal) You have to insert echo statements in smart places. It also helps to run the script with
Code:
sh -x myscript.sh
As for the remote, set up an SSH session to the remote server and run the script in that session. No need for VNC as bash scripts are usually console based if you don't call GUI programs from the script.
I was able to locally debug shell scripts by attaching bashbd to ddd. I was expecting someting similar even in remote mode.
The linux box doesn't have ssh server installed, only telnet. I tried installing ssh, but it said no valid C++ compiler was found. In that case I presume even gcc is not installed in that box. And, to add to the worries, it doesnt have anymore free space to install applications. I use a 256MB flash card & debian dist in the box.
I guess as you said sh -x is the best solution for the moment.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
SSH and Telnet should provide an equal connection as seen from any application. The difference is that Telnet is not secure while SSH is. Therefor on most boxes Telnet is diabled. If it is there and SSH is not, you should be able to work over Telnet.
This gives you (sub)shell prompt where you can inspect cwd, file system, running processes, exported variables etc. at the point where the script is running.
If you need access to local variables and functions in the shell script, you can use more complex form of the same call-home idea. See:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.