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
kcalarm(1M)															       kcalarm(1M)

NAME
kcalarm - add, delete, or list kernel tunable alarms, as well as turn kernel tunable monitoring on and off. SYNOPSIS
kcalarm threshold <event> interval comment <notification> tunable [tunable... kcalarm threshold <event> interval comment <notification> key tunable [tunable... kcalarm (on | off threshold <event> interval comment <notification> key tunable [tunable... kcalarm ] key [tunable... kcalarm (on |off | status <event> = (initial | repeat | return <notification> = notification_target:[data]:[port] DESCRIPTION
kcalarm is used to manage kernel tunable alarms and monitors; alarms and monitors are implemented in the kcmond(1M) daemon. Users can cre- ate, modify, delete, and list kernel tunable alarms. Alarms send a notification though various notification targets when a kernel tunable crosses a specified percentage threshold of its current setting. Monitoring is the process of collecting historical tunable data. When this feature is turned on, historical data is collected on the usage of supported tunables. This data is used by the kcusage (see kcusage(1M)) command to generate usage tables (including top consumers) for supported kernel tunables and enables graphs in the kcweb(1M) tool. Monitoring is turned on by default when the Kernel Configuration (kcweb) tool is installed. Root permissions are required to execute kcalarm when the -a, -d, -s, and -m (on|off) options are specified. Operands recognizes the following operands tunable Name of the kernel tunable. See kcusage(1M) for a list of tunables that can be monitored. If the token "any" is used as the tunable, an alarm is created that monitors all monitorable tunables, except dbc_max_pct and ninode; this alarm sends notifi- cation if any of them exceed the specified threshold. The list of valid tunables can be found on the kcusage(1M) manpage. If no options are provided, the kcalarm will list alarms for the specified tunable(s), or for all tunables if none are specified. Options recognizes the following options Add a kernel tunable alarm for the specified tunable(s). Separate alarms will be added for each tunable named with the -a option. The -a option should be used with the -n option, and with -t, -e and -i if values other than the defaults are desired. Delete a kernel tunable alarm for the specified tunable(s). If multiple alarms exist for a single tunable, -k, -t, -e, -i, and -n options can be used to clarify the delete request. The command will interactively confirm each delete request unless the -F (force) option is spec- ified. Force the deletion or change of status of an alarm, without confirming the request. This option is only valid with -d and -s options. This is a percentage of the current setting of the kernel tunable over which the alarm should sound (i.e 75 indicates 75 percent of the value of the current setting). The default is 80 percent. Only whole numbers are allowed. (initial|repeat|return) Event type. This determines what type of event will trigger a notification when the threshold is crossed. The three options are initial, repeat, and return. initial sends a notification from the first polling, and each time the threshold is exceeded (once per set of polls when the tunable exceeds the threshold). repeat sends a notification any time the tunable is polled and its value exceeds the specified threshold (this can lead to a large number of messages if the polling interval is small). return sends a notification at the first polling at which resource usage falls below threshold after exceeding it. The -e option can be specified multiple times to provide combinations of initial, repeat, and return. If no -e is provided with the -a option, the alarm will be added with the initial event type by default. This specifies how often the tunable data will be sampled (in minutes). If no interval is specified with the -a option, an interval of 5 minutes will be used by default. This is a user provided string to help identify the alarm request. This text is included in notifications. The comment is empty by default. Unique key used to disambiguate alarms from each other. Can be used with -s, -d and when listing. The value of the key is displayed when listing with the -l (long) option. Notification target if an alarm is triggered, where notification is a colon separated string (in quotes if it contains any spaces) in the form notification_target:[data]:[port]. The kcalarm command uses the Event Monitoring Service (EMS) infrastructure, and therefore supports any of the notification targets supported by EMS (see ems(5)). Valid choices are: opcmsg:(normal|warning|minor|major|critical): This option can be used with OpenView/IT/Operations notifications. (tcp|udp):host:port This option is used for any application that accepts these protocols and follows the rules defined in the EMS Developer's Kit. snmp:(normal|warning|minor|major|critical): This option can be used with any application that accepts SNMP traps, such as OpenView NNM, or IT/O. The application must be setup to recognize the SNMP traps generated. email:address: This option causes an email to be sent to the specified address when an alarm is triggered. If a comment is provided, it will be included in the body of the email message. syslog:: This option causes notifications to be written to syslog on the local system. If a comment is provided, it will be included in the syslog entry. textlog:filename: This option causes notifications to be written to the specified filename on the local system. If a comment is provided, it will be included in the textlog entry. console:: This option causes notifications to be written to the system console on the local system. If a comment is provided, it will be included. Long listing in machine readable format. By default output is in human readable format. Note that output will not be localized when the -l option is specified. Set the status of an alarm for the specified tunable(s), either on or off. This option allows temporarily disabling alarms without deleting them. If multiple alarms exist for a given tunable, -k, -t, -e, -i, and -n options can be used to clarify the on/off request. Turn kernel tunable monitoring on, off, or check the present status. This option is on by default when the Kernel Configuration tool is installed. This option must be on in order for kcusage to generate tables of historical tunable usage. Turning monitoring off will disable the features kcusage and kcweb that depend on the availability of historical data. RETURN VALUE
Upon completion, kcalarm returns one of the following values: Successful. Command failed, see STDERR for specifics. EXAMPLES
Add an alarm that monitors all kernel tunables, which will send notification to admin@corp.com if any kernel tunable resource exceeds 90% of the tunable's current setting. Default values for event type and polling interval will be used. kcalarm -a -t 90 -n email:admin@corp.com: any Add an alarm for the nproc kernel tunable with a threshold of 65%, repeat event type, polling interval of five minutes, with an email noti- fication target of admin@corp.com. kcalarm -a -t 65 -e repeat -i 5 -n email:admin@corp.com: nproc Delete the alarm added in the above example. The kcalarm command will confirm this request since the -F wasn't specified. kcalarm -d -t 65 -e repeat -i 5 -n email:admin@corp.com: nproc Force the deletion of ALL nproc alarms. kcalarm -d -F nproc List all of the alarms for the max_thread_proc kernel tunable. kcalarm max_thread_proc Turn off kernel tunable monitoring. kcalarm -m off AUTHORS
was developed by Hewlett-Packard. FILES
Log file for EMS clients, including kcalarm. Any errors are logged here. SEE ALSO
kcweb(1M), kcusage(1M), kcmond(1M) ems(5) kcalarm(1M)
All times are GMT -4. The time now is 03:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy