Operating System - HP-UX
1847696 Members
5960 Online
110265 Solutions
New Discussion

Re: Scrambled file - even with String

 
Sailesh_1
Advisor

Scrambled file - even with String

Hi there,

I have non-text file and wants to convert to a text file with control charecters removed.
when I try "string " it gives me the output as again non-text file.this is happening from all the users ID's when login directlty from a telnet session. however when i do a "su" with "-" to some other login ID, the string command works fine! (I mean i get a proper output with control charecters removed.)

any clues? what's the diiference, when I login directly from a telnet session and trying a "su -" from another user session?

any help is highly appreciated.

Thanks guys!
Sailesh
12 REPLIES 12
Siddhartha M
Frequent Advisor

Re: Scrambled file - even with String

Hi

When you invoke "su" with the "-" handle, the the user's environment settings are executed.

For eg:

# su - user1
would execute the /etc/profile and then the
initialization files that exist in user1's home directory.

Regarding your mopping up of the control characters try the following:

# dos2ux

See the man page for more info.




yogesh_4
Regular Advisor

Re: Scrambled file - even with String

When you use "su" with the "-" sign the the user's environment settings are getting executed.
Also for removiing control characters from the file use "dos2ux filename". This file name is output file name.This command which will remove "^M " or any other control character from that file

Sailesh_1
Advisor

Re: Scrambled file - even with String

Thanks guys! for u'r reply.

you all are right. but in my case, even if i use the same user(login user) as the su - user, it works fine! i.e,

for example,

say I have logged in the system as user "sailesh". then i try to string the file and i get a scrambled file. so i do a
"su - sailesh" and try string again and it works perfect.

so my question is what exactly are the difference doing a login and doing a su - ?
as far as my undersatnding, both executes exactly the same initialization files..right?
but my case shows it wrong..

Secondly, I can't use dos2ux utility.
this is because, my file is a binary file with few text in it. i dont not know how this works in my case.

expecting more ideas...

Thanks,
Sailesh
Sailesh_1
Advisor

Re: Scrambled file - even with String

Yes guys...

dos2ux utility doesnot work on this file..I have just tested...
Siddhartha M
Frequent Advisor

Re: Scrambled file - even with String

Hi

As a workaround you could dos2ux your string'ed binary file
In other words:

# strings binaryfile > file1
# dos2ux file1

alternatively

# strings binaryfile > file1
# sed 's/^M//g' file1 > file2
steven Burgess_2
Honored Contributor

Re: Scrambled file - even with String

Hi Sailesh

You could try and convert the file using dd

dd if=file conv=ascii bs=10 of=outputfile

If the - option is specified, the new shell starts up as if the new user had initiated a new login session. Therefore there is no difference between an initial telnet session and su - username

What happens if you try

su - username -c 'cat filename'

HTH

Steve


take your time and think things through
Sailesh_1
Advisor

Re: Scrambled file - even with String

Hi Steve,

The dd command did not work out..it gave me a much "dangearous" output..:)

however, su cmmand worked with replacing the cat with strings.

i.e, su - username -c 'strings file'

though i need to provide passowrd. i have to find a way to use this in the scripts till i have a solution..things are geeting complex..:)

let me know if you have any more ideas..

Thanks much,
Sailesh
steven Burgess_2
Honored Contributor

Re: Scrambled file - even with String

Hi Sailesh

Can you post the first couple of lines of the file with the strings and without the strings, or even attach the file to the thread ?

Thanks

Steve
take your time and think things through
Sailesh_1
Advisor

Re: Scrambled file - even with String

Hi Steve,

Thanks for the Intrest shown..

Attaching the sample file from cat,strings, strings after su -, and dd


I beleive there is some env parameter influencing my shell by direct login and is over coming after su -

so there could be some difference between direct logging in and su -

scratching my head..:)

Thanks,
Sailesh
Siddhartha M
Frequent Advisor

Re: Scrambled file - even with String

Hi (again)
Can you try a diff of your env files after telnet and su?

ie

telnet
after login in,

# env > /tmp/env.telnet
# su - user
# env > /tmp/env.su

# diff /tmp/env.telnet /tmp/env.su

This will bring out the differences ( if any )
in your environment settings in both the situations

You could also take a look at the following thread where a similar issue is discussed:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x0fb2d5fab40ed6118ff40090279cd0f9,00.html


Bill Hassell
Honored Contributor

Re: Scrambled file - even with String

Are you really using telnet or using a terminal window from CDE? The terminal windows in CDE (or VUE) bypass all the standard Unix login procedures (no profiles are run) which IMHO is a terrible default and might explain the difference between su - and the login you are seeing.

In either case, you need to make sure you are running the 'real' strings command and not some hacker's copy left in a bad PATH list. Try this when logging in as an ordinary user:

/usr/bin/strings FileName

If that works, then you have a bad PATH and you can see where the strings command is located with the type command as in:

type strings

If it is not /usr/bin, then PATH is not right and this can be very dangerous as security may have been compromised. When a user logs in, the contgents of /etc/profile followed by .profile are executed. To verify this, add an echo command to both files to identify when that file is run. If a login does NOT produce the echo commands, something is wrong with the login setup and needs to be fixed.

And if strings shows up in some unsecure directory (like /usr/local/bin in a default HP-UX system), I would suspect a hacker is on the loose in your system, or at least someone with Unix skills that should not have access to the system. Also make sure that the PATH for all users is secure. PATH is set in /etc/profile from the file /etc/PATH. Make these tests on each entry in /etc/PATH:

- does the directory exist?
- is the directory not writable by a group or the world?
- is the directory really a directory?
- is the parent directory not writable by the world?
- are there no duplicated directories?
- is the directory real or a symbolic link?

Each of the above represents a problem that should be addressed in the /etc/PATH file.




Bill Hassell, sysadmin
rachel_11
Advisor

Re: Scrambled file - even with String

Hello Sailesh,

The issue of non printable characters can be solved by a very simple program, for example:
main()
{
char ltr;
while ((ltr=getchar()) >0 )
{
if((ltr == 10) || (ltr == 13)) { putchar(ltr); continue;}
if(ltr >= 32) putchar(ltr);
}
}

run it:
program < filein > fileout

It will delete all control characters but leave
cr & lf

regards,
Rachel