First off: what a mess! My suggestion is to standardise these app versions first: create a directory for every version and put respective version plus its config file there. Something like this:
To have a path like /tool is already questionable but to put an application there and its config into /opt is a sure-fire recipe for disaster. It may be a lot of work but you should clean that up as soon as possible.
If you have one config for several versions create one (maybe somewhere else) and use symbolic links like Neo suggested to represent them at the respective directory. Something like:
I need result export in text file not rename directory.
------ Post updated at 06:56 AM ------
I can't change location of files because they are running and I can't kill them.
I want to export result in text file , and don't want to create symbolic link or rename directory.
Please be more specific: got the following error, got the following output instead of the following expected one.
--
I have corrected an error in my prev post.
Now with little modification it work perfectly! Thank you
but have two question:
1-is it possible to set name for head columns?
2-in each config file wrote state, it it possible to show those state in new column like this:
You can process a config file like this, put in a function:
readconfig(){
# set state, hostname, ip
while IFS=" =" read confkey confval
do
case $confkey in
([Ss]tate) state=$confval;;
([Hh]ostname) hostname=$confval;;
([Ii]p) ip=$confval;;
esac
done
}
You have given my script proposal that certainly needs some adaption.
YOUR version would be more helpful.
But maybe you can help yourself with the following information.
Once you have defined the readconfig function in your script, and once you have the pathname of a config file in a variable, say config , then you can call the function like this
readconfig <$config
and then you have set the variables state , hostname , ip that you can echo out as $state , $hostname , $ip .
I try below code, but give me this error : ./script.sh: line 14: -bind /home/config: No such file or directory.
I think it is related to output of this command "ps -eo args",
"-bind /home/config"
consider "-bind" as argument, if I able to define only address of config file problem will be fix but i have no idea how can I extract only address of config file and suppress "-bind" !
#!/bin/sh
cnt=0
ps -eo args |
while read prog args
do
type=""
case $prog in
(*app);;
(*)
continue;;
esac
ver=$("$prog" -version </dev/null)
readconfig < $args
readconfig(){
# set state, hostname, ip
while IFS=" =" read confkey confval
do
case $confkey in
([Ss]tate) state=$confval;;
([Hh]ostname) host=$confval;;
([Ii]p) ip=$confval;;
esac
done
}
echo $confkey $confval $state $hostname $ip