LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 03-12-2009, 05:05 AM   #1
unev_21
Member
 
Registered: Mar 2009
Distribution: Ubuntu
Posts: 51

Rep: Reputation: 16
Unhappy Remote Debugging Shell scripts


Hi All,

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..

Any thoughts ppl??

Regards,
unev_21.
 
Old 03-12-2009, 06:14 AM   #2
T74marcell
Member
 
Registered: Mar 2009
Posts: 102

Rep: Reputation: 18
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.

Arch Linux

Last edited by T74marcell; 03-14-2009 at 01:14 AM.
 
Old 03-12-2009, 08:36 AM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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.

jlinkels
 
Old 03-12-2009, 02:11 PM   #4
unev_21
Member
 
Registered: Mar 2009
Distribution: Ubuntu
Posts: 51

Original Poster
Rep: Reputation: 16
thanks jlinkels & T74marcell.

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.

unev_21
 
Old 03-12-2009, 03:03 PM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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.

jlinkels
 
Old 10-17-2019, 06:01 AM   #6
askervin
LQ Newbie
 
Registered: Oct 2019
Posts: 1

Rep: Reputation: Disabled
Remote script that calls home for debugging

Sometimes it could be enough to make the script call home to you with netcat (nc). Add a line to your script:

Code:
mkfifo /tmp/f ; cat /tmp/f | sh -i 2>&1 | nc HOMEHOST HOMEPORT > /tmp/f
and wait for it to call at HOMEHOST:

Code:
$ nc -k -l -p HOMEPORT
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:

https://01.org/fmbt/blogs/ask/2019/d...emote-scripts/
 
  


Reply

Tags
debugging, remote, scripts, shell



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
debugging remote process in gdb arunachalam Linux - Software 2 02-18-2008 10:27 PM
using GDB for remote kernel debugging vibhooti Linux - Software 0 04-23-2007 01:17 AM
Debugging shell scripts konstantinmiller Programming 9 06-08-2006 05:33 AM
kernel debugging on remote system urwithsudheer Programming 0 03-23-2006 02:44 AM
FC4 Remote Kernel Debugging gratner Fedora 2 11-02-2005 05:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration