Sponsored Content
Top Forums Shell Programming and Scripting Question regarding shells and subshells when a script is run Post 302435067 by DeCoTwc on Tuesday 6th of July 2010 09:47:33 AM
Old 07-06-2010
Question regarding shells and subshells when a script is run

I have the following script running with nohup on one of my servers:

Code:
#!/bin/bash
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#set log number
#i=1
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#Check if log exits, if so incrememnt log number up so we don't clobber
#while [[ -f /tmp/ethtool.$i.dump ]];do let i=i+1;done
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#Location of streamer log
LOGFILE=/opt/VideoServer/logs/streamer_log.txt
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#Before tailing logs, dump current eth information
ethtool -S eth3 > /tmp/ethdump.$(date "+%m.%d.%y.%H.%M").start
cat /proc/net/cxgb3/ofld_dev0/stats >> /tmp/ethdump.$(date "+%m.%d.%y.%H.%M").start
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#Start tailing the log
tail -F $LOGFILE|while read line;do
        line=($line)
        if [[ "${line[2]}" == "E" ]]; then
            echo "${line[*]}" | grep -q "FX_HR_Timer_Sink::restart_timer_"
                if [[ $? -eq 0 ]];then
                        LOGTIME=$(date "+%m.%d.%y.%H.%M")
                        echo "${line[*]}" > /tmp/ethdump.$LOGTIME
                        echo >>  /tmp/ethdump.$LOGTIME
                        echo >>  /tmp/ethdump.$LOGTIME
                        ethtool -S eth3 >>  /tmp/ethdump.$LOGTIME
                        echo >>  /tmp/ethdump.$LOGTIME
                        echo >>  /tmp/ethdump.$LOGTIME
                        cat /proc/net/cxgb3/ofld_dev0/stats >>  /tmp/ethdump.$LOGTIME
                        #let i=i+1
                fi
        fi
    done

All it's doing is watching a log file, and looking for errors (as indicated by E in the third column) and then checking to see if that error is a specific problem we're having, and if so, dumping some information about the interface. The script runs perfectly, and creates the dump files exactly as expected. The one thing I don't understand is why it seems to create two processes when it is run:

Code:
[root@p1b021 ~]# ps -ef|grep logWatch.sh
root      6675     1  0 Jul05 ?        00:00:00 /bin/bash ./logWatch.sh
root      6681  6675  0 Jul05 ?        00:00:01 /bin/bash ./logWatch.sh
root      8221  8195  0 09:44 pts/0    00:00:00 grep logWatch.sh

I assume it has something to do with creating subshells when the script is run, but as I (unfortunately) learned most of my scripting and whatnot from trial and error, and not from real book learning, simple things like this escape me.

I've tried to do some reading, and while I understand shells and subshells to a point in theory, I'm having a hard time understanding what's going on in practice. Could anyone give me the idiots explanation of why I'm spawning two processes to do one job? (I know the script isn't running twice at the same time...only one dump file is being created).
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

basic question about shells?

I have come across the topic of changing shells, does that mean that all Unix operating systems comes with a variety of shells built in and its up to the user to select a shell of his/her choice? (2 Replies)
Discussion started by: wmosley2
2 Replies

2. UNIX for Advanced & Expert Users

script to run different shells which run different processes

Hi, Would like to ask the experts if anyone knows how to run a script like this: dtterm -title shell1 run process1 on shell1 dtterm -title shell2 run process2 on shell2 cheers! p/s: sorry if i used the wrong forum, quite concussed after watching world cup for several nights; but I... (2 Replies)
Discussion started by: mochi
2 Replies

3. Shell Programming and Scripting

Killing parent shells from subshells (KSH)

Hi all, I have a shell script which calls other shell scripts, depending on the input. Within a.sh, I have a command which calls b.sh (ie. ksh b.sh) Normally, we use the exit function to terminate a shell. However, if I choose to call exit from b.sh, I will return to the parent shell who... (4 Replies)
Discussion started by: rockysfr
4 Replies

4. Shell Programming and Scripting

Using different shells in one script

Hi, Is it possible to use multiple shells in one script. There are sometimes we need to club shell specific commands in single script. for example in bash mode we use -e with echo to use Escape sequence but in ksh it is not required. How to tell a UNIX command to run in a specific shell. ... (2 Replies)
Discussion started by: sanjay1979
2 Replies

5. Shell Programming and Scripting

Book and Links about Shells; and zsh question

HI, I would like to ask You about some good books or links where I can find information about shells, theoretical information. I will be grateful if You can help me And I have question about zsh loop trivial script: #!/bin/zsh for i in {1..100000} do echo $i; doneexec time is 10... (9 Replies)
Discussion started by: Physix
9 Replies

6. Shell Programming and Scripting

Question on tweaking the PATH variable to allow the world to run my executable script

All, I am pretty new to Unix and still in the learning curve :) I have a simple requirement for which I did not get an answer yet (Atleast I do not know how to keyword the search for my requirement!!!). I have an executable script my.script1 in a folder /data/misc/scripts/dev, which when... (5 Replies)
Discussion started by: bharath.gct
5 Replies

