ak835
January 20, 2010, 9:09am
1
Guys
Look at the following string....!!
/global/site/vendor/Vignette7/Content/7_5/java5/jre/bin/java -classpath /global/site/vendor/Vignette7/Content/7_5/lib/vgnconfiglauncher.jar -Dcom.vignette.jvmid=V7CDS1CA1 -DVgnStartupClass=com.vignette.config.agent.Agent -DVgnClassPathFile=/global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1/conf/cfa.classpath -Xms32m -Xmx128m -Dcom.vignette.workingDir=/global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1 -Dcom.vignette.installDir=/global/site/vendor/Vignette7/Content/7_5 -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl -Dorg.apache.commons.logging.Log=com.vignette.logging.CommonsLogger com.vignette.config.launcher.vgnlauncher -c /global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1/conf/cfa.cfg -i /cs/config.cfa-V7CDS1CA1
From this huge string ,i just need
global/site/vendor/Vignette7/Content/7_5/java5/jre/bin/java
I have already tried ,but failed with
1.awk '{print $1}'
2.nawk '{print $1}'
3.nawk -F ' ' '{print $1}'
Any ideas/clues?
Regards
Abhi
Scott
January 20, 2010, 9:12am
2
Hi.
The first awk works fine. What error do you get (and what OS are you using)?
ak835
January 20, 2010, 9:14am
3
I am getting a time out error.
I am trying to do following on Solaris 5.10
CMD=<first huge string i pasted>
A=$(echo $CMD |nawk -F ' ' '{print $1}')
B=`dirname $A`
if [ $B = "." ]
then
echo ""
else
echo $B
fi
$
$ HUGE_STRING="/global/site/vendor/Vignette7/Content/7_5/java5/jre/bin/java -classpath /global/site/vendor/Vi
gnette7/Content/7_5/lib/vgnconfiglauncher.jar -Dcom.vignette.jvmid=V7CDS1CA1 -DVgnStartupClass=com.vignette.c
onfig.agent.Agent -DVgnClassPathFile=/global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1/conf/cfa.classpath -
Xms32m -Xmx128m -Dcom.vignette.workingDir=/global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1 -Dcom.vignette.
installDir=/global/site/vendor/Vignette7/Content/7_5 -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xe
rces.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFac
toryImpl -Dorg.apache.commons.logging.Log=com.vignette.logging.CommonsLogger com.vignette.config.launcher.vgn
launcher -c /global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1/conf/cfa.cfg -i /cs/config.cfa-V7CDS1CA1"
$
$
$ echo $HUGE_STRING | perl -lane '{print $F[0]}'
/global/site/vendor/Vignette7/Content/7_5/java5/jre/bin/java
$
$
tyler_durden
Scott
January 20, 2010, 9:36am
5
Hmm.
In Solaris 10, it works with nawk
# cat Test
CMD="/global/site/vendor/Vignette7/Content/7_5/java5/jre/bin/java -classpath /global/site/vendor/Vignette7/Content/7_5/lib/vgnconfiglauncher.jar -Dcom.vignette.jvmid=V7CDS1CA1 -DVgnStartupClass=com.vignette.config.agent.Agent -DVgnClassPathFile=/global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1/conf/cfa.classpath -Xms32m -Xmx128m -Dcom.vignette.workingDir=/global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1 -Dcom.vignette.installDir=/global/site/vendor/Vignette7/Content/7_5 -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl -Dorg.apache.commons.logging.Log=com.vignette.logging.CommonsLogger com.vignette.config.launcher.vgnlauncher -c /global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1/conf/cfa.cfg -i /cs/config.cfa-V7CDS1CA1"
A=$(echo $CMD | nawk '{print $1}')
B=`dirname $A`
if [ $B = "." ]
then
echo ""
else
echo $B
fi
# ./Test
/global/site/vendor/Vignette7/Content/7_5/java5/jre/bin
Is that the actual string you used? How long until this "time out"? Can you run the script, and post the output, including the error?
joeyg
January 20, 2010, 9:39am
6
After setting A, do an
echo $A
just to make sure that line is where the 'time-out' is occurring.
It would help isolate the problem because in theory anyway, that second command could be the culprit.
ak835
January 20, 2010, 11:04am
7
dodge this....!!
0 0 root 29040 1 0 59 20330440311536 30000c031dc S ? 919:55 /global/site/vendor/WAS/WebSphere7/AppServer/java/bin/java -XX:+UnlockDiagnosticVMOptions -Dwas.status.socket=47077 -XX:+UnsyncloadClass -XX:MaxPermSize=256m -Declipse.security -Dosgi.framework.extensions=com.ibm.ws.eclipse.adaptors -Dosgi.install.area=/global/site/vendor/WAS/WebSphere7/AppServer -Dosgi.configuration.area=/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/configuration -Djava.awt.headless=true -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.PollSelectorProvider -Xbootclasspath/p:/global/site/vendor/WAS/WebSphere7/AppServer/java/jre/lib/ext/ibmorb.jar:/global/site/vendor/WAS/WebSphere7/AppServer/java/jre/lib/ext/ibmext.jar -classpath /global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/properties:/global/site/vendor/WAS/WebSphere7/AppServer/properties:/global/site/vendor/WAS/WebSphere7/AppServer/lib/startup.jar:/global/site/vendor/WAS/WebSphere7/AppServer/lib/bootstrap.jar:/global/site/vendor/WAS/WebSphere7/AppServer/lib/jsf-nls.jar:/global/site/vendor/WAS/WebSphere7/AppServer/lib/lmproxy.jar:/global/site/vendor/WAS/WebSphere7/AppServer/lib/urlprotocols.jar:/global/site/vendor/WAS/WebSphere7/AppServer/deploytool/itp/batchboot.jar:/global/site/vendor/WAS/WebSphere7/AppServer/deploytool/itp/batch2.jar:/global/site/vendor/WAS/WebSphere7/AppServer/java/lib/tools.jar -Dibm.websphere.internalClassAccessMode=allow -Xms50m -Xmx256m -Dws.ext.dirs=/global/site/vendor/WAS/WebSphere7/AppServer/java/lib:/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/classes:/global/site/vendor/WAS/WebSphere7/AppServer/classes:/global/site/vendor/WAS/WebSphere7/AppServer/lib:/global/site/vendor/WAS/WebSphere7/AppServer/installedChannels:/global/site/vendor/WAS/WebSphere7/AppServer/lib/ext:/global/site/vendor/WAS/WebSphere7/AppServer/web/help:/global/site/vendor/WAS/WebSphere7/AppServer/deploytool/itp/plugins/com.ibm.etools.ejbdeploy/runtime -Dderby.system.home=/global/site/vendor/WAS/WebSphere7/AppServer/derby -Dcom.ibm.itp.location=/global/site/vendor/WAS/WebSphere7/AppServer/bin -Djava.util.logging.configureByServer=true -Duser.install.root=/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01 -Djavax.management.builder.initial=com.ibm.ws.management.PlatformMBeanServerBuilder -Dwas.install.root=/global/site/vendor/WAS/WebSphere7/AppServer -Dpython.cachedir=/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/temp/cachedir -Djava.util.logging.manager=com.ibm.ws.bootstrap.WsLogManager -Dserver.root=/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01 -Dcom.ibm.security.jgss.debug=off -Dcom.ibm.security.krb5.Krb5Debug=off -Djava.security.auth.login.config=/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/properties/wsjaas.conf -Djava.security.policy=/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/properties/server.policy com.ibm.wsspi.bootstrap.WSPreLauncher -nosplash -application com.ibm.ws.bootstrap.WSLauncher com.ibm.ws.runtime.WsServer /global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/config clmsd027JobMgrCell01 clmsd027JobMgr01 jobmgr
I have written code like this:
A=$(/usr/ucb/ps -alxww | nawk '$2 != "UID" { printf("%s %s ",$1,$2);system("getent passwd "$2"| sed s/:.*$// | tr -d \\\\n");$1=""; $2=""; print $0 }$2 == "UID" { $2="UID USER"; print }'|nawk -F' ' '{ if($4 == "29040"){substr("^ ","");print}}')
B=$(echo "$A" |nawk '{print substr($0,index($0,":")+3,length($0))}'|nawk -F ' ' '{print $1}')
C=$(dirname "$B")
if [ $C = "." ]
then
echo ""
else
echo $C
fi
no error...my engine simply got exhausted ...i am not sure if its bcoz of string size or i have written something wrong above [though it works fine now for the earlier huge string i had pasted ]
give me something which will give me first column ,irrespective of the string length,size etc....
help me out guys !!
Regards
Abhi
methyl
January 20, 2010, 11:44am
9
ak835. Judging from that last post, are you are trying to find out the full program path for PID 29040 only?
If so, part of the problem is that you are processing details for every process when "ps" can give you the details for one process.
I too wonder where the timeout comes from. Are you using a remote shell?
On the surface the simple way to deal with a long string is to put it in a file (rather than an environment variable) and then process it totally in a programming language.
alister
January 20, 2010, 12:42pm
10
set $CMD
Will place what you want in the positional parameter $1.
$ echo $CMD
/global/site/vendor/Vignette7/Content/7_5/java5/jre/bin/java -classpath /global/site/vendor/Vignette7/Content/7_5/lib/vgnconfiglauncher.jar -Dcom.vignette.jvmid=V7CDS1CA1 -DVgnStartupClass=com.vignette.config.agent.Agent -DVgnClassPathFile=/global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1/conf/cfa.classpath -Xms32m -Xmx128m -Dcom.vignette.workingDir=/global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1 -Dcom.vignette.installDir=/global/site/vendor/Vignette7/Content/7_5 -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl -Dorg.apache.commons.logging.Log=com.vignette.logging.CommonsLogger com.vignette.config.launcher.vgnlauncher -c /global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1/conf/cfa.cfg -i /cs/config.cfa-V7CDS1CA1
$ set $CMD
$ echo $1
/global/site/vendor/Vignette7/Content/7_5/java5/jre/bin/java
Regards,
Alister
$ cmd='/global/site/vendor/Vignette7/Content/7_5/java5/jre/bin/java -classpath /global/site/vendor/Vignette7/Content/7_5/lib/vgnconfiglauncher.jar -Dcom.vignette.jvmid=V7CDS1CA1 -DVgnStartupClass=com.vignette.config.agent.Agent -DVgnClassPathFile=/global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1/conf/cfa.classpath -Xms32m -Xmx128m -Dcom.vignette.workingDir=/global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1 -Dcom.vignette.installDir=/global/site/vendor/Vignette7/Content/7_5 -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl -Dorg.apache.commons.logging.Log=com.vignette.logging.CommonsLogger com.vignette.config.launcher.vgnlauncher -c /global/site/vendor/Vignette7/Content/7_5/V7CDS1CA1/conf/cfa.cfg -i /cs/config.cfa-V7CDS1CA1'
$ echo ${cmd%% *}
/global/site/vendor/Vignette7/Content/7_5/java5/jre/bin/java
Scott
January 20, 2010, 3:56pm
12
Hi.
These are all good solutions, but let's not forget the "dirname" part of the original question
Hello ,
In perl I would accomplish this,
perl -wlna -e 'print $F[0]'
Regards,
rk4k
January 20, 2010, 10:37pm
14
why not ?
cut -f1 -d' ' | cut -f2-40 -d'/'
just increase 40 if the dirname have so many char. :D:D
ak835
January 21, 2010, 8:13am
15
thanks for all these wonderful responses...!!
here is what i see working for me...
A=$(/usr/ucb/ps -alxww | nawk '$2 != "UID" { printf("%s %s ",$1,$2);system("getent passwd "$2"| sed s/:.*$// | tr -d \\\\n");$1=""; $2=""; print $0 }$2 == "UID" { $2="UID USER"; print }'|nawk -F' ' '{ if($4 == "@@Host Processes.PID@@"){substr("^ ","");print}}')
CMDP=$(echo "$A" |nawk '{print substr($0,index($0,":")+3,length($0))}')
set $CMDP
C=$(echo $1)
D=`dirname $C`
if [ $D = "." ]
then
echo ""
else
echo $D
fi
Scrutinizer:
When i saw what you wrote ,i felt that should work for me but a strange thing happens..look below
bash-3.00$ A=$(/usr/ucb/ps -alxww | nawk '$2 != "UID" { printf("%s %s ",$1,$2);system("getent passwd "$2"| sed s/:.*$// | tr -d \\\\n");$1=""; $2=""; print $0 }$2 == "UID" { $2="UID USER"; print }'|nawk -F' ' '{ if($4 == "29040"){substr("^ ","");print}}')
bash-3.00$ CMDP=$(echo "$A" |nawk '{print substr($0,index($0,":")+3,length($0))}')
bash-3.00$ echo $CMDP
/global/site/vendor/WAS/WebSphere7/AppServer/java/bin/java -XX:+UnlockDiagnosticVMOptions -Dwas.status.socket=47077 -XX:+UnsyncloadClass -XX:MaxPermSize=256m -Declipse.security -Dosgi.framework.extensions=com.ibm.ws.eclipse.adaptors -Dosgi.install.area=/global/site/vendor/WAS/WebSphere7/AppServer -Dosgi.configuration.area=/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/configuration -Djava.awt.headless=true -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.PollSelectorProvider -Xbootclasspath/p:/global/site/vendor/WAS/WebSphere7/AppServer/java/jre/lib/ext/ibmorb.jar:/global/site/vendor/WAS/WebSphere7/AppServer/java/jre/lib/ext/ibmext.jar -classpath /global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/properties:/global/site/vendor/WAS/WebSphere7/AppServer/properties:/global/site/vendor/WAS/WebSphere7/AppServer/lib/startup.jar:/global/site/vendor/WAS/WebSphere7/AppServer/lib/bootstrap.jar:/global/site/vendor/WAS/WebSphere7/AppServer/lib/jsf-nls.jar:/global/site/vendor/WAS/WebSphere7/AppServer/lib/lmproxy.jar:/global/site/vendor/WAS/WebSphere7/AppServer/lib/urlprotocols.jar:/global/site/vendor/WAS/WebSphere7/AppServer/deploytool/itp/batchboot.jar:/global/site/vendor/WAS/WebSphere7/AppServer/deploytool/itp/batch2.jar:/global/site/vendor/WAS/WebSphere7/AppServer/java/lib/tools.jar -Dibm.websphere.internalClassAccessMode=allow -Xms50m -Xmx256m -Dws.ext.dirs=/global/site/vendor/WAS/WebSphere7/AppServer/java/lib:/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/classes:/global/site/vendor/WAS/WebSphere7/AppServer/classes:/global/site/vendor/WAS/WebSphere7/AppServer/lib:/global/site/vendor/WAS/WebSphere7/AppServer/installedChannels:/global/site/vendor/WAS/WebSphere7/AppServer/lib/ext:/global/site/vendor/WAS/WebSphere7/AppServer/web/help:/global/site/vendor/WAS/WebSphere7/AppServer/deploytool/itp/plugins/com.ibm.etools.ejbdeploy/runtime -Dderby.system.home=/global/site/vendor/WAS/WebSphere7/AppServer/derby -Dcom.ibm.itp.location=/global/site/vendor/WAS/WebSphere7/AppServer/bin -Djava.util.logging.configureByServer=true -Duser.install.root=/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01 -Djavax.management.builder.initial=com.ibm.ws.management.PlatformMBeanServerBuilder -Dwas.install.root=/global/site/vendor/WAS/WebSphere7/AppServer -Dpython.cachedir=/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/temp/cachedir -Djava.util.logging.manager=com.ibm.ws.bootstrap.WsLogManager -Dserver.root=/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01 -Dcom.ibm.security.jgss.debug=off -Dcom.ibm.security.krb5.Krb5Debug=off -Djava.security.auth.login.config=/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/properties/wsjaas.conf -Djava.security.policy=/global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/properties/server.policy com.ibm.wsspi.bootstrap.WSPreLauncher -nosplash -application com.ibm.ws.bootstrap.WSLauncher com.ibm.ws.runtime.WsServer /global/site/vendor/WAS/WebSphere7/AppServer/profiles/JobMgr01/config clmsd027JobMgrCell01 clmsd027JobMgr01 jobmgr
bash-3.00$ echo ${CMDP%% *}
It did not work out of code line.If i set it manually on command prompt ,then it works.
Thanks anyway !!
Perl is out of question,thanks for the suggestions though !!
I am still testing it and will keep posted .
Regards
Abhi
SSSB
January 21, 2010, 1:21pm
16
CMD="/global/site/............/cs/config.cfa-V7CDS1CA1"
newCMD=$(echo $CMD | awk -F/bin '{print $1}')
o/p
echo $newCMD
/global/site/vendor/Vignette7/Content/7_5/java5/jre