Re: sed command giving an error (1246 Views)
Reply
Occasional Advisor
srnagu
Posts: 10
Registered: ‎03-21-2008
Message 1 of 24 (1,246 Views)

sed command giving an error

[ Edited ]

Hi,

Will somebody please help me ?
When I execute this ....
paste -s -d"^m" swagent.log | sed '{s/\"\./\"\.\n/g}' > swagent.new
I get following error.
sed: Function {s/\"\./\"\.\n/g} cannot be parsed.

 

P.S. This thread has been moved from  HP-UX>General to HP-UX > languages. -HP Forum Moderator

Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 24 (1,246 Views)

Re: sed command giving an error

HI:

Drop the curly braces:

# sed 's/\"\./\"\.\n/g'

That said, what are you attempting to do? On HP-UX there is 'ux2dos' and 'dos2ux' to convert between Unix and DOS (Windows) line terminations. See the manpages for 'dos2ux'.

Regards!

...JRF...
Acclaimed Contributor
Dennis Handly
Posts: 25,190
Registered: ‎03-06-2006
Message 3 of 24 (1,246 Views)

Re: sed command giving an error

As JRF says, drop the {}. But if you really really want them, I think you need a ";" before the "}".

You also seem to have a "\" before the double quote. This isn't needed and may mess you up.

You might explain what you are doing. You seem to be adding CRs. Then you seem to be adding newlines but not after the CRs, after '".'.
Occasional Advisor
srnagu
Posts: 10
Registered: ‎03-21-2008
Message 4 of 24 (1,246 Views)

Re: sed command giving an error

Hi,

Thanks for quick response.

When I tried this without {}

This is the error

paste -s -d"^m" swagent.log | sed 's/\"\./\"\.\N/g' > swagent.new

Error which I got :--


sed: Memory allocation failed.


Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 5 of 24 (1,246 Views)

Re: sed command giving an error

Hi (again):

> sed: Memory allocation failed.

Again, exactly what is your objective?

Your command creates one HUGH single-line file that is longer than your 'sed' buffers can tolerate.

Regards!

...JRF...
Occasional Advisor
srnagu
Posts: 10
Registered: ‎03-21-2008
Message 6 of 24 (1,246 Views)

Re: sed command giving an error

By mistake in HP UX, Ihave changed the owner and gid of all the files.
After that I did run swverify \*
It generated a log file.
Please find attached doc.

I want to merge 1st and 2nd line, 3rd and 4th line ...........

That is why I'm using sed
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 7 of 24 (1,246 Views)

Re: sed command giving an error

Hi (again):

> By mistake in HP UX, I have changed the owner and gid of all the files. After that I did run swverify \* ...I want to merge 1st and 2nd line, 3rd and 4th line ...

If you are trying to correct the permissions and ownership, you can use 'swverify' to do this!

# swverify -F \*

Regards!

...JRF...
Occasional Advisor
srnagu
Posts: 10
Registered: ‎03-21-2008
Message 8 of 24 (1,246 Views)

Re: sed command giving an error

Thx,
I was not knowing this.

Will this fix errors?
How can I fix these errors ?
Acclaimed Contributor
Dennis Handly
Posts: 25,190
Registered: ‎03-06-2006
Message 9 of 24 (1,246 Views)

Re: sed command giving an error

>I want to merge 1st and 2nd line, 3rd and 4th line

If you want to do this, use awk:
awk '
{
getline second
print $0, second
}' swagent.log

You can use sed but it's much harder to understand/remember:
sed -e 'N; s/\n/ /' swagent.log
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 10 of 24 (1,246 Views)

Re: sed command giving an error

Hi (again):

From the 'swverify(1M)' manpages:

"-F Runs vendor-specific fix scripts to correct and report problems on installed software. The fix script can create missind directories, correct file modifications (mode, owner, group, major, and minor), and recreate symbolic links."

Regards!

...JRF...
Acclaimed Contributor
Dennis Handly
Posts: 25,190
Registered: ‎03-06-2006
Message 11 of 24 (1,246 Views)

Re: sed command giving an error

>Will this fix errors?

The ones you listed, yes.
Occasional Advisor
srnagu
Posts: 10
Registered: ‎03-21-2008
Message 12 of 24 (1,246 Views)

Re: sed command giving an error

It gave some errors while executing.

Please refer attachment.

Which is that script file ?

If i change the permission of that script file alone manually will it fix error ?
Acclaimed Contributor
Dennis Handly
Posts: 25,190
Registered: ‎03-06-2006
Message 13 of 24 (1,246 Views)

Re: sed command giving an error

>It gave some errors while executing.

Of course it did. The same ones you got before. But it should have fixed them.

>Which is that script file?

You tell us. You would need to look at the swverify.log.

>If i change the permission of that script file alone manually will it fix error?

Without more details, we can't tell. You could try "swverify -F \*" a second time to see if it has already fixed the problems.
Occasional Advisor
srnagu
Posts: 10
Registered: ‎03-21-2008
Message 14 of 24 (1,246 Views)

Re: sed command giving an error

Hi,

I executed swverify -F\* again.
It did fix the errors which was there earlier.

But is there any way I can fix the ownership issue of other files like
/etc/..
/dev/..
/usr/..

I feel it has fixed only package/sw files errors, not system files
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 15 of 24 (1,246 Views)

Re: sed command giving an error

Hi (again):

> But is there any way I can fix the ownership issue of other files like
/etc/..
/dev/..
/usr/..

If you mean the permissions and ownership of these DIRECTORIES, then

# chmod 555 /etc /dev /usr
# chown bin:bin /etc /dev /usr

Regards!

...JRF...
Occasional Advisor
srnagu
Posts: 10
Registered: ‎03-21-2008
Message 16 of 24 (1,246 Views)

Re: sed command giving an error

I didnt mean the directories alone.

The files in those directories. For ex..

/etc/passwd, /etc/inittab, /var/adm/syslog/....
There are somany device files too with wrong ownership.

Is there any method I can find this ownership details from some other system and put the same in this server.

As you know doing one by one is near impossible.
Acclaimed Contributor
Dennis Handly
Posts: 25,190
Registered: ‎03-06-2006
Message 17 of 24 (1,246 Views)

Re: sed command giving an error

>I feel it has fixed only package/sw files errors, not system files

That's correct. It only fixes files recorded in the IPD. You'll have to correct those other files/directories.
You would need to look at another system for the correct values.
Occasional Advisor
srnagu
Posts: 10
Registered: ‎03-21-2008
Message 18 of 24 (1,246 Views)

Re: sed command giving an error

If I'm not wrong, the permission of each file will be different in any given directory.

how can I bring back those settings ?

Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 19 of 24 (1,246 Views)

Re: sed command giving an error

Hi (again):

> If I'm not wrong, the permission of each file will be different in any given directory.

True.

> how can I bring back those settings ?

You could the broken server directory contents to that of a known good one.

Regards!

...JRF...
Acclaimed Contributor
Dennis Handly
Posts: 25,190
Registered: ‎03-06-2006
Message 20 of 24 (1,246 Views)

Re: sed command giving an error

>how can I bring back those settings?

From your backup of course. ;-)

Otherwise you would have to compare with another system and either manually or with a script, fix them.

I suppose you could use swpackage on your good system to create a dummy product, then copy the IPD entries to your new system and then use swverify -F.

Of course this may be harder than writing a script from scratch. :-)
Occasional Advisor
srnagu
Posts: 10
Registered: ‎03-21-2008
Message 21 of 24 (1,246 Views)

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.
Acclaimed Contributor
Dennis Handly
Posts: 25,190
Registered: ‎03-06-2006
Message 22 of 24 (1,246 Views)

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
Acclaimed Contributor
Dennis Handly
Posts: 25,190
Registered: ‎03-06-2006
Message 23 of 24 (1,246 Views)

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
Occasional Advisor
srnagu
Posts: 10
Registered: ‎03-21-2008
Message 24 of 24 (1,246 Views)

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.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.