Search and replace without changing ownership


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search and replace without changing ownership
# 8  
Old 04-10-2010
MySQL

Quote:
Originally Posted by dheian
No, nginx. Apparently the sed changing ownership issue can be fixes by adding the -c switch to the sed command.
I understood you..But sed doesnt change ownerships..I think your webserver isnt recognizes your web page files because of its changed modif times.

For example

Code:
 
ls -l filex
-rw-rw-r-- 1 testuser testuser 44 Mar 27 08:29 filex
 
whoami
root
 
sed -i '2i selam' filex  # in edit mode (changes date)
-rw-rw-r-- 1 testuser testuser 50 Mar 27 08:32 filex
 
sed -ci '2i selam' filex   # in copy mode (changes date)
ls -l filex
-rw-rw-r-- 1 testuser testuser 56 Mar 27 08:33 filex

I use GNU sed version 4.1.5

As result ownnership didnt change..
Your problem is webserver doesnt recozgnize because of your file's timestamps changes..
I think you must use touch command for update modif times of your files.

add your command
Code:
 
find . -type f -print0 | xargs -0 touch -ma

# 9  
Old 04-10-2010
Quote:
Originally Posted by ygemici
I understood you..But sed doesnt change ownerships..I think your webserver isnt recognizes your web page files because of its changed modif times.

For example

Code:
ls -l filex
-rw-rw-r-- 1 testuser testuser 44 Mar 27 08:29 filex
 
whoami
root
 
sed -i '2i selam' filex  # in edit mode (changes date)
-rw-rw-r-- 1 testuser testuser 50 Mar 27 08:32 filex
 
sed -ci '2i selam' filex   # in copy mode (changes date)
ls -l filex
-rw-rw-r-- 1 testuser testuser 56 Mar 27 08:33 filex

I use GNU sed version 4.1.5

I believe that to be a misleading example, because you're running as root and root can chown the files it creates to preserve ownership. If sed is run as a regular user who has read access to the files but is not the owner, then it could not possibly maintain ownership unless it is running suid root.

Even when running with superuser privileges, at least some implementations out there do not even attempt to preserve ownership. The following example is using an old version of freebsd sed on osx 10.4.11.

Code:
$ whoami
testuser
$ touch myfile
$ ls -l myfile
-rw-r--r--   1 testuser  testuser  0 Apr 10 10:38 myfile
$ sudo su
Password:
# whoami
root
# sed -i '' 'i\           
> hi' myfile
# ls -l myfile
-rw-r--r--   1 root  testuser  0 Apr 10 10:41 myfile
#

Looking at current freebsd sed source, http://www.freebsd.org/cgi/cvsweb.cg...?annotate=1.44, these days it seems to make an attempt to preserve ownership and permissions:
Code:
                    389:                        fchown(fileno(outfile), sb.st_uid, sb.st_gid);
                    390:                        fchmod(fileno(outfile), sb.st_mode & ALLPERMS);

Again, as mentioned above, even though the attempt is made, fchown cannot change the ownership of "outfile" unless it's run with superuser priviliges.


Quote:
Originally Posted by ygemici
I think your webserver isnt recognizes your web page files because of its changed modif times.
...snip...
Your problem is webserver doesnt recozgnize because of your file's timestamps changes..
I think you must use touch command for update modif times of your files.

add your command
Code:
find . -type f -print0 | xargs -0 touch -ma

That doesn't make any sense to me. If a webserver ceased to serve a file because of a change in the file's timestamps, it would be impossible to edit/update a file on a website without further intervention. If I'm mistaken, I'd appreciate some elaboration or a link to further information on the matter.

Regards,
Alister

Last edited by alister; 04-10-2010 at 02:37 PM..
# 10  
Old 04-10-2010
MySQL

I can try different sed on freebsd or solaris and old system if i can find any chance..I work on GNU sed 4.1.5..ok.

for second state , I have similiar problem with my apache tomcat server..
My webserver was didnt recognizing more before..When i touch my files my webserver execute the new files.
Maybe I think same problem is.

Regards
@ygemici

Quote:
Originally Posted by alister
I believe that to be a misleading example, because you're running as root and root can chown the files it creates to preserve ownership. If sed is run as a regular user who has read access to the files but is not the owner, then it could not possibly maintain ownership unless it is running suid root.

Even when running with superuser privileges, at least some implementations out there do not even attempt to preserve ownership. The following example is using an old version of freebsd sed on osx 10.4.11.

Code:
$ whoami
testuser
$ touch myfile
$ ls -l myfile
-rw-r--r--   1 testuser  testuser  0 Apr 10 10:38 myfile
$ sudo su
Password:
# whoami
root
# sed -i '' 'i\           
> hi' myfile
# ls -l myfile
-rw-r--r--   1 root  testuser  0 Apr 10 10:41 myfile
#

