LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-04-2013, 11:06 AM   #1
ulkoma
Member
 
Registered: Feb 2012
Distribution: CentOS
Posts: 69

Rep: Reputation: Disabled
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
 
Old 05-04-2013, 11:40 AM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
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.
 
1 members found this post helpful.
Old 05-04-2013, 11:59 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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

Last edited by shivaa; 05-04-2013 at 12:02 PM.
 
1 members found this post helpful.
Old 05-04-2013, 12:22 PM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,630

Rep: Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265
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.
 
1 members found this post helpful.
Old 05-04-2013, 04:41 PM   #5
ulkoma
Member
 
Registered: Feb 2012
Distribution: CentOS
Posts: 69

Original Poster
Rep: Reputation: Disabled
What if I use TOMOYO Linux? does it work as a debugger?
 
Old 05-04-2013, 08:08 PM   #6
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
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.
 
Old 05-05-2013, 02:57 AM   #7
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
A good logging system within bash's script would be helpful as well.
 
Old 05-05-2013, 05:08 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by ulkoma View Post
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.
 
Old 05-05-2013, 05:14 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,630

Rep: Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265
Quote:
Originally Posted by konsolebox View Post
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.
 
Old 05-05-2013, 06:57 AM   #10
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by pan64 View Post
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.
 
Old 05-06-2013, 06:01 PM   #11
ulkoma
Member
 
Registered: Feb 2012
Distribution: CentOS
Posts: 69

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by unSpawn View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Bash Script to Monitor URL anishkumarv Linux - Newbie 28 08-29-2019 11:41 AM
log monitor bash script tronica Programming 5 05-14-2008 02:53 AM
Using PHP, run bash script and see results on Server's Monitor xmrkite Linux - Software 6 10-17-2006 01:28 PM
perl/bash script to monitor all processes running in my machine pudhiyavan Linux - Security 4 07-19-2005 02:09 PM
Bash script help for dummy. need to monitor and restore my adsl connection default Programming 10 07-09-2004 04:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:34 AM.

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