I have a problem where I need to change the ownership and permissions of one file that exists on more than 200 servers. I belong to 2 different groups and need to change the ownership from one group to another. I also need the permissions to be 644. This could be easily done if I had root access, but I don't. So instead I need to copy the file as one user and then remove the old file and then rename the recently copied file to the name of the old file. This becomes rather tedious, so I wanted to create a script to automate these tasks. I thought kornshell would do the trick but my script doesn't seem to be doing anything. Here is what I have so far:
#!/usr/bin/ksh sudo su - oradba cd config chmod 644 hostenv.cfg chown orainst hostenv.cfg exit sudo su - orainst cd config cp -p hostenv.cfg hostenv.cfgnew rm hostenv.cfg mv hostenv.cfgnew hostenv.cfg
I figured this would work because those are all the commands I need to run to successfully change the ownership/permissions of the file.
All I need to do is change the hostenv.cfg file from this:
-rwxrw---- 1 oradba dba 4433 May 1 21:43 hostenv.cfg
-rw-r--r-- 1 orainst dba 4433 May 1 21:43 hostenv.cfg
What can I do to fix my script? Also, if I need to build user prompts into my script to ask for passwords that is fine, but I thought the system would ask for me.
Here is what happens when I try to run my script:
My user is changed to oradba and nothing else happens... Until I type exit...
exit logout chmod: changing permissions of `hostenv.cfg': Operation not permitted chown: changing ownership of `hostenv.cfg': Operation not permitted