Sponsored Content
Top Forums Shell Programming and Scripting Shell script to execute condition until an event occurs Post 302833659 by Scott on Wednesday 17th of July 2013 02:49:21 PM
Old 07-17-2013
It's because "$i" is initially undefined. Quoting it gets around this.

Code:
#!/usr/bin/ksh

cd $receive_dir
until [ "$i" = stopfile ]
 do
   for i in *; do
     time=$(date +%m-%d-%Y-%H:%M:%S)
     echo "$time"
     echo "$i"
  done
done

for i in `ls receive_dir`; do will produce an error if no files exist, and for i in *; do resolves to * if no files exist, and it seems a bit wasteful to scan a whole directory to look for a known file, so it's probably better just to check if the file exists.

Code:
until [ -f $receive_dir/stopfile ]

(not forgetting to add a sleep to the loop)
 

10 More Discussions You Might Find Interesting

1. Programming

Cannot catch SIGINT while serial break condition occurs

I setup termios structure with IGNBRK is not set and BRKINT is set. To allow the process to receive signals I call: fcntl(fd, F_SETOWN, getpid()); I have made a signal handler to catch all signals. I can catch SIGINT when pressing ctrl+c but when I send break signal over serial then it cannot... (13 Replies)
Discussion started by: gzz
13 Replies

2. Shell Programming and Scripting

keypress event in shell script

Hi All, How can I trap a character press in the shell script. For eg:- I have a script runinng a infinite loops , I will need to dispay menu asking for run process of to stop process and process stauts like we do in glance I have seen the traping the signal in glance command, (8 Replies)
Discussion started by: arvindng
8 Replies

3. UNIX for Dummies Questions & Answers

Can we trigger an shell script on an event

Hi, My program A updates a log called logA. I have a shell script S that is responsible to send emails reading from the log. I want to trigger execution of the script whenever there is an update to the log. Thanks in advance. (8 Replies)
Discussion started by: cv_pan
8 Replies

4. UNIX for Advanced & Expert Users

Truncation Occurs When Outputting Shell Script to stderr

Operating System: Solaris 10, Shell We are outputting the results of our scripts to the stderr file. However we have encountered a problem where some of the lines in the file are truncated. Is there a way to increase the terminal or column size within the script so that this does not... (4 Replies)
Discussion started by: fazzasx
4 Replies

5. AIX

if condition in AIX5.3-10 shell script

True if file exists and has been modified since it was last read. if then command else exit fi i am on AIX5.3-10. it does not understand -N any other way. i can use -ot (file1 is older than file2), but prefer -N if possible. (3 Replies)
Discussion started by: tjmannonline
3 Replies

6. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

7. UNIX for Dummies Questions & Answers

While condition in shell script

while do if ;then read driverName else driverName="" fi done can anyone please explain what exactly is happening on 1st line...is it like the conditions being ORed...I have no clue about this. (4 Replies)
Discussion started by: rtagarra
4 Replies

8. Shell Programming and Scripting

Shell script to poll a directory and stop upon an event

Need shell script to: 1/keep polling a directory "receive_dir" irrespective of having files or no files in it. 2/move the files over to another directory "send_dir". 3/the script should only stop polling upon a file "stopfile" get moved to "receive_dir". Thanks !! My script: until do... (0 Replies)
Discussion started by: iaav
0 Replies

9. Shell Programming and Scripting

Need Help to add Condition in Shell Script..

Hi Team, I m very new to shell scripting , i want to add following condition in my script . Can anybody help me. There are three port in My node "$port" port_A port_B port_C I Want to add following Conditions in my script. If Node is connected to port_A and port_B script... (10 Replies)
Discussion started by: Ganesh Mankar
10 Replies

10. Shell Programming and Scripting

If condition shell script beginner

Hi all I have the folloing process that needs checking often: ps -ef | grep ih bscsrtx 206 15901 0 11:28:10 pts/6 0:00 fih -r4 bscsrtx 218 15901 0 11:28:27 pts/6 0:01 aih bscsrtx 29763 15901 4 11:27:16 pts/6 0:59 rdh -prih root 429 27268 0 11:30:15 pts/td ... (13 Replies)
Discussion started by: fretagi
13 Replies
POWERD(8)						    BSD System Manager's Manual 						 POWERD(8)

