Sponsored Content
Top Forums Shell Programming and Scripting Problem with nohup use in scripting Post 302538582 by Corona688 on Wednesday 13th of July 2011 12:05:46 PM
Old 07-13-2011
I see a few things problematic with this:

Code:
alarm_file_array="test1.alarms test2.alarms test3.alarms test4.alarms"
for file in ${alarm_file_array[@]}
do
	nohup tail -f $file |awk 'NR>10' >> output.alarms 2>/dev/null &
done

First and foremost, if you did get all three of these pipe chains writing to output.alarms independently, they wouldn't know or care about each other -- they'd just write whatever they want, wherever they want, whenever they want, potentially overwriting each others' contents. You should have a separate logfile for each tail.

Second of all, 'tail' and 'awk' are separate processes. The warning message is coming from the standard error of tail, and you're only redirecting awk.

Third of all, you're only putting awk in the background, not tail, which is why tail hangs -- not because of nohup.

Fourth, it makes no sense to use nohup at the start of a pipe chain, because it does what it says it's doing -- sends its stdout into nohup.out and not into the pipe feeding into awk.

You can achieve a similar effect to nohup by redirecting all streams to /dev/null, which will work for the entire pipe chain. You can also put an entire subshell in the background with ( ) .

Code:
alarm_file_array="test1.alarms test2.alarms test3.alarms test4.alarms"
for file in ${alarm_file_array[@]}
do
        (   exec 0</dev/null # stdin
            exec 1>/dev/null # stdout
            exec 2>/dev/null # stderr
            tail -f $file |awk 'NR>10' >> ${file}.out ) &
      disown
done

The 'disown' is so the script won't wait for the background jobs to finish before it quits. Some shells don't have disown, but those wouldn't wait for background jobs anyway.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem executing nohup

I am trying to submit background jobs using the nohup command on a client system where my session is running under a "master shell" (BASH). If I try to nohup the actual job (ie: nohup MYJOB.BAT > MYJOB.LOG 2>&1 &) the command will fail with a return code of 126 and a "permission denied" message.... (0 Replies)
Discussion started by: christyw
0 Replies

2. Solaris

problem with nohup

While executing a ksh file with a input parameter in background like the following bash-2.03$nohup fil.ksh 4 & the nohup session is stopped. The same ksh file while executed like bash-2.03$fil.ksh 4 works fine. I am trying the above in Solaris 5.8 in bash shell. Please let me... (2 Replies)
Discussion started by: kkna
2 Replies

3. UNIX for Dummies Questions & Answers

Problem with nohup command

Hello folks, I have got a script which telnets to different boxes and runs a certain script with 3 run time args. The line from the script which does it is: (sleep 1; echo $USERID ; sleep 1; echo $PASSWD ; sleep 1 ; echo y ; sleep 1 ; echo "\r" ; sleep 1 ; echo "cd $FILEPATH" ; sleep 1 ; sleep 1... (1 Reply)
Discussion started by: Rajat
1 Replies

4. Shell Programming and Scripting

Scripting on AIX and using nohup

ok... want to start off by saying i am sorry for the ignorance... still trying to figure out the diffs between solaris and aix... and i think that is where i am running into problems... :o SITTIATION: we are doing an implementation for Oracle's CC&B... we recently switched from... (1 Reply)
Discussion started by: Dagaswolf
1 Replies

5. Shell Programming and Scripting

problem with exit while using nohup

Hi, I am kinda confused with this, am not sure what is happening i have a script say test.sh ---------- cat myfile | while read line do exit 2 done echo "out of loop" ----------- as it is evident, the exit should cause the script to terminate ,hence producing no output for the... (1 Reply)
Discussion started by: sumirmehta
1 Replies

6. Shell Programming and Scripting

Problem with nohup

Hello I am running this script inst.sh #!/bin/ksh sqlplus -s username/password @temp.sql ----Here is my temp.sql set serveroutput on select instance_name from V$instance; exit When i run the script inst.sh on the command prompt...it runs fine...but when i run it using... (5 Replies)
Discussion started by: njafri
5 Replies

7. Shell Programming and Scripting

Problem regarding nohup.out

There is a daemon which is constantly writing to this particular nohup.out file.This daemon can't be stopped. But the large size of this file is hampering the directory space.I want to write a script which will wait for 48 hours and then delete the contents of the file ( nohup.out ), but not the... (1 Reply)
Discussion started by: Gourav
1 Replies

8. UNIX for Advanced & Expert Users

Problem on throwing sftp in nohup

Hi, but it is possible to effect a sftp in??? thanks thousand Germanico ---------- Post updated at 07:01 AM ---------- Previous update was at 05:51 AM ---------- Hi, but it is possible to effect a sftp in nohup mode??? (2 Replies)
Discussion started by: GERMANICO
2 Replies

9. Ubuntu

nohup problem

Hi All I am struggling to get a process to run in the background on a Ubuntu Linux machine. I run: - /home/brad > /usr/bin/nohup sudo /home/brad/spideroak/jsystem/runner/runAgent < /dev/null & 5611 /home/brad > /usr/bin/nohup: appending output to `nohup.out' + Stopped (SIGTTOU) ... (9 Replies)
Discussion started by: steadyonabix
9 Replies

10. AIX

Nohup problem

Hi I need to execute about 1000 scp commands sequential , so I made "scp.sh" - like this scp - rp ... scp - rp ... ............ scp - rp ... then I run nohup sh scp.sh &The problem is: nohup process stopped when I closed session, or when the session expired,... Something wrong :(:(:( ... (4 Replies)
Discussion started by: bobochacha29
4 Replies
kcmond(1M)																kcmond(1M)

NAME
kcmond - EMS Kernel Tunable Monitor daemon SYNOPSIS
kcmond DESCRIPTION
The kcmond daemon monitors the consumption of kernel resources. It is an Event Monitoring Services (EMS - see ems(5)) monitor. The data collected by kcusage can be displayed by kcusage(1M). kcmond includes a resource dictionary file (/etc/opt/resmon/dictionary/kcmond_01.dict) which is used by EMS to identify resources for moni- toring. Users can control the monitoring of each kernel tunable by setting a percentage value for the consumption of that resource. For example, if the user sets a value of 75 for nproc, the Kernel Tunable Monitor will report an event when the number of processes reaches 75% of the nproc setting. The kcalarm(1M) command is used to add, modify and delete kernel tunable alarms. The kcusage(1M) command is used to view data collected by kcmond. The kcweb(1M) command provides a Web-based, graphical user interface to control alarms and view usage data, including graphs of the usage data. kcmond is a light weight daemon that will exit after being idle for ten minutes. SUPPORTED PARAMETERS
For a complete list of the kernel tunables that can be monitored with this daemon, see the kcusage(1M) manpage. DEPENDENCIES
kcmond must be run by the registrar process of the Event Monitoring Service (EMS) and is not designed to be run from the command line. AUTHORS
was developed by Hewlett-Packard. FILES
Executable. The resource dictionary for kcmond, describes the location (e.g. /system/kernel_tunables/nproc) of kernel tunables in the resource hierar- chy and references kcmond as the resource monitor. Log file for the entire Resource Monitor Framework, including kcmond. Any errors are logged here. SEE ALSO
kcalarm(1M), ems(5), kcusage(1M) kcmond(1M)
All times are GMT -4. The time now is 09:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy