permissions in scripts
Hey all I'm having one heck of an issue I hope you can help me with.
I have a script if I login as "su" the script works like a champ.
BUT if I login as "su -" I get an error because the wrong fields are used.
I know the easy answer..logiin as "su" but the db admins are used to"su -"
and change here is like pulling teeth.
I thougth it might be a permissions thing so I set the new scripts to 744 to match the old ..no help.
What am I missing????????????
Ok I bit the bullet and changed the script to read the next field.
Oh it worked BUT then when it tries to tar the file I get:
tar: 10\:13: Cannot stat: No such file or directory
BUT it puts a tar file in the directory under the correct name BUT not the correct byte count.
Remember I had the above error last week
So what the he!! am I missing what is messed up???????????????????
I think the problem is that when you use:
Originally Posted by mace
it takes you to the user's ("root", if no other user specified) home directory,
but when you use:
it does not. So, it's just a matter of "where" you run the script (or where "tar" looks for files) .
P.S. if you use "su" in the script, you may also have to use it with other options like -l -s and -c. See "man su" for that.
su - loads up a clean environment, like you would get if you logged in as that user to begin with. su doesn't have the clean environment, so any variables, aliases, and things like that will still be set from the original user. su - doesn't just change the home directory. Perhaps your script is relying on something that is not as easily accessible with a new, clean environment. It's very hard to tell what's going on without seeing the script itself.
Well I thought about it for awhile and came up with the fix.
I deleted all the scripts and recreated them while I was root(su -)
This solved the problem.
Now the question is WHY?????????????
When you run the command 'su' a new, interactive shell is spawned belonging to user root. You remain in the same directory as when you ran the command. THat means your scripts and the files you are tarring are accessible with a relative path.
When you run 'su -' you spawn a new login shell for user root. This means that a different initialisation file is read and also you will find yourself in /root which is roots home directory.
Now if your script was relying on calling files that were in the directory from wich you issued the 'su -' command, and the absolute paths to these files were not specified in the script then you will get file not found errors.