LinuxQuestions.org
Review your favorite Linux distribution.
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, 12:06 PM   #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, 12:40 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,284

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
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, 12:59 PM   #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 01:02 PM.
 
1 members found this post helpful.
Old 05-04-2013, 01:22 PM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,512

Rep: Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434
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, 05: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, 09:08 PM   #6
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,284

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
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, 03: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, 06:08 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,332
Blog Entries: 55

Rep: Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533
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, 06:14 AM   #9
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,512

Rep: Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434
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, 07: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, 07: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 26 03-14-2011 02:41 PM
log monitor bash script tronica Programming 5 05-14-2008 03:53 AM
Using PHP, run bash script and see results on Server's Monitor xmrkite Linux - Software 6 10-17-2006 02:28 PM
perl/bash script to monitor all processes running in my machine pudhiyavan Linux - Security 4 07-19-2005 03:09 PM
Bash script help for dummy. need to monitor and restore my adsl connection default Programming 10 07-09-2004 05:10 PM


All times are GMT -5. The time now is 05:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration