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
nohup(1)						      General Commands Manual							  nohup(1)

NAME
nohup - run a command immune to hangups SYNOPSIS
command [arguments] DESCRIPTION
executes command with hangups and quits ignored. If output is not redirected by the user, both standard output and standard error are sent to If is not writable in the current directory, output is redirected to otherwise, fails. If a file is created, the file's permission bits will be set to If output from is redirected to a terminal, or is not redirected at all, the output is sent to EXTERNAL INFLUENCES
Environment Variables determines the language in which messages are displayed. If is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty vari- able. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, behaves as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single- and multi-byte character code sets are supported. EXAMPLES
It is frequently desirable to apply to pipelines or lists of commands. This can be done only by placing pipelines and command lists in a single file, called a shell script. To run the script using features apply to the entire contents of file. If the shell script file is to be executed often, the need to type can be eliminated by setting execute permission on file. The script can also be run in the background with interrupts ignored (see sh(1)): file typically contains normal keyboard command sequences that one would want to continue running in case the terminal disconnects, such as: WARNINGS
Be careful to place punctuation properly. For example, in the command form: applies only to command1. To correct the problem, use the command form: Be careful of where standard error is redirected. The following command may put error messages on tape, making it unreadable: whereas puts the error messages into file EXIT STATUS
The following exit values are returned: The command specified by command was found but could not be invoked An error occurred in the nohup utility or the specified command could not be found Otherwise, the exit status of nohup will be that of the command specified. SEE ALSO
chmod(1), nice(1), sh(1), signal(5). STANDARDS CONFORMANCE
nohup(1)
All times are GMT -4. The time now is 08:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy