Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
ias_gc-dk
Contributor
Jump to solution

ifconfig output differs from manual execution to script execution

Hello

I run a script every day on our VSX platform clusters with extracts a number of metrics for reporting about usage for each of our customers.

I wanted to expand the script to get the interface-values to make sure our documentation are up to date, but when I include this command to the bash-script:

ifconfig | grep -A1 Ethernet | grep -v '\-\-' | paste -sd ' \n' | awk '{ print $1","$7","$9 }' | awk -v vsname=$VS_NAME -F '[,:]' '{ print vsname","$1","$3"/"$5 }' >> /var/tmp/$Ldate-cp_facts_vs_interfaces_output-$1.txt

I get a different output, than if I run the command manually. The output in the script match what the \ifconfig puts out.

Example output:

Running command manually on a vs:

vs-customer1,bond1.3237,10.50.237.240/255.255.255.0
vs-customer1,bond3.1349,47.29.2.60/255.255.255.248
vs-customer1,wrp384,200.83.4.25/255.255.255.0

Running command in script on a vs:

vs-customer1,bond1.3237,100.127.48.1/255.255.255.240
vs-customer1,bond3.1349,100.127.48.17/255.255.255.240
vs-customer1,wrp384,100.127.48.33/255.255.255.240

Do I need to set a parameter in the script for ifconfig to give me the correct output, like with using specific checkpoint commands in scripts: source /etc/profile.d/CP.sh; ?

0 Kudos
1 Solution

Accepted Solutions
Bob_Zimmerman
Authority
Authority

On VSX in interactive shells, 'ifconfig' is intercepted by the alias you saw above, which returns false results based on the cluster VIPs. Real 'ifconfig'—which your headless script is using—returns the real data.

To get the fake data via your script, you can source /etc/profile.d/CP.sh, then call /bin/cp-ifconfig.sh instead of ifconfig.

View solution in original post

(1)
8 Replies
PhoneBoy
Admin
Admin

I suspect you’re ultimately referencing a different ifconfig in your script: 
Use the command “which ifconfig” to see the precise location of the ifconfig binary you use on the CLI.
Use that in your script to ensure you are calling the same ifconfig binary.

ias_gc-dk
Contributor

Running which in the command gives this:

# which ifconfig
alias ifconfig='/bin/cp-ifconfig.sh'
/bin/cp-ifconfig.sh

So its a CP-script. So perhaps I need the source /etc/profile.d/CP.sh;  in my script after all.

0 Kudos
JozkoMrkvicka
Mentor
Mentor

use "/sbin/ifconfig" in the script.

Kind regards,
Jozko Mrkvicka
0 Kudos
ias_gc-dk
Contributor

Nope, that gives the undesired result.

0 Kudos
Alex-
Advisor
Advisor

Try adding source /etc/profile.d/vsenv.sh to your script.

0 Kudos
ias_gc-dk
Contributor

Nope, doesn't work either.

its source /etc/profile.d/CP.sh, then call /bin/cp-ifconfig.sh instead of ifconfig as Bob_Zimmerman describes.

0 Kudos
Bob_Zimmerman
Authority
Authority

On VSX in interactive shells, 'ifconfig' is intercepted by the alias you saw above, which returns false results based on the cluster VIPs. Real 'ifconfig'—which your headless script is using—returns the real data.

To get the fake data via your script, you can source /etc/profile.d/CP.sh, then call /bin/cp-ifconfig.sh instead of ifconfig.

(1)
ias_gc-dk
Contributor

This worked! Thanks!

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events