Sponsored Content
Full Discussion: Conditional execution
Top Forums Shell Programming and Scripting Conditional execution Post 302853169 by edstevens on Friday 13th of September 2013 10:35:59 AM
Old 09-13-2013
Conditional execution

Here's an interesting (to me, anyway) little puzzle.

Background:
I have a process that restores a number of large(ish) files from tape backup. As an individual file is being written, it is owned by root, then the ownership is changed when that file is complete. Since this process can take some time (and operations, who actually runs it) isn't timely about starting it when requested or telling me when it completes, I wrote a little script to watch for the presence of the root-owned files:

Code:
echo "Please enter sleep interval: "
read sleep_interval
while :
do
ls -ltr /mydir |grep root
date
echo Sleeping $sleep_interval seconds
sleep $sleep_interval
done

So when I first kick it off, I set the sleep interval to something large, like 300. Then when I see files who are owned by root showing up, I cancel the script and resubmit with a sleep interval of 10.

So it occurs to me, could I code it to self-determine what the sleep interval should be. Check the outcome of the 'ls', and if nothing is owned by root sleep for 300, else sleep for 10. So, on first starting, there would be no files, so it would sleep for 300. On the first iteration that turns up a file, sleep goes to 10, and on first following iteration with no files owned by root, sleep goes back to 300.

In pseudo code, something like this:

Code:
while :
do
ls -ltr /mydir |grep root|grep -v "lost+found"
#- begin pseudo code
if nothing found
   sleep 300
else
   sleep 10
fi
# - end pseudo code
done

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

If conditional

Hi, I am new to unix and shell scripting.In my script,there is a line using the "if" conditional - if && ; then do something Here "x" is a variable holding string value.If it is not equal to a comma or a string,only then I want to enter the "if" loop. But I am getting error while... (1 Reply)
Discussion started by: abhinavsinha
1 Replies

2. Shell Programming and Scripting

Conditional execution and parallel jobs

how can i process jobs parallel with conditions below. Script1.ksh Script2.ksh Script3.ksh Script4.ksh Script5.ksh Script6.ksh Script7.ksh Script8.ksh Script9.ksh Script10.ksh After successful completion of Script1.ksh I need to run Script7.ksh. After successful... (4 Replies)
Discussion started by: ford2020
4 Replies

3. Shell Programming and Scripting

unix script for conditional execution

Below is my shell script. I am trying to execute two different BTEQ scripts depending on the day of the week. So on a saturday I will execute a certain BTEQ script and on other weekdays I will run the other script. #!/bin/ksh dt=`date +"%a"` if then bteq > final_output <<- EOF .run... (3 Replies)
Discussion started by: Mihirjani
3 Replies

4. Shell Programming and Scripting

Expect Issue Serial Forground Execution vs Concurrent Background Execution

I have an expect script that interrogates several hundred unix servers for both access and directories therein using "ssh user@host ls -l /path". The combination of host/path are unique but the host may be interrogated multiple times if there are multiple paths to test. The expect script is run... (2 Replies)
Discussion started by: twk
2 Replies

5. Shell Programming and Scripting

Help on shell script conditional execution when CPU Idle > 60%

I need a shell script that will monitor a few conditions and not execute until the these conditions are met. The problem I'm having is that I can not perform a database snapshot (backup) of a sybaseIQ database unless the CPU Status Idle % is above 60% or the snapshot (backup) fails. If... (2 Replies)
Discussion started by: pancona99
2 Replies

6. Shell Programming and Scripting

Conditional execution

Hi All, I want to echo a message in case a system is reachable by ping or echo a different message in case it's not reachable. Sample code i wrote is ping localhost -n 2 | grep 'ttl' > ping_op; ls ping_op > /dev/null && drReachable=Alive; echo -e `date`: \\t "DR server is reachable" >>... (5 Replies)
Discussion started by: Mr. Zer0
5 Replies

7. UNIX for Dummies Questions & Answers

Conditional execution of statements

Hi , I have a script which has multiple awk and sed commands like below. First one :- find /root/src/ -name "*csv" -size 0 -exec rm {} \; Second one: - ls *SRE*.txt > SRT_TRAN.dat rm *asr*.txt Third one :- find /root/src/ -name '*.csv' | while read FILENAME ; do awk... (2 Replies)
Discussion started by: shruthidwh
2 Replies

8. Shell Programming and Scripting

search and conditional execution

Hi, I have a list of files with different filenames like nam0001.txt,pan0001.txt etc coming in /data/inbox from various places. I needed a shell script which would:- 1)searches for a word from the filenames (coming in inbox directory) provided in input parameter. 2)if found, put in... (2 Replies)
Discussion started by: Saiesh
2 Replies

9. Shell Programming and Scripting

Conditional Execution of a Script.

I have a unix shell script Test.sh more Test.sh echo "Calling dbquery1.sh...." ./dbquery1.sh echo "Calling dbquery2.sh...." ./dbquery2.sh more dbquery1.sh sqlplus -s user1/password1@DB_SID @/tmp/storedprocedures/Hello.rcp I run Test.sh However, I do not want dbquery2.sh to be... (3 Replies)
Discussion started by: mohtashims
3 Replies

10. UNIX for Dummies Questions & Answers

Bashrc File - Conditional Command Execution?

Hello All, I was wondering if there is a way to execute a command in my ".bashrc" file based on how I logged into the PC? I was thinking maybe there is a way to check how the user (*myself) logged in, maybe somehow with the who command along with something else, but I'm not sure... I know I... (7 Replies)
Discussion started by: mrm5102
7 Replies
puzzle(1X)																puzzle(1X)

NAME
puzzle - 15-puzzle game for X SYNOPSIS
puzzle [-option...] OPTIONS
This option specifies the display to use; see X(1X). This option specifies the size and position of the puzzle window; see X(1X). This option specifies the size of the puzzle in squares. This option specifies the speed in tiles per second for moving tiles around. This option specifies an image file containing the picture to use on the tiles. Try "mandrill.cm." This only works on 8-bit pseudo-color screens. This option indicates that the program should create its own colormap for the picture option. DESCRIPTION
Executing puzzle with no arguments plays a 4x4 15-puzzle. The control bar has two boxes in it. Clicking in the left box scrambles the puzzle. Clicking in the right box solves the puzzle. Clicking the middle button anywhere else in the control bar causes puzzle to exit. Clicking in the tiled region moves the empty spot to that location if the region you click in is in the same row or column as the empty slot. BUGS
The picture option should work on a wider variety of screens. COPYRIGHT
Copyright 1988, Don Bennett. SEE ALSO
X(1X) AUTHOR
Don Bennett, HP Labs puzzle(1X)
All times are GMT -4. The time now is 05:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy