Writing to file failing (maybe due to lock?)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Writing to file failing (maybe due to lock?)
# 1  
Old 09-16-2008
Question Writing to file failing (maybe due to lock?)

Driver script kicks off supporter scripts in background.
The supporter script writes it's own PID ($$) into a status file. When script completes, deletes the PID from the status file.
Quote:
echo $PID >> $STATUS
##blah...blah
sed '/'$PID'/d' $STATUS > $STATUS.$$
mv $STATUS.$$ $STATUS
The driver script constantly polls this status file for number of lines. As and when it's get lower than XX number of lines, fires off another supporter script in background. This continues till all supporter scripts have started and then the driver program just waits for the $Status file line count to go to zero and stops.
Problem:
+++++++++++
I am echoing putting the $PID into Status file and removal too. I am seeing both in nohup.out. However, VERY, VERY ERRATICALLY sometimes although the echo statements on removal success are present, the $STATUS file still shows the PID! I checked and also determined these PIDs are indeed unique. Why is it that although the sed command runs successfully (the echo on removal is after the sed command with a if .. $? -eq 0 clause) the actual delete do not happen? Is it because at that point in time 2 or more background processes are "attacking" the $STATUS file and somehow sed fails to recognize it? What can be done to ensure that the sed command really does delete the entry, i.e. obtain a file lock/handle, etc. I think it's obvious, but the STATUS file is common.
# 2  
Old 09-16-2008
No help?

Please, can't anyone help me figuring out why sed commands returns 0 but still fails to delete the word? How to obtain an explicit lock on a file, do the sed-based delete, release the lock so that an alternate process can write into the file?
# 3  
Old 09-16-2008
No problems... the issue's resolved.

I resolved the file lock issue.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SSH is failing due to unknown reason

Hi, I have setup keys between user1@server1 and user2@server2 however, the ssh is failing. server1 is Linux 3.10.0-514.6.2.el7.x86_64 #1 SMP whereas server2 is 5.10 Generic_150400-40 sun4v sparc sun4v I have checked port 22 to be open and keys to be correct. I also find the permissions... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

Ssh failing due to Bad owner error

i am logged in with "user1" on host1. I m trying to ssh to host2 using user id "user2" $ ssh user2@host2 Bad owner or permissions on /home/user1/.ssh/config Question 1: Can you please tell me why am i getting the Bad owner permissions error on that directory ? Question 2: Where is it... (7 Replies)
Discussion started by: mohtashims
7 Replies

3. Shell Programming and Scripting

Writing if condition in shell script and failing to do requirement

Hi, I am trying to edit the values in a file. For example i am trying to edit the value of "ABC" in a file by executing shell script. Please Note that ABC value can be there mulitple times or it may not be there in the file Conditions for it is 1. If ABC is less than 123 then it should... (14 Replies)
Discussion started by: darling
14 Replies

4. Shell Programming and Scripting

Output redirection of c binary file to a file in shell script is failing

I am struck up with a problem and that is with output redirection. I used all the ways for the redirection of the output of c binary to a file, still it is failing. Here are the different ways which I have used: ./a.out | tee -a /root/tmp.txt 2>&1 ./a.out | tee -a /root/tmp.txt 1>&1 ./a.out |... (2 Replies)
Discussion started by: Maya29988
2 Replies

5. Solaris

zip -r <directory> failing due to 2GB limit - Just asking opinion

Hi, Am trying to run zip -r on a 2.4G directory and it is failing with the error below. I believe this is because of the 2G limit of the zip program. server101(oper01)/u01/temp$: date Thu Mar 15 12:53:44 NZDT 2012 server101(oper01)/u01/temp$: ls -l total 8 drwxr-x--x 4 oracle dba ... (1 Reply)
Discussion started by: newbie_01
1 Replies

6. UNIX for Advanced & Expert Users

Testing privileges -lock lockfile /var/lock/subsys/..- Permission denied

Hi all, I have to test some user priviliges. The goal is to be sure that an unauthorized user can't restart some modules (ssh, mysql etc...). I'm trying to automate it with a shell script but in same cases I got the syslog broadcast message. Is there any way to simply get a return code... (3 Replies)
Discussion started by: Dedalus
3 Replies

7. Homework & Coursework Questions

how to delete core file (file created due to apps crashed)

1. The problem statement, all variables and given/known data: When looking for corefiles, include any file with core in its name. (Some UNIX/Linux systems add the PID of the process that created the core to reduce the chances of overwriting an already existing core file that might be needed. The... (6 Replies)
Discussion started by: s3270226
6 Replies

8. Red Hat

Security Question: Lock after invalid login, Session Lock and Required Minimum Password Length

Hello all, If anyone has time, I have a few questions: How do I do the following in Linux. We are using Red Hat and Oracle Enterprise Linux, which is based on Red Hat too. 1. How to lock the account after a few (like 3) invalid password attempts? 2. How do you lock a screen after 30... (1 Reply)
Discussion started by: nstarz
1 Replies

9. Programming

Not able to compile Pro*c file due - give errors and points to /usr/include/.. file

I am trying to compile the pro*C file but gives errors. It says it encountered "std" while it was expecting ; , = ( $ $ORACLE_HOME/bin/proc tradewind/dataaccess/Blob.pcc Pro*C/C++: Release 10.2.0.3.0 - Production on Fri May 9 11:10:54 2008 Copyright (c) 1982, 2005, Oracle. All rights... (0 Replies)
Discussion started by: shafi2all
0 Replies

10. UNIX for Dummies Questions & Answers

how to lock keyboard without using lock command

how can I lock my keyboard while I'm away from the computer without using lock command. What other commands gives me the option to lock keyboard device? thanks (7 Replies)
Discussion started by: dianayun
7 Replies
Login or Register to Ask a Question