Version checking


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Version checking
# 22  
Old 09-07-2018
Ps and args return correct value , but function (readconfig) does not return correct value!
Any idea?
# 23  
Old 09-07-2018
Quote:
Originally Posted by indeed_1
Ps and args return correct value , but function (readconfig) does not return correct value!
Any idea?
not without enabling set -x INSIDE the function and seeing what's going on.

Last edited by vgersh99; 09-07-2018 at 02:18 PM..
# 24  
Old 09-07-2018
Quote:
Originally Posted by indeed_1
Ps and args return correct value , but function (readconfig) does not return correct value!
Any idea?
First off: you do not provide your source code but only tiny (and may insignificant) morsels of it. You do not provide any output of the script but tell us only the absolute minimum of symptoms like "doesn't work" or "doesn't print". How are we supposed to debug your script on only rudimentary second-hand information?

And speaking about debugging: how about sitting down and put some debug statements into your code? At least you could show the same amount of effort you want to show us helping you in helping yourself!

Regarding your problem: i suppose the variables inside readvar() are local to that function and therefore the values are not usable outside of it. A shell function will not "return" anything else than a return code (an unsigned short short it).

I hope this helps.

bakunin
# 25  
Old 09-07-2018
Dear Bakunin,
You right
Here is the more detail , when I use “set -x” in “readconfig” function in code:
Code:
#!/bin/sh
cnt=0
ps -eo args |
while read prog TMP args
do
type=""
  case $prog in
  (*app);;
  (*)
    continue;;
  esac
  ver=$("$prog" -version  </dev/null)


readconfig(){ set -x
  # set state, hostname, ip
while IFS=" =" read confkey confval
  do
    case $confkey in
    ([Ss]tate) FIRST_STATE=$confval;;
    ([Hh]ostname) HOST_NAME=$confval;;
    ([Ii]p) FIRST_IP=$confval;;
    esac
  done

}
readconfig < $args
echo "$hostname $state $ip"

done

Here is my config file content:
Code:
FIRST_IP 192.168.10.10
FIRST_STATE 1010
HOST_NAME rhel

Here is output of script after run with set -x in “readconfig” function.
Code:
+ IFS=' ='
+ read confkey confval
+ case $confkey in
+ IFS=' ='
+ read confkey confval
+ case $confkey in
+ IFS=' ='
+ read confkey confval
+ case $confkey in


Last edited by indeed_1; 09-07-2018 at 06:18 PM..
# 26  
Old 09-11-2018
The purpose of a function is:
it is defined once, and can be used multiple times.
In other words, the function definition should be once, before the loop, NOT in the loop.
Move it to the beginning of your script!
Code:
#!/bin/sh
readconfig(){
...
}
cnt=0
ps -eo args |
while read prog TMP args
do
  ...
  readconfig < $args
  ...
done

In the loop you call the function.
# 27  
Old 09-12-2018
still print nothing , here is the code:
Code:
#!/bin/sh
readconfig(){ set -x

while IFS=" " read confkey confval;
  do
    case $confkey in
    ([Ss]tate) FIRST_STATE=$confval;;
    ([Hh]ostname) HOST_NAME=$confval;;
    ([Ii]p) FIRST_IP=$confval;;
    esac
  done
}

cnt=0
ps -eo args |
while read prog TMP args
do
type=""
  case $prog in
  (*app);;
  (*)
  readconfig < $args
    continue;;
  esac
  ver=$("$prog" -version  </dev/null )
echo "$confval $confkey $state"
done

Here is the content of config file:
Code:
FIRST_IP 192.168.10.10
FIRST_STATE 1010
HOST_NAME rhel

here is the debug result of function (set -x):
Code:
+ IFS=
+ read confkey confval
+ case $confkey in
+ IFS=
+ read confkey confval
+ case $confkey in
+ IFS=
+ read confkey confval
+ echo '  '

# 28  
Old 09-12-2018
can you provide a sample output of ps -eo args which would satisfy your code conditions.
This User Gave Thanks to vgersh99 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

OS version and Firmware version

Guys, How to find OS version and firmware version in LINUX? Like in AIX. uname -a will show me the version 5.3, 6.1,7.1. lsmcode -c will show me - system firmware image as SF240_417. What are the similar commands in Linux. I checked uname -a and cat /etc/release. uname... (1 Reply)
Discussion started by: ElizabethPJ
1 Replies

2. AIX

Checking xlc compiler version

Hi, Below is output of lslpp command. bash-3.00# lslpp -L | grep xlC xlC.aix50.rte 11.1.0.1 C F XL C/C++ Runtime for AIX 5.3 xlC.cpp 9.0.0.0 C F C for AIX Preprocessor xlC.msg.en_US.cpp 9.0.0.0 C F C for AIX... (2 Replies)
Discussion started by: manoj.solaris
2 Replies

3. Shell Programming and Scripting

Copy a file from directroy/ prior version to the directory/ new version

How to copy a file from directroy/ prior version to the directory/ new version automatically. (4 Replies)
Discussion started by: roy1912
4 Replies

4. SCO

Stop boot system at "Checking protected password and checking subsystem databases"

Hi, (i'm sorry for my english) I'm a problem on boot sco unix 5.0.5 open server. this stop at "Checking protected password and checking subsystem databases" (See this image ) I'm try this: 1) http://www.digipedia.pl/usenet/thread/50/37093/#post37094 2) SCO: SCO Unix - Server hangs... (9 Replies)
Discussion started by: buji
9 Replies

5. UNIX for Advanced & Expert Users

Advanced Search * View * Edit JAVA version to WORK in GLASSFISH Forum topic JAVA version

Would like to confirm the ff. I got confused actually with the version I needed to download that will work on glassfish 3.0.1 a. Debian Squeeze (HP DL360). Need to use java version6 On Debian, I did apt-get install sun-java6-jdk. So when I check it's java version "1.6.0_22" Java(TM) SE... (1 Reply)
Discussion started by: lhareigh890
1 Replies

6. Solaris

Migrate unix version 8 to version 9

i have a program writing in PRO C which currently running in unix version 8 tie with oracle 8i, but in the future company gonna migrate this OS to version 9. Anything i have to prepare for my PRO C program to run in unix version 9? or anything would that impact my program couldn't run well? what... (2 Replies)
Discussion started by: lsy
2 Replies

7. AIX

checking the version revisions of a java file inside the ear using KSHELL in AIX.

consider on day1, in PVCS repository we have java files like a.java,b.java with version revision 1.0, through ANT build script we have compiled and created an ear,named c.ear in AIX build server.we have transfered this ear from build server to portal server through FTP using KSHELL. consider... (0 Replies)
Discussion started by: kareemaashik
0 Replies

8. UNIX for Dummies Questions & Answers

checking for non-zero value

I have a process that spits out a file called sqlplus.out, here is what the result looks like: Currently the value you see is zero, what I need to do is perform an action if that value is non-zero, so how do I check that value in an if statement? If it helps at this moment in development the... (6 Replies)
Discussion started by: philplasma
6 Replies

9. UNIX Desktop Questions & Answers

checking of GNU C Complier version

Hi, How do i check the GNU C Complier my system is running? thanks jennifer (2 Replies)
Discussion started by: jennifer
2 Replies
Login or Register to Ask a Question