NAME
powerd -- power management daemon for sysmon SYNOPSIS
powerd [-dn] DESCRIPTION
powerd acts upon power management events posted by the kernel's power management facility. When events are posted, powerd translates the event into a script name and a list of arguments. powerd then runs the script in order to implement the power management policy defined by the system administrator. powerd supports the following option: -d Enable debugging mode. Verbose messages and all messages intended for syslog(8) will be sent to stderr, and powerd will stay in the foreground of the controlling terminal. -n Prevent execution of power management scripts. CONFIGURATION SCRIPTS
All configuration of powerd is encapsulated into scripts that are run when power management events occur. The daemon will look for the scripts from the directory /etc/powerd/scripts. Configuration scripts are run synchronously; powerd will start the script and wait for its completion before it handles the next event. Configuration scripts are called with different arguments, depending on the script class. These classes are described in the following sec- tions. POWER SWITCH SCRIPTS Power switch scripts are called when a state change event occurs on a power switch device. Power switch scripts are called with two argu- ments: the device with which the event is associated, and the event type. The following power switch script names are defined: power_button This script is called when an event occurs on a power button device. reset_button This script is called when an event occurs on a reset button device. sleep_button This script is called when an event occurs on a sleep button device. lid_switch This script is called when an event occurs on a lid switch device. acadapter This script is called when an online or offline event occurs on an AC adapter device. hotkey_button This script is called when an event occurs on a hotkey button device. The following events are defined for power switch devices: pressed The button was pressed, the lid was closed, or the AC adapter was connected. released The button was released, the lid was opened, or the AC adapter was disconnected. Note that power and sleep button devices usually do not post this type of event. The following is an example of how a power button script might be invoked when a power button is pressed by the operator: /etc/powerd/scripts/power_button acpibut0 pressed ENVSYS SCRIPTS envsys(4) scripts are called when a condition was triggered in a sensor. These scripts are called with three arguments: the device associ- ated, the event type, and the sensor's name. The sensor_drive and the sensor_battery scripts uses a fourth argument: state description. The following envsys script names are defined: sensor_battery This script is called when an event occurs on a battery sensor (Wh/Ah/Battery state). sensor_drive This script is called when an event occurs on a drive sensor. sensor_fan This script is called when an event occurs on a fan sensor. sensor_indicator This script is called when an event ocurrs on a indicator/integer sensor. sensor_power This script is called when an event occurs on a power sensor (W/Ampere). sensor_resistance This script is called when an event occurs on a resistance sensor (Ohm). sensor_temperature This script is called when an event occurs on a temperature sensor. sensor_voltage This script is called when an event occurs on a voltage sensor. The following events are defined for fan, indicator, power, resistance, temperature, and voltage sensors: critical A critical condition was triggered. critical-under A critical under condition was triggered. critical-over A critical over condition was triggered. warning-under A warning under condition was triggered. warning-over A warning over condition was triggered. The following event is defined for all scripts, but it is only sent if any of the previous events has been previously sent: normal A normal state/capacity/condition was triggered. The following events are defined only for battery sensors: user-capacity Capacity dropped below the limit set by the user. low-power System is running in low power. This implies that the AC adapter is disconnected and all batteries are in critical or low capacity. The script shutdowns the system gracefully by default. The following events are defined for drive and battery sensors: state-changed The state of the sensor has been changed and it is not in the normal state. The following is an example of how a temperature sensor script might be invoked when a critical over condition is triggered: /etc/powerd/scripts/sensor_temperature lm0 critical-over "CPU Temp" SEE ALSO
acpi(4), acpiacad(4), acpibut(4), acpilid(4), envsys(4), i386/apm(4) HISTORY
powerd first appeared in NetBSD 2.0. Support to handle envsys(4) events appeared in NetBSD 5.0. AUTHORS
powerd was written by Jason R. Thorpe <thorpej@wasabisystems.com> and contributed by Wasabi Systems, Inc. Juan Romero Pardines added support to handle envsys(4) events. BUGS
Due to its synchronous nature powerd cannot be trusted to handle events within a certain time. BSD
December 15, 2010 BSD
All times are GMT -4. The time now is 08:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy