0

I'm trying to change the group owner of an output file that gets created from a script. right now the output looks like this :

-rw-rw-r-- 1 oasedms dba  1898 Apr 10 15:42 DRAFT_342870_8_1.xml

I want the group owner to be "adlib-adm" instead of dba.

I'm running this on rhel 6.5

Thanks in advance!

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
Wajahat Makki
  • 39
  • 1
  • 2
  • 5
  • 1
    Like always? Google "file change group linux"? – Peter - Reinstate Monica Apr 13 '15 at 14:47
  • `sudo chown adlib-adm:adlib-adm DRAFT_342870_8_1.xml` will change the group ownership as well as user ownership of the file... – ryekayo Apr 13 '15 at 14:48
  • i know i can change it individually but i want the default group to be adlib-adm when the script gets executed. So when the script gets executed I want all the files to have adlib-adm ad the group owner. I already changed the group owner of the directory – Wajahat Makki Apr 13 '15 at 14:50
  • Ah. You may want to edit your question.-- Presumably the default group of a file created by a script is that of the "primary" group of that user which can be set via `usermod`. (I have never done that, just googled...). Of course changing the primary group will have side effects which may be unintended, in which case changing the group explicitly is the only recourse. – Peter - Reinstate Monica Apr 13 '15 at 14:59
  • Does this answer your question? [Bash Scripting - How to set the group that new files will be created with?](https://stackoverflow.com/questions/1321168/bash-scripting-how-to-set-the-group-that-new-files-will-be-created-with) – Adam Millerchip May 31 '21 at 10:00
  • This really belongs on the ServerFault. But even more problematic is this is found through any basic google search. – rh0dium May 31 '21 at 21:19

2 Answers2

2

you can use chown command to change the owner and goup of the file.

chown adlib-adm:group /address/of/file

I hope this helps. Have a good day.

shiv garg
  • 761
  • 1
  • 8
  • 26
  • Very exact and helpful ! – salil vishnu Kapur Apr 13 '15 at 14:52
  • Thank you for the quick reply. I do know that you can change the group owner of individual files like that but what i want is that there is a script thats being executed and when it gets executed the files that it creates should AUTOMATICALLY have adlib-adm as a group owner. – Wajahat Makki Apr 13 '15 at 14:54
  • you should simply add these lines at the end of the bash script or you may call a bash script from the program before it ends. the bash script will change the permissions – shiv garg Apr 13 '15 at 14:57
  • I do understand that and I have recommended that to the end user but theres another server that has the same exact script and everything and when tht script gets run in that server the output has the correct group owner. The end user wants to know why its right on one server and not on the other eventhough they are the same exact servers. The script thats running successfully is the prod server and the other one is dev. – Wajahat Makki Apr 13 '15 at 15:00
  • have you checked the group of the user who is creating the file over the server where the correct file is getting generated. if the user is present in the required group then you can access that file – shiv garg Apr 13 '15 at 15:06
  • all the users and groups are actually in Active directory and controlled by VAS – Wajahat Makki Apr 13 '15 at 15:29
0
chgrp adlib-adm DRAFT_342870_8_1.xml

Edit: See Bash Scripting - How to set the group that new files will be created with?

You may also want to consider sg :

sg [-] [group [-c ] command]

sg - execute command as different group ID. The sg command works similar to newgrp but accepts a command. The command will be executed with the /bin/sh shell.

Community
  • 1
  • 1
Shane Voisard
  • 1,145
  • 8
  • 12