7. Shell Programming and Scripting

how to run an already made script run against a list of ip addresses solaris 8 question

how to run an already developed script run against a list of ip addresses solaris 8 question. the script goes away and check traffic information, for example check_GE-VLANStats-P3 1.1.1.1 and returns the results ok. how do I run this against an ip list? i.e a list of 30 ip addresses (26 Replies)
Discussion started by: llcooljatt
26 Replies

8. UNIX Desktop Questions & Answers

How to run addtional Shells on top of the default shell

Hi What is the command to run additional available shells on top of default shell. I am using bash also how can i tell that the additional shells are actually running? Also what is the advantage of running additional shells on top of your default login shell of bash? Lastly... (1 Reply)
Discussion started by: Bill Thompson
1 Replies

9. UNIX for Dummies Questions & Answers

How to run additional shells

Hi, unix newbi here. Im currently on the bash shell, what are the commands to run additional shells? for example i want to run csh and then ksh? Thanks. BT. (2 Replies)
Discussion started by: BillThompson
2 Replies

10. Shell Programming and Scripting

Run commands in a script in different shells

Hi to all, i have the following problem... i want to run three commands in a script in different shells... the first command is running always and is needed for the second on to run properly... example # Procedure 1 xterm -e exec1 arg1 arg2 # Procedure 2 xterm -e exec2 arg1 arg2 #... (6 Replies)
Discussion started by: paladinaeon
6 Replies
SYSPROFILE(8)						      System Manager's Manual						     SYSPROFILE(8)

NAME
sysprofile - modular centralized shell configuration DESCRIPTION
sysprofile is a generic approach to configure shell settings in a modular and centralized way mostly aimed at avoiding work for lazy sysad- mins. It has only been tested to work with the bash shell. It basically consists of the small /etc/sysprofile shell script which invokes other small shell scripts having a .bash suffix which are contained in the /etc/sysprofile.d/ directory. The system administrator can drop in any script he wants without any naming convention other than that the scripts need to have a .bash suffix to enable automagic sourcing by /etc/sysprofile. This mechanism is set up by inserting a small shell routine into /etc/profile for login shells and optionally into /etc/bashrc and/or /etc/bash.bashrc for non-login shells from where the actual /etc/sysprofile script is invoked: if [ -f /etc/sysprofile ]; then . /etc/sysprofile fi For using "sysprofile" under X11, one can source it in a similar way from /etc/X11/Xsession or your X display manager's Xsession file to provide the same shell environment as under the console in X11. See the example files in /usr/share/doc/sysprofile/ for illustration. For usage of terminal emulators with a non-login bash shell under X11, take care to enable sysprofile via /etc/bash.bashrc. If not set this way, your terminal emulators won't come up with the environment defined by the scripts in /etc/sysprofile.d/. Users not wanting /etc/sysprofile to be sourced for their environment can easily disable it's automatic mechanism. It can be disabled by simply creating an empty file called $HOME/.nosysprofile in the user's home directory using e.g. the touch(1) command. Any single configuration file in /etc/sysprofile.d/ can be overridden by any user by creating a private $HOME/.sysprofile.d/ directory which may contain a user's own version of any configuration file to be sourced instead of the system default. It's names have just to match exactly the system's default /etc/sysprofile.d/ configuration files. Empty versions of these files contained in the $HOME/.syspro- file.d/ directory automatically disable sourcing of the system wide version. Naturally, users can add and include their own private script inventions to be automagically executed by /etc/sysprofile at login time. OPTIONS
There are no options other than those dictated by shell conventions. Anything is defined within the configuration scripts themselves. SEE ALSO
The README files and configuration examples contained in /etc/sysprofile.d/ and the manual pages bash(1), xdm(1x), xdm.options(5), and wdm(1x). Recommended further reading is everything related with shell programming. If you need a similar mechanism for executing code at logout time check out the related package syslogout(8) which is a very close compan- ion to sysprofile. BUGS
sysprofile in its current form is mainly restricted to bash(1) syntax. In fact it is actually a rather embarrassing quick and dirty hack than anything else - but it works. It serves the practical need to enable a centralized bash configuration until something better becomes available. Your constructive criticism in making this into something better" is very welcome. Before i forget to mention it: we take patches... ;-) AUTHOR
sysprofile was developed by Paul Seelig <pseelig@debian.org> specifically for the Debian GNU/Linux system. Feel free to port it to and use it anywhere else under the conditions of either the GNU public license or the BSD license or both. Better yet, please help to make it into something more worthwhile than it currently is. SYSPROFILE(8)
All times are GMT -4. The time now is 01:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy