Operating System - HP-UX
1837085 Members
2272 Online
110112 Solutions
New Discussion

Re: Changing perms to owner then back to original.

 
Michael Allmer
Frequent Advisor

Changing perms to owner then back to original.

I am looking for some assistance in finding a solution to handle changing ownerships of directories to a owner prior to a cron job running, then back to the original owner once the other cron job is complete.

Example: If I start off with the following-


drwxr-xr-x cadadmin users scripts
drwxr-xr-x twetendl users twetendl
drwxr-xr-x valisys users valisys
drwxr-xr-x vanberbj users vanberbj
drwxr-xr-x walliske catia walliske

I need to change it to prior to the cron job starting:
drwxr-xr-x cadadmin users scripts
drwxr-xr-x cadadmin users twetendl
drwxr-xr-x cadadmin users valisys
drwxr-xr-x cadadmin users vanberbj
drwxr-xr-x cadadmin catia walliske

The change it back after the cron job runs.
drwxr-xr-x cadadmin users scripts
drwxr-xr-x twetendl users twetendl
drwxr-xr-x valisys users valisys
drwxr-xr-x vanberbj users vanberbj
drwxr-xr-x walliske catia walliske

We have looked at ACL’s but this will not work due to restriction of the how the cron job is running.
I know I can use the 'find' command to find the directories and change the ownership. I am unsure how to retain the orginal ownership and use it to change the ownership back.
8 REPLIES 8
Tim Nelson
Honored Contributor

Re: Changing perms to owner then back to original.

Is there an alterior motive to this ? e.g. something does not work as you expect and are attempting to resolve in this fashion ?

If so supply some big picture and maybe we can come up with a bigger solution ?

Other than finding the dirs and current perms then saving in a file, you will then need to parse out the rxwrw-r-x into either binary ( 765 or chars u+rwx,g+rw,o+rx ). not very eloquent.


TTr
Honored Contributor

Re: Changing perms to owner then back to original.

Who is the cron job running as? If it is not running as root you may not be able to change the permissions/ownership forth and back. The problem with changing ownership is that once the owner of a file changes ownership from himself to someone else, they have lost ownership of the file and they can not change it back. The new owner has to chnage the ownership back.

It the cron job is running as root you could build a listing in a tempfile with each file/directory path and the original permissions/ownership and use that file later on to restore the original settings.
Michael Allmer
Frequent Advisor

Re: Changing perms to owner then back to original.

The cron job that is running is a job that runs rsync to update files across servers. It does additional checks on files prior having rsync update the files. The cron job runs as 'cadadmin' Since 'cadadmin' does not own all the directories, then files cannot be updated within directories 'cadadmin' does not own.
Yogeeraj_1
Honored Contributor

Re: Changing perms to owner then back to original.

hi,

one dirty way will be to use ssh and script commands that will set the desired permissions.

hope this helps!
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Steven Schweda
Honored Contributor

Re: Changing perms to owner then back to original.

I'd look at changing owner/group+permissions
or using ACLs.

> We have looked at ACLâ s but this will not
> work due to restriction of the how the cron
> job is running.

Are you offering an impossibility proof for
this, or should we believe that you've tried
everything?

What, exactly, is this "restriction", and
why can't it be changed?
Dennis Handly
Acclaimed Contributor

Re: Changing perms to owner then back to original.

>Tim: you will then need to parse out the rxwrw-r-x into chars u+rwx,g+rw,o+rx. not very eloquent.

I have two scripts posted that will save and restore owners and permissions.
Rasheed Tamton
Honored Contributor

Re: Changing perms to owner then back to original.

You can do it using setacl - the only restriction is the file system should be JFS. In that case, you can use chacl/lsacl.

If you want some examples, please see the below link:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1190418

If you can explain exactly where you stuck, then someone will be able to assist you.
Michael Allmer
Frequent Advisor

Re: Changing perms to owner then back to original.

I appoligize for not stating my requirements clearly. I thank you all for you attempts in assisting me.