Looking at current freebsd sed source, http://www.freebsd.org/cgi/cvsweb.cg...?annotate=1.44, these days it seems to make an attempt to preserve ownership and permissions:
Code:
                    389:                        fchown(fileno(outfile), sb.st_uid, sb.st_gid);
                    390:                        fchmod(fileno(outfile), sb.st_mode & ALLPERMS);

Again, as mentioned above, even though the attempt is made, fchown cannot change the ownership of "outfile" unless it's run with superuser priviliges.




That doesn't make any sense to me. If a webserver ceased to serve a file because of a change in the file's timestamps, it would be impossible to edit/update a file on a website without further intervention. If I'm mistaken, I'd appreciate some elaboration or a link to further information on the matter.

Regards,
Alister
# 11  
Old 04-10-2010
Hi, ygemici:

Quote:
Originally Posted by ygemici
I can try different sed on freebsd or solaris and old system if i can find any chance..I work on GNU sed 4.1.5..ok
Did you try your earlier "sed -i" example but as a non-root user with read permissions but who is not the owner?

I found an old pentium 2 laptop with a circa 2006 Debian install, which also happens to have GNU sed 4.1.5; I tried `sed -i` and it did indeed change the file's ownership as expected (User A owned the file, User B ran the sed command, ownership changed from A to B, neither user was root).

Also, oddly, your 4.1.5 seems to support a -c flag (which was also mentioned earlier by the original poster), but my 4.1.5 does not. There is no mention of it at Invoking sed - sed, a stream editor nor did I see any sign of it in the option handling source code of gnu sed 4.1.5 and 4.2 (which I downloaded from Sed - Free Software Directory - Free Software Foundation). The only mention I can find is at sed(1) - Linux man page

Perhaps I need to have my eyes checked, but I'm totally lost with regard to the origin of the -c flag (there is also no mention of it in the man pages of OpenBSD, NetBSD, FreeBSD, OSX, Solaris, POSIX, HP-UX, AIX). If anyone can shed some light on it, I'd be curious to know what's going on (even though I seldom use a GNU userland).

Regards,
alister

Last edited by alister; 04-10-2010 at 04:03 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

User's Home directory ownership is changing Automatically

Hi , on my Solaris 10 machine user's home directory ownership is being changed automatically to their UID. can any one please tell me whats the reason behind it . users are there in /etc/passwd file . /etc/shadow file is also there along with nssswitch.conf file and there is no changes made to... (5 Replies)
Discussion started by: usernew
5 Replies

2. Shell Programming and Scripting

Changing ownership of a directory, subdirectory and files as same as in another server

accidentally i have changed ownership of a directory,subdirectory and files wil below command. I want to the change ownership back as same as in same directory on another server. How can i do it? chown -R user:group /u01 is there any simple script? it is really an urgent need.. (2 Replies)
Discussion started by: johnveslin
2 Replies

3. UNIX for Dummies Questions & Answers

regarding changing ownership and group

i am able to change the mode using chmod and able to change permission. but i am not able to change group and ownership. getting as invalid can any one help me regarding this . (4 Replies)
Discussion started by: satheeshkr_cse
4 Replies

4. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

5. UNIX for Dummies Questions & Answers

changing ownership?

how would i change ownership of file1 so the user NATE gets ownership of the file? (1 Reply)
Discussion started by: trob
1 Replies

6. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

7. Red Hat

changing wtmp ownership and permission

Hi, I am using redhat AS 3. Recently, I was asked to implement a security control on the OS: to change ownership of /var/log/wtmp to root:sys and permission to 600. However, when I made the change and reboot the machine, everything was reverted. How come? Please help. The following is the... (1 Reply)
Discussion started by: voa2mp3
1 Replies

8. UNIX for Advanced & Expert Users

File group ownership changing automatically

Hi everyone, Need help with an issue. The group ownership of files on my Solaris system is getting changed automatically. Could someone tell me the reason why? And how could I correct it? One more info- everytime the ownership changes, it changes to "x". Thanks :confused: (1 Reply)
Discussion started by: top_gun
1 Replies

9. UNIX for Dummies Questions & Answers

copy directory without changing ownership setting

hi currently i am migrating some directories over to a new server. is there any command (rcp or ftp or anything) for me to use without changing the ownership and permission of the directory? i am copying some directories from unix machine to linux machine. what is the exact command? thanks... (2 Replies)
Discussion started by: legato
2 Replies

10. Solaris

Diectory ownership ...changing

Help...... I am running a 420R w/sol 8 and I am trying to install sun's monitoring software srs netconnect. I have installed it on 6 other boxes with no problem. Installation failed with the message: ## Installing part 1 of 1. /etc/opt/SUNWsrspx/CustomerCert.pem... (6 Replies)
Discussion started by: finster
6 Replies
Login or Register to Ask a Question