Operating System - Linux
1753328 Members
4944 Online
108792 Solutions
New Discussion юеВ

Re: sed command giving an error

 
srnagu
Occasional Advisor

Re: sed command giving an error

Hi,

Thanks again, for somany inputs.
I know I'm asking too much, but could you please help me in writing a script?
I will be grateful,if you could give me some basic idea to begin with atleast.
Dennis Handly
Acclaimed Contributor

Re: sed command giving an error

>could you please help me in writing a script?

You might want to read the following about assigning points to reward us for the answers we have already given:
http://forums.itrc.hp.com/service/forums/helptips.do?#33
Dennis Handly
Acclaimed Contributor

Re: sed command giving an error

>but could you please help me in writing a script? I will be grateful, if you could give me some basic idea to begin with at least.

With UNIX, you can break up the task with multiple scripts. As you feel more confident you can put them together.

Here are two scripts that will generate chown commands:
=================
chown_script_A.sh:
#!/usr/bin/ksh

# Use find to generate a list of files. Then build up chown for each
# file.
# Only do current filesystem
# Usage: list-of-directories

find $* -xdev -exec \ll -d {} +

=================
chown_script_B.sh:

#!/usr/bin/ksh

# Read stdin for a list of ll(1) output. Generate chown commands
# Use chown -h, since it works on symlinks and files/directories.

# Usage: ... | $0
# Usage: $0 < file

awk '
{
print "chown -h", $3 ":" $4, $9
} '

===============================

You would execute this on your good system:
chown_script_A.sh /etc | chown_script_B.sh > chown.sh

If you are happy with the contents, copy to your bad system as execute it as follows:
# sh chown.sh

Doing the chmod is harder since symlinks must be skipped and handling of SUID and sticky bits.

Here is my first pass at that script:
=================
chmod_script_C.sh:
#!/usr/bin/ksh

# Read stdin for a list of ll(1) output. Generate chmod commands

# Usage: ... | $0
# Usage: $0 < file

awk '
{
type = substr($1, 1, 1)

if (type == "l") {
print "# Symlink skipped:", $1, $9
next
}
user = substr($1, 2, 3)
group = substr($1, 5, 3)
other = substr($1, 8, 3)

# remove "-"
gsub("-", "", user)
gsub("-", "", group)
gsub("-", "", other)

# handle SUID and sticky bits
sub("s", "sx", user)
sub("S", "s", user)
sub("s", "sx", group)
sub("S", "s", group)
sub("t", "tx", other)
sub("T", "t", other)

print "chmod u=" user ",g=" group ",o=" other, $9
} '

===============================

You would execute this on your good system:
chown_script_A.sh /etc | chmod_script_C.sh > chmod.sh

If you are happy with the contents, copy to your bad system as execute it as follows:
# sh chmod.sh
srnagu
Occasional Advisor

Re: sed command giving an error

Hi,

Thank you so much..

You guys helped me a lot when my integrity was at risk.., my confidence was par low due to that typo .

I did in this way...

In working system, I wrote a small script with very few basic commands..

find / -user root -group root "*">/tmp/fs1
find / -user bin -group bin "*">/tmp/fs2
like this I continued for 5-6 combinations...

.................
.........

I copied this files to 'bad' server

In this server one by one I changed permissions using for loop

for i in `cat /tmp/fs1`; do chown -h root:root $i; done
for i in `cat /tmp/fs2`; do chown -h bin:bin $i; done

..........

This fixed most of the files.