Hello Guys
/usr/local/sbin/sshd
I need to spilt such a line like this
Path to be set as :/usr/local/sbin
Command to be set as : sshd
What combination should i use?
Regards
Abhi
Hello Guys
/usr/local/sbin/sshd
I need to spilt such a line like this
Path to be set as :/usr/local/sbin
Command to be set as : sshd
What combination should i use?
Regards
Abhi
simple,
basename /usr/local/sbin/sshd
dirname /usr/local/sbin/sshd
For the above said output, command is
echo "Path to be set as: `basename /usr/local/sbin/sshd`"
echo "Command to be set as : `dirname /usr/local/sbin/sshd`"
oh yes...!!
i had forgotten these two commands....thanks !!
now lets try something else...
we have something like this:
/usr/sbin/rsct/bin/rmcd -a IBM.LPCommands -r
i need to spilt this as :
path:/usr/sbin/rsct/bin/
command:rmcd
arguments:-a IBM.LPCommands -r
i guess `dirname` would work but how about basename?
its interesting to see how to get those arguments as well...
Regards
Abhi
There is no need to use external commands.
path=/usr/local/sbin/sshd
echo ${path##*/}
echo ${path%/*}
How I do it, Don't know how correct it is though. Thoughts???
cmdline='/usr/sbin/rsct/bin/rmcd -a IBM.LPCommands -r'
path=${cmdline%/*} # Path
tmp=${cmdline##*/} # Filename & Arguments
fname=${tmp%% *} # Filename - Wish it could be nested... :) fname=${${cmdline##*/}%% *}
args=${tmp#${fname} *} # Arguments
echo ${path} # Path
echo ${fname} # Filename
echo ${args} # Arguments
-Enjoy
fh : )_~
Thanks Festus !!
/var/itlm/wasagent/jre/bin/java -classpath properties:lib/admin.jar:lib/bootstrap.jar:lib/classloader.jar:lib/ecutils.jar:lib/emf.jar:lib/ffdc.jar:lib/idl.jar:lib/iwsorb.jar:lib/j2ee.jar:lib/mail-impl.jar:lib/management.jar:lib/naming.jar:lib/namingclient.jar:lib/ras.jar:lib/runtime.jar:lib/sas.jar:lib/security.jar:lib/soap.jar:lib/tmx4jc.jar:lib/tx.jar:lib/utils.jar:lib/wasjmx.jar:lib/wasproduct.jar:lib/wlmclient.jar:lib/wsexception.jar:lib/wssec.jar:wasagent.jar:resources.jar:jlog.jar:jffdc.jar:tivolicommondir.jar:ITLMToolkit.jar -Djlog.propertyFileDir=/var/itlm/wasagent -Ditlm.agent.dir=/var/itlm -Dcom.ibm.SOAP.ConfigURL=file:/var/itlm/wasagent/properties/soap.client.props -Djava.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory -Ditlm.config.dir=/etc -Ditlm.agent.pid=98796 com.ibm.it.rome.wasagent.WASAgent
Any idea how can such a long string can be handled?
Basically i m facing problem with these huge string? How do i get arguments out of it?
Regards
Abhi
Read the parameter expansion section of your shell's man page, and look at the examples already given. They contain the techniques you need.
str=/usr/local/sbin/sshd
path=${str%/*}
cmd=${str##*/}
echo $path" <--> "$cmd
Thanks Guys !!
but i need help in capturing that whole string and the commands you guys have mentioned are working fine but before i use them i need that complete string stored in a variable.
How do i capture all of below in a variable ?
"/var/itlm/wasagent/jre/bin/java -classpath properties:lib/admin.jar:lib/bootstrap.jar:lib/classloader.jar:lib/ecutils.jar:lib/emf.jar:lib/ffdc.jar:lib/idl.jar:lib/iwsorb.jar:lib/j2ee.jar:lib/mail-impl.jar:lib/management.jar:lib/naming.jar:lib/namingclient.jar:lib/ras.jar:lib/runtime.jar:lib/sas.jar:lib/security.jar:lib/soap.jar:lib/tmx4jc.jar:lib/tx.jar:lib/utils.jar:lib/wasjmx.jar:lib/wasproduct.jar:lib/wlmclient.jar:lib/wsexception.jar:lib/wssec.jar:wasagent.jar:resources.jar:jlog.jar:jffdc.jar:tivolicommondir.jar:ITLMToolkit.jar -Djlog.propertyFileDir=/var/itlm/wasagent -Ditlm.agent.dir=/var/itlm -Dcom.ibm.SOAP.ConfigURL=file:/var/itlm/wasagent/properties/soap.client.props -Djava.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory -Ditlm.config.dir=/etc -Ditlm.agent.pid=98796 com.ibm.it.rome.wasagent"
Help Appreciated !! i am pressed for time !!
Regards
Abhi
Use command substitution:
var=$( your_command )
The output of your_command will be stored in ${var}.
I am not having these strings ready.
I would be getting them on runtime and need to capture then.
e.g
ps -ef |grep java
would display all java threads ,where command column would be such a string.
I need to get that in a variable and then i can use the commands posted here.
I am not sure if 'sed' needs to be used here.
Regards
Abhi
Why do you need sed?
var=$( ps -ef |grep java )
Or if you just need one field:
var=$( ps -efo comm |grep java )
With due respect,i think you have not understood my query.
'ps -ef|grep java' was just an example.
The command i am running all the time is
COLUMNS=2047 /usr/bin/ps -eo pid,ppid,uid,user,args
Whenever this command runs,whatever processes are up and running would be shown.The 5th column is 'args' column which could be any string.
for e.g
/sbin/startpar -f -- /etc/init.d/rc3.d/S19named-internal
My query is :
How do i get all of this string in a variable?
Pls note that i need script code to do this.I am not assigning this string to a variable on a command prompt for some R&D purpose.
Regards
Abhi
Do you have a command that will get you that line?
If so, put that command inside command substitution syntax:
var=$( whatever_the_command_is_goes_here )
The output of whatever_the_command_is_goes_here will be stored in ${var}.
thats precisely what i am asking....
the command/ set of commands to capture that string?
In case you have an AIX box,run following command
COLUMNS=2047 /usr/bin/ps -eo pid,ppid,uid,user,args
You'll see five-column o/p ,of which 5th column will have strings ,separated by whitespaces.
Select one row where 5th column would be a such a huge string.Now assume you are iterating over its PID(1st column value) meaning you know this value and need to iterate over this to get that 5th column and whatever is there in that column ,assign it to a variable.
How would ya do it?
Regards
Abhi
Why don't you paste the output of that command over here ?
Not everyone over here has an AIX box (an example being myself).
Which value ? 5th column or 1st column ?
Does "this" mean the "1st column" ?
Why would one need to iterate over the "1st column" ?
Again, what's "that column" ? - 5th column ? or (gasp!) 1st column ?
tyler_durden
puff!!
i thought ppl here are smart enough to understand things....!! sheer disappointment !!
one last attempt to explain what i need:
here it is
bash-3.00$ COLUMNS=2047 /usr/bin/ps -eo pid,ppid,uid,user,args
238062 1 0 root /opt/CA/SharedComponents/ca_lic/lic98fds
242070 131238 0 root /var/itlm/wasagent/jre/bin/java -classpath properties:lib/admin.jar:lib/bootstrap.jar:lib/classloader.jar:lib/ecutils.jar:lib/emf.jar:lib/ffdc.jar:lib/idl.jar:lib/iwsorb.jar:lib/j2ee.jar:lib/mail-impl.jar:lib/management.jar:lib/naming.jar:lib/namingclient.jar:lib/ras.jar:lib/runtime.jar:lib/sas.jar:lib/security.jar:lib/soap.jar:lib/tmx4jc.jar:lib/tx.jar:lib/utils.jar:lib/wasjmx.jar:lib/wasproduct.jar:lib/wlmclient.jar:lib/wsexception.jar:lib/wssec.jar:wasagent.jar:resources.jar:jlog.jar:jffdc.jar:tivolicommondir.jar:ITLMToolkit.jar -Djlog.propertyFileDir=/var/itlm/wasagent -Ditlm.agent.dir=/var/itlm -Dcom.ibm.SOAP.ConfigURL=file:/var/itlm/wasagent/properties/soap.client.props -Djava.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory -Ditlm.config.dir=/etc -Ditlm.agent.pid=131238 com.ibm.it.rome.wasagent.WASAgent
246220 299054 0 root db2ckpwd 0
now we see PID column,we have that value.Take that value and write something that it would look for the 5th column (command)...and irrespective of how long this string (command) is ,assign it to a variable.
e.g PID=242070,ARGS string is needed in a variable so that i can spilt it into three parts.(Command Name,Command Path,Command Arguments)
Regards
Abhi
---------- Post updated at 06:03 PM ---------- Previous update was at 04:00 PM ----------
PID @@Host Processes .PID@@
COLUMNS=2047 ps -eo pid,ppid,uid,user,args|awk -F' ' '{ if($1 == @@Host Processes.PID@@) print $5 }'
If i punch "242070" in place of @@Host Processes.PID@@,then what i get is
/var/itlm/wasagent/jre/bin/java
I need that whole string.
Does this help?
Regards
Abhi
---------- Post updated at 06:06 PM ---------- Previous update was at 06:03 PM ----------
oops !! i again spoke in riddle.....didn't i ?!!
I need that whole string.
that whole string is:
/var/itlm/wasagent/jre/bin/java -classpath properties:lib/admin.jar:lib/bootstrap.jar:lib/classloader.jar:lib/ecutils.jar:lib/emf.jar:lib/ffdc.jar:lib/idl.jar:lib/iwsorb.jar:lib/j2ee.jar:lib/mail-impl.jar:lib/management.jar:lib/naming.jar:lib/namingclient.jar:lib/ras.jar:lib/runtime.jar:lib/sas.jar:lib/security.jar:lib/soap.jar:lib/tmx4jc.jar:lib/tx.jar:lib/utils.jar:lib/wasjmx.jar:lib/wasproduct.jar:lib/wlmclient.jar:lib/wsexception.jar:lib/wssec.jar:wasagent.jar:resources.jar:jlog.jar:jffdc.jar:tivolicommondir.jar:ITLMToolkit.jar -Djlog.propertyFileDir=/var/itlm/wasagent -Ditlm.agent.dir=/var/itlm -Dcom.ibm.SOAP.ConfigURL=file:/var/itlm/wasagent/properties/soap.client.props -Djava.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory -Ditlm.config.dir=/etc -Ditlm.agent.pid=131238 com.ibm.it.rome.wasagent.WASAgent
try something like this :
awk .............{ for(i=5;i<=NF;i++) print $i } ' .. instead of "print $5"
One way:
COLUMNS=2047 /usr/bin/ps -eo pid,ppid,uid,user,args |
awk '/java/{$1=$2=$3=$4="";sub("^ ","");print}'
Regards
Thanks panyam ..!!
that for loop works ..just that it eats up whitespaces !!
Thanks Franklin52 !!
awk with sub worked well in AIX and Linux... had to use 'substr' in solaris...!!
Watch out my threads in near future... i have got some nasty request to be done with !!
Thank you everyone !!
Regards
Abhi