creating a subscript which checks for a flag?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers creating a subscript which checks for a flag?
# 1  
Old 02-16-2009
Power creating a subscript which checks for a flag?

I want to incorportae a subscript in a job script which is used for loading purposes.
What i require is that before a job runs it should check for a flag ,if flag is not present then create it and the loading should start.
Once loading finishes it should delete the flag.
So if any other load comes while loading is happening it should wait until that flag is deleted by the previous load?
# 2  
Old 02-17-2009
This is a "Dummy mutex" using the filesystem:
Code:
while [ -f /var/run/flag ]; do
  sleep 10; 
done
touch /var/run/flag
trap "rm -f /var/run/flag" 0    # works on most modern shells
... proceed

It is possible for a race condition to occur, so don't use this for anything critical.

If you have "flock" you can do this more securely:
Code:
#!/bin/sh
# script1.sh
exec flock /var/run/flag $PWD/script2.sh

Now script2.sh will only be run when the "flag" is not locked.
# 3  
Old 02-18-2009
thank you....

suppose i want to create a log for the load file which waited {basically for how long it waited and all related info like time and all} while the previous file was waiting ..how do i proceed in the same script?
# 4  
Old 02-18-2009
At the start of the script do:
Code:
{ echo "Starting process; date; } >somelogfile
# 
# <put wait code here>
#
{ echo "Finished waiting"; date; } >somelogfile

For best results, use a format with date that is both human and machine readable:
Code:
date "+%s %c"

The first field will be the number of seconds since 1970, so you can use that to easily and precisely calculate how long it was waiting. The second part of the line is the human-readable timestamp.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Calling subscript with sh vs. ksh

I ran into an issue today that I was able to resolve, but I don't quite understand why the resolution worked. I'm wondering if anyone can help me make sense of it. I have a "kicker" script that calls 4 subscripts on a RHEL 6.9 server. It calls the scripts in sequence checking for a 0 exit code... (5 Replies)
Discussion started by: derndingle
5 Replies

2. Shell Programming and Scripting

Daily Checks

Hey Guys, I'm seeking some assistance in getting this script to run as a cron job for the user oracle.. the script is basically to perform 2 ADRCI checks... see the script below... i'm getting the following error: /export/home/oracle/Daily_Checks/ADRCI_Daily_Checks.sh: syntax error at line 16:... (7 Replies)
Discussion started by: Racegod
7 Replies

3. UNIX for Dummies Questions & Answers

Name of subscript

I have a script that executes another, so script1 executes script2. Using the $0 variable inside script2 returns the name of script1. How can I get the name of script2? Thanks (2 Replies)
Discussion started by: charding1
2 Replies

4. Shell Programming and Scripting

How to use a subscript and a super script while printing a character

I want to print a output after executing a awk command How to represent a subscript or a superscript while using print command eg : Ts. where character 's' is subscript of T T2 where '2' is the superscript of T thank you. Shashi: (3 Replies)
Discussion started by: shashi792
3 Replies

5. Shell Programming and Scripting

How to solve Subscript out of range?

Hi everyone I want to compare numbers line by line Example array = 12 15 15 19 14 I have code: #!bin/csh set a = 1 set b = 2 while($a<6) if($array == $array)then echo "EQUAL" else if($array < $array)then echo "SMALLER" else echo "BIGGER" endif @ a = $a + 1 @ b = $b + 1 (2 Replies)
Discussion started by: vincyoxy
2 Replies

6. Shell Programming and Scripting

checking for a flag in a subscript?

I want to incorportae a subscript in a job script which is used for loading purposes. What i require is that before a job runs it should check for a flag ,if flag is not present then create it and the loading should start. Once loading finishes it should delete the flag. So if any other load... (2 Replies)
Discussion started by: bathla
2 Replies

7. AIX

Checking for flag in a subscript?

I want to incorportae a subscript in a job script which is used for loading purposes. What i require is that before a job runs it should check for a flag ,if flag is not present then create it and the loading should start. Once loading finishes it should delete the flag. So if any other load... (1 Reply)
Discussion started by: bathla
1 Replies

8. UNIX for Advanced & Expert Users

Doing Checks on a file

I have a process that I am trying to provide a solution for and have hit a brick wall and would like some pointers in the right direction. Basically on a daily basis a report is automatically generated in a CSV format (FIRST.CSV) which includes codes and amounts in the following format: ... (6 Replies)
Discussion started by: SAMZ
6 Replies

9. Shell Programming and Scripting

Perl hashes "Can't use subscript on private hash"

This is driving me mad, where am I going wrong? The relevant segment of code: sub getndsybcons { my @servers=@{$_}; my @sybservers=@{$_}; my %results; foreach my $server(@servers) { my $biggestsyb; my $biggestsybval=0; ... (9 Replies)
Discussion started by: Smiling Dragon
9 Replies

10. Shell Programming and Scripting

Calling subscript but sleep halts the main script

Ok, I have written a main script which checks a directory contents every 30 secs then sleeps. The subscript does a usermod, if the user is logged on, it sleeps for 30 secs and then trys again over and over again. Here's the problem. when the subscript is called ./subscript.sh or exec... (1 Reply)
Discussion started by: doublejz
1 Replies
Login or Register to Ask a Question