1

I need to get dimm info using ipmitool as follows:

exec("/usr/bin/ipmitool -I lan -H $spip -U root -P '$thepassword' sunoem cli 'show System/Memory/DIMMs/$a' | grep -i location", $dimm_loc, $ipmiretval);

$a is previously defined as: $a=$dimm[$i]

The return value for the above exec command is 1. If I replace $a with its vaule, i.e exec("/usr/bin/ipmitool -I lan -H $spip -U root -P '$thepassword' sunoem cli 'show System/Memory/DIMMs/D5' | grep -i location", $dimm_loc, $ipmiretval);

The exec command executes as expected. So it looks like $a cannot be used in the above example. How else can I pass the variable to the exec command?

Thanks!!

2 Answers 2

2

Run var_dump($a) and see what actualy it contains. Also dump the executed command as a string to see if command is formated properly.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Bartosz!!! Yes there was extra spaces at the beginning of the string that needed to be trimmed!!! Thanks a ton!!.
Remember, var_dump is your closest friend when it comes to debug something :)
1

One more tip. Instead of doing an exec("some very long command line"), put your command line in a variable, then both LOG and exec() the variable. For example:

$fmt="/usr/bin/ipmitool -I lan -H %s -U root -P '%s' sunoem cli 'show System/Memory/DIMMs/%s' | grep -i location";

$cmd=sprintf($fmt, $spip, $thepassword, $a);
exec($cmd, $dimm_loc, $ipmiretval);
syslog(LOG_DEBUG, "Running: $cmd");

if ($ipmiretval > 0) {
  syslog(LOG_ERR, "exec FAILED: $cmd");
} else {
  syslog(LOG_DEBUG, "exec: $cmd");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.