Getting warning message while creating a file thru script

I have a script, it will create 3 files
---------
file1=dataout/file1.txt
file2=dataout/file2.txt
file3=dataout/file3.txt

echo "0" > $file3
---------

For file1 and file2 we are not initializing any values.

But for file3 we are initializing the value of 0.

When we execute the script. file1 and file2 are created with chmod 664 permission.

But the file3 is created with chmod 644 permission.

The file3 has to be created with chmod 664 permission. So we have tried by giving the following code.

------------
file1=dataout/file1.txt
file2=dataout/file2.txt
file3=dataout/file3.txt

echo "0" > $file3
chmod 664 $file3
------------

If I execute the script, I am not getting any warning message. If the script is executed by some other id, we are getting the warning message "chmod:dataout/file3.txt: not owner".

Can anyone help me to fix this issue.

Thanks
Krishnakanth Manivannan

is other users are in same group ?

Yes...

One more thing.. how come file1 and file2 are having chmod 664 permission and file3 alone is having chmod 644 permission when executing the script.

Krishnakanth Manivannan

chmod -f 664 $file3

1 Like