LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What is the easiest way to monitor a bash script (https://www.linuxquestions.org/questions/linux-newbie-8/what-is-the-easiest-way-to-monitor-a-bash-script-4175460696/)

ulkoma 05-04-2013 11:06 AM

What is the easiest way to monitor a bash script
 
into act? as in debugging it in real time wachting the processes forking, terminating ... etc

Thanks

btmiller 05-04-2013 11:40 AM

You could always try the "-x" flag, which will exho each command in the script as it runs. If you need to actually watch processes forking and terminating, you're probably going to need to have bash run the script under a debugger such as gdb.

shivaa 05-04-2013 11:59 AM

Add a bedug mode i.e. set -xv just below the shebang, so you can check step by step execution of the script:
Code:

#!/bin/bash
set -xv
command1
command2
.....
.....
commandN

Or you can invoke your script as:
Code:

~$ bash -xv scriptname.sh

pan64 05-04-2013 12:22 PM

if you need low level kernel trace (file i/o, fork, memory handling and similar) you can use strace: strace -o result [-f] <command>
it will work not only for shell script but for apps also.

ulkoma 05-04-2013 04:41 PM

What if I use TOMOYO Linux? does it work as a debugger?

btmiller 05-04-2013 08:08 PM

A debugger is a piece of software that can be run on any distribution.The tools mentioned above (strace, gdb, the -x flag) will work on any distribution.

konsolebox 05-05-2013 02:57 AM

A good logging system within bash's script would be helpful as well.

unSpawn 05-05-2013 05:08 AM

Quote:

Originally Posted by ulkoma (Post 4944960)
What if I use TOMOYO Linux? does it work as a debugger?

TOMOYO is a path-based MAC. In the sense of debugging access you could use it in learning mode but as others already said look at distro-agnostic tools first as having to install TOMOYO just for debugging a script would be disproportional.

It could be helpful if you would elaborate what the problem exactly is you're trying to solve.

pan64 05-05-2013 05:14 AM

Quote:

Originally Posted by konsolebox (Post 4945168)
A good logging system within bash's script would be helpful as well.

what do you mean by that? something like log4j in java? in general the shells have no such library collections, but in special cases you can [only] implement such features. For example the service start/stop environment has common scripts and functions.

konsolebox 05-05-2013 06:57 AM

Quote:

Originally Posted by pan64 (Post 4945230)
what do you mean by that? something like log4j in java? in general the shells have no such library collections, but in special cases you can [only] implement such features. For example the service start/stop environment has common scripts and functions.

He could borrow my concepts and even make use of those codes in my project: http://sourceforge.net/p/playshell/c.../source/log.sh

And also check some libraries like: log4sh, and bash-logger.

ulkoma 05-06-2013 06:01 PM

Quote:

Originally Posted by unSpawn (Post 4945223)
TOMOYO is a path-based MAC. In the sense of debugging access you could use it in learning mode but as others already said look at distro-agnostic tools first as having to install TOMOYO just for debugging a script would be disproportional.

It could be helpful if you would elaborate what the problem exactly is you're trying to solve.

man I love your answers... I just like to see processes invoking/forking other processes in a path-based way, TOMOYO looked cool in a video I watched, unfortunately it seems I cant find a debugger that shows the output in a way similar to TOMOYO


All times are GMT -5. The time now is 01:28 AM.