1828667 Members
2099 Online
109984 Solutions
New Discussion

script quries

 
yc_2
Regular Advisor

script quries

Hi,

When I run a script, I got the following using ps -ef | grep <script>:

cis_opr 11610 1 0 08:35:30 ? 0:00 /bin/ksh ./<script>

Can the script be run so that ps -ef | grep <script> will get the following (ie without /bin/ksh>

cis_opr 11610 1 0 08:35:30 ? 0:00 ./ezproxy



Thanks in advance.
7 REPLIES 7
Matthew_50
Valued Contributor

Re: script quries

you have to use awk to parse the output,
for example,

ps -ef | grep <script>|awk '{print $1,$2,$3,$4,$5,$6,$7,$9}'
Patrick Wallek
Honored Contributor

Re: script quries

How are you running the script?

Are you running it like:

$ ksh ./scriptname

or do you have #!/usr/bin/ksh as the first line of the script?
yc_2
Regular Advisor

Re: script quries

Hi Patrick Wallek,

When the script was executed, it consists of the following:
#!/usr/bin/ksh

I cotook out the #!/usr/bin/ksh and ran:

#ksh ./<script>

The result of ps -ef | grep <script> is the same.
MarkSyder
Honored Contributor

Re: script quries

If you are running ksh script, that suggests the script is not an executable.

Try:

chmod +x script (or chmod 744 if you only want the owner to be able to execute the script)
./script

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Vibhor Kumar Agarwal
Esteemed Contributor

Re: script quries

I think the problem is that the script that you are running has some syntaxes specific to ksh.

That's why you have to use either of the 2 things: ksh or #/usr/bin/ksh

and this may be the reason why its showing in ps -ef.

Check what is your default shell, try changing it and then running.
Vibhor Kumar Agarwal
Ralph Grothe
Honored Contributor

Re: script quries

I'm afraid, I think you will have to parse the output from ps yourself.
It's true that if you run a script in the process table as cmd appears the interpreter (i.e. in your case /bin/ksh).
Because I haven't your process running I used a running Perl script of mine as an example for how such parsing could look like.
As you may recognise I stripped off the 2nd field from the right side which holds the interpreter.
I used Perl for parsing but you could as well use any combination of awk, grep, sed, cut, tr ...

$ UNIX95= ps -fC arschd|perl -anle 'if($.>1){$F[-2]=undef;print "@F" }'
saz 4288 1 0 Jun 26 ? 00:01 /usr/local/sbin/arschd


I have to admid, because with ps output you have varying fields, that it would be better to use Perl's pack() function for this purpose.
But I thought this would be too distracting.
Madness, thy name is system administration
Stuart Browne
Honored Contributor

Re: script quries

An expansion on Mark Syder's answer.

Yes, make the script file it's self executable (chmod), but also make sure that the first line of the script is something similar to:

#!/bin/ksh

This will tell the OS that when you run the script directly (i.e. ./ezproxy), it will use the interpreter '/bin/ksh' to run it in.

Go #! magic ;)
One long-haired git at your service...