0

I'm trying to lock a file using the command lock. Its syntax is

./lock </path/to/file/name>

I need to lock a bunch of files in a given directory and in order to achieve this I'm using two scripts:

  1. parent.sh
  2. child.sh

parent.sh will call a child.sh process for every file. So, if I need to lock 9 files I will have parent.sh spawn 9 child.sh but unfortunately this isn't happening.

[root@localhost /]# cat parent.sh
#!/bin/ksh
for f in /vol4/commit/file[1-9]
do
 sh /child.sh & $f
done

[root@localhost /]# cat child.sh
#!/bin/ksh
./lock $1

When I run sh parent.sh, I got the following error

[root@localhost /]# sh parent.sh
parent.sh: line 4: /vol4/commit/file1: Permission denied
parent.sh: line 4: /vol4/commit/file2: Permission denied
parent.sh: line 4: /vol4/commit/file3: Permission denied
parent.sh: line 4: /vol4/commit/file4: Permission denied
parent.sh: line 4: /vol4/commit/file5: Permission denied
parent.sh: line 4: /vol4/commit/file6: Permission denied
parent.sh: line 4: /vol4/commit/file7: Permission denied
parent.sh: line 4: /vol4/commit/file8: Permission denied
parent.sh: line 4: /vol4/commit/file9: Permission denied

Since I'm running as root, I didn't expect any permissions issue here but that's what I'm seeing.

2

Line 4 of parent.sh, you wrote sh /child.sh & $f. The ampersand must be put at the end of the command like that: sh /child.sh $f &.

In your case, you are trying to run sh /child.sh in background, and then you are executing $f in foreground, which will lead to a permission denied as I can assume that your files /vol4/commit/file[1-9] are not executable.

Also, you might want to note that if your file is in read only, you might not be able to edit it or acquire write lock, even for root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.