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
FAXCRON(8)						      System Manager's Manual							FAXCRON(8)

NAME
faxcron - HylaFAX routine maintenance script SYNOPSIS
/usr/sbin/faxcron [ -n ] [ -l lastrun ] DESCRIPTION
faxcron is a command script that does routine upkeep tasks in a HylaFAX spooling directory hierarchy. This script is intended to be invoked from cron(8) on behalf of the fax user (often the ``fax'' user is uucp) once a day, with the standard output sent by mail to the HylaFAX administrator. For example, the following crontab might be set up for the fax user: 25 23 * * * sh /usr/sbin/faxcron | mail FaxMaster The faxcron script does the following work: o report statistics for facsimile transmitted since the last time faxcron was run. o report statistics for facsimile transmitted in the past week. o report statistics for facsimile received since the last time faxcron was run. o report statistics for facsimile received in the past week. o report any recent calls that failed suspiciously and return the associated trace log; o purge data that is 30 days or older from the remote machine information directory; o delete information that is 30 days or older from session trace log files; o remove files from the tmp directory that are older than 1 day; o remove files in the received facsimile queue that are 7 days or older; o report sites that are currently having jobs rejected; and o force all session log files to be owned by the fax user and kept with protection mode 644. OPTIONS
-n Forces faxcron to run without updating any files. -l lastrun Forces the notion of the last time that faxcron was run to be lastrun. The value of lastrun is a date and time string of the form ``MM/DD/YY HH:MM'' (the date(1) format string ``%D %H:%M''). -info n Set the expiration time for data in the info database to be n days. -log n Set the expiration time for session log data to be n days. -rcv n Set the expiration time for files in the received facsimile queue to be n days. -tmp n Set the expiration time for files in the tmp directory to be n days. -mode m Set the file protection mode for session logs to m (a command line argument to chmod(1)). NOTES
This script requires nawk(1) or gawk(1) and a date (1) program that supports the ``+format'' option. If session logs are to be kept private this script must be modified to filter out sensitive information such as calling card numbers. (It should also be run with ``-mode 0600'' so that session log files are not publicly readable.) FILES
/var/spool/hylafax spooling area /var/spool/hylafax/status/lastrun timestamp of last run /usr/sbin/xferfaxstats for generating transmit statistics /usr/sbin/recvstats for generating receive statistics /var/spool/hylafax/tmp/faxcronXXXX temporary file for truncating session logs /var/spool/hylafax/tmp/faxlogXXXX temporary file for logs of failed calls SEE ALSO
cron(8), faxq(8), faxgetty(8), faxsend(8), xferfaxstats(8), recvstats(8), hylafax-server(5) May 12, 1996 FAXCRON(8)
All times are GMT -4. The time now is 11:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy