[Klug-general] Looking at shell scripts during execution

David Halliday david.halliday at gmail.com
Thu Nov 22 09:58:29 UTC 2012


I have used screen for running scripts, many of us on the team use it as a
matter of course. I remember discovering screen and deciding that sliced
bread had nothing on it!

I hadn't seen this method of running scripts within a screen session
before, very interesting. Although it doesn't give me the immediate
snapshot on all running scripts that my bash functions do (which was part
of the original aim).


On 21 November 2012 19:42, Alan Buchel <alan at communitytechnology.org.uk>wrote:

> **
> My fave for running and monitoring scripts is GNU screen.
> With it you can just run the script in screen sessions and attach to it
> when you want to see the status (or debug) your script.
>
> screen -S foo
> screen -r foo
> /path/to/script.sh
> CTRL-a d #detach from session
>
> Far easier than debugging log files!
>
> When I want to run a number of scripts or use cron to kick them off, I
> write a wrapper script which creates a screen session and injects the
> commands for example:
>
> screen -dm foo
> sleep 5 #just gives the command time to execute
> screen -X -S foo -p0 eval 'stuff /path/to/script.sh'
> sleep 5
> screen -X -S foo -p0 eval 'stuff \015' #return key equivalent
>
> Any screen can then be recovered to current terminal with
>
> screen -r foo #if the screen is currently not attached to any terminal
>
> or
>
> screen -x foo  #if it is already attached to a terminal
>
> to detach from the screen session use:
>
> CTRL-a d
>
> Alan
> ================================
>
>
> On 21/11/12 16:26, David Halliday wrote:
>
> Hi, I recently had an issue where I wanted to ge some visibility on what
> some large script which included various tasks, functions, sub scripts
> etc... were doing.
>
> Mostly I wanted another way to view where a script was, what it was doing
> while it was still running. While the scripts do produce log files I wanted
> to view a snapshot of this point in time.
>
> ps does contain all this data but managing it is sometimes a little
> difficult, passing the filters to get the granularity you require and
> getting the formatting needed wasn't easy.
>
> So I created a pair of bash functions that I can include in a text file,
> then pull them into the command line and call them whenever I wanted an
> overview of my scripts.
>
> I have put the code on my wiki, hope this might be of use to someone else:http://david-halliday.co.uk/wiki/doku.php?id=linux:bits:process_tree_with_ps
>
> I just have to include the functions on the command line as:
> . /path/to/script.sh
>
> then call the main function to get all shell scripts and output their
> details:
> dh_script_view
>
> This should be fairly easy to understand and modify for viewing sub
> processes of any process you chose handing it's pid to the function:
> dh_pidtree
>
>
>
> _______________________________________________
> Kent mailing listKent at mailman.lug.org.ukhttps://mailman.lug.org.uk/mailman/listinfo/kent
>
>
> _______________________________________________
> Kent mailing list
> Kent at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/kent
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/kent/attachments/20121122/51c9963a/attachment-0001.html>


More information about the Kent mailing list