Converting the Shell Script to Bigfix Action Script

(imported topic written by VipulSri)

Hello,

I am trying to convert my Shell script to Bigfix action script using the tool from
http://bigfix.me/content/shelltoaction

It doesn’t work as the output fails, however if I push my shell script choosing the “sh” option under Action Script tab it works fine.

I am able to push the information properly but to get it as an action script would be better so that it can be shared with everyone.

Shell Script:

#!/bin/bash
rm /var/opt/BESClient/__BESData/"BES Inventory and License"/__HardwareInfo/inventory.txt
rm /var/opt/BESClient/__BESData/"BES Inventory and License"/__HardwareInfo/application.txt
#OS Serial Number       (Prior to getting this information, you need to have "sneep" installed on the Solaris Endpoint)
echo "SerialNumber:`sneep`" >> /var/opt/BESClient/__BESData/"BES Inventory and License"/__HardwareInfo/inventory.txt
#Processor Core Count
echo "Processor_Core_Count:`kstat -m cpu_info|grep -w core_id|uniq|wc -l`" >> /var/opt/BESClient/__BESData/"BES Inventory and License"/__HardwareInfo/inventory.txt
#Number of Physical Processor(s)
echo "Number_of_Physical_Processor(s):`psrinfo -p`" >> /var/opt/BESClient/__BESData/"BES Inventory and License"/__HardwareInfo/inventory.txt
#Number of Virtual Processor(s)
echo "Number_of_Virtual_Processor(s):`psrinfo|wc -l`" >> /var/opt/BESClient/__BESData/"BES Inventory and License"/__HardwareInfo/inventory.txt
#Processor Total Count
virtual=`psrinfo|wc -l`
physical=`psrinfo -p`
echo "Processor_Total_Count:$(( $virtual + $physical ))" >> /var/opt/BESClient/__BESData/"BES Inventory and License"/__HardwareInfo/inventory.txt
#Owner * (Last Logon)
echo "last_loggedon_user:`last | head -1 | awk '{ print $1 }'`" >> /var/opt/BESClient/__BESData/"BES Inventory and License"/__HardwareInfo/inventory.txt
#HDD Total Count
echo "HDD_Total_Count:`format </dev/null | grep -c '[0-100]\.'`" >> /var/opt/BESClient/__BESData/"BES Inventory and License"/__HardwareInfo/inventory.txt
#Application
pkginfo -l | /usr/xpg4/bin/grep -e 'NAME' -e 'VENDOR' -e 'VERSION' >> /var/opt/BESClient/__BESData/"BES Inventory and License"/__HardwareInfo/application.txt
#Physical / Virtual
prtdiag -v | grep -i "System Configuration" | egrep -i '(VMware)|(Virtual)'
if [[ $? -eq 0 ]]
then
echo "Virtual/Physical:virtual machine" >> /var/opt/BESClient/__BESData/"BES Inventory and License"/__HardwareInfo/inventory.txt
else
echo "Virtual/Physical:physical machine" >> /var/opt/BESClient/__BESData/"BES Inventory and License"/__HardwareInfo/inventory.txt
fi

Any help?

Thanks

Vipul

(imported comment written by mickyt)

I would just use the createfile option as follows:

// My actionscript

delete __createfile

createfile until end

{insert your script here}

end

move __createfile myshellscript.sh

waithidden myshellscript.sh

Just in case your not aware most of what your doing in your script can be accomplished with many of the analysis from the BES Inventory & License site provided your licensed for that. Just saying. Hope this helps.

Cheers,

Michael

(imported comment written by VipulSri)

Thanks Michael. your script looks good but I was looking for to get my shell script modified in a way that the original “Hardware Probe - Solaris” (Fixlet) is done. It seems that the default script convertor needs some tweaking to work properly or maybe I am using it incorrectly.

I too avoid a lot of customization in the environment as the default features from IEM are amazing, however the client I am working with is very demanding and so ended up doing this customization.

Thanks

Vipul

(imported comment written by GarrethJeremiah)

just remeber to replace the “{” with “{{” in your awk statement, to avoid IEM thinking you are inserting relevance statements.

(imported comment written by VipulSri)

Hello Garreth,

I tried replacing the symbol in the awk statement and the good thing is that it was failing in my earlier tries however since this change it is not failing in the awk statement line but now failing in the very next one.

Please suggest.

Thanks

Vipul

(imported comment written by GarrethJeremiah)

delete __createfile

createfile until __THEEND

#!/bin/bash

rm -f “/var/opt/BESClient/__BESData/BES Inventory and License/__HardwareInfo/inventory.txt”

rm -f “/var/opt/BESClient/__BESData/BES Inventory and License/__HardwareInfo/application.txt”

#OS Serial Number (Prior to getting this information, you need to have “sneep” installed on the Solaris Endpoint)

{if exists file “insert path to sneep” then “echo %22SerialNumber:sneep%22 >> %22/var/opt/BESClient/__BESData/BES Inventory and License/__HardwareInfo/inventory.txt%22” else “Error: sneep not installed”}

#Processor Core Count

echo “Processor_Core_Count:kstat -m cpu_info|grep -w core_id|uniq|wc -l” >> “/var/opt/BESClient/__BESData/BES Inventory and License/__HardwareInfo/inventory.txt”

#Number of Physical Processor(s)

echo “Number_of_Physical_Processor(s):psrinfo -p” >> “/var/opt/BESClient/__BESData/BES Inventory and License/__HardwareInfo/inventory.txt”

#Number of Virtual Processor(s)

echo “Number_of_Virtual_Processor(s):psrinfo|wc -l” >> “/var/opt/BESClient/__BESData/BES Inventory and License/__HardwareInfo/inventory.txt”

#Processor Total Count

virtual=psrinfo|wc -l

physical=psrinfo -p

echo “Processor_Total_Count:$(( $virtual + $physical ))” >>"/var/opt/BESClient/__BESData/BES Inventory and License/__HardwareInfo/inventory.txt"

#Owner * (Last Logon)

echo “last_loggedon_user:last | head -1 | awk '{{ print $1 }'” >>"/var/opt/BESClient/__BESData/BES Inventory and License/__HardwareInfo/inventory.txt"

#HDD Total Count

echo “HDD_Total_Count:format </dev/null | grep -c '[0-100]\.'” >>"/var/opt/BESClient/__BESData/BES Inventory and License/__HardwareInfo/inventory.txt"

#Application

pkginfo -l | /usr/xpg4/bin/grep -e ‘NAME’ -e ‘VENDOR’ -e ‘VERSION’ >> “/var/opt/BESClient/__BESData/BES Inventory and License/__HardwareInfo/application.txt”

#Physical / Virtual

prtdiag -v | grep -i “System Configuration” | egrep -i ‘(VMware)|(Virtual)’

if [[ $? -eq 0 ]]

then

echo “Virtual/Physical:virtual machine” >>"/var/opt/BESClient/__BESData/BES Inventory and License/__HardwareInfo/inventory.txt"

else

echo “Virtual/Physical:physical machine” >>"/var/opt/BESClient/__BESData/BES Inventory and License/__HardwareInfo/inventory.txt"

fi

__THEEND

(imported comment written by VipulSri)

Thanks for the quick responses guys. The script I am using is working fine when I run it as a shell script however when I try to use the convertor or manually modify the script to run as a Bigfix Action script then it fails.

//Shell to Action Script Conversion Utility

delete __appendfile

appendfile rm /var/opt/BESClient/__BESData/“BES Inventory and License”/__HardwareInfo/inventory.txt

appendfile rm /var/opt/BESClient/__BESData/“BES Inventory and License”/__HardwareInfo/application.txt

//Processor Type

appendfile echo “Processor_Type:uname -p” >> /var/opt/BESClient/__BESData/“BES Inventory and License”/__HardwareInfo/inventory.txt

//Total Physical Memory

appendfile cat /proc/meminfo | grep MemTotal >> /var/opt/BESClient/__BESData/“BES Inventory and License”/__HardwareInfo/inventory.txt

//Owner * (Last Logon)

appendfile echo “last_loggedon_user:last | head -1 | awk '{{ print $1 }'” >> /var/opt/BESClient/__BESData/“BES Inventory and License”/__HardwareInfo/inventory.txt

//Application

appendfile rpm -qa --queryformat ‘Name:%{NAME}\nVersion:%{VERSION}-%{RELEASE}\nVendor:%{VENDOR}\n’ >> /var/opt/BESClient/__BESData/“BES Inventory and License”/__HardwareInfo/application.txt

//modify appendfile to allow execution

wait chmod 555 "{(client folder of current site as string) & “/__appendfile”}

//execute shell script as written

wait “{(client folder of current site as string) & “/__appendfile”}”

Please help me with correcting this script which is the output of the convertor.

Thanks

Vipul

(imported comment written by VipulSri)

Finally i got it working.

//Shell to Action Script Conversion Utility

delete __appendfile

appendfile rm /var/opt/BESClient/__BESData/“BES Inventory and License”/__HardwareInfo/inventory.txt

appendfile rm /var/opt/BESClient/__BESData/“BES Inventory and License”/__HardwareInfo/application.txt

//Processor Type

appendfile echo “Processor_Type:uname -p” >> /var/opt/BESClient/__BESData/“BES Inventory and License”/__HardwareInfo/inventory.txt

//Total Physical Memory

appendfile cat /proc/meminfo | grep MemTotal >> /var/opt/BESClient/__BESData/“BES Inventory and License”/__HardwareInfo/inventory.txt

//Owner * (Last Logon)

appendfile echo “last_loggedon_user:last | head -1 | awk '{{ print $1 }'” >> /var/opt/BESClient/__BESData/“BES Inventory and License”/__HardwareInfo/inventory.txt

//Application

appendfile rpm -qa --queryformat ‘Name:%{{NAME}\nVersion:%{{VERSION}-%{{RELEASE}\nVendor:%{{VENDOR}\n’ >> /var/opt/BESClient/__BESData/“BES Inventory and License”/__HardwareInfo/application.txt

//modify appendfile to allow execution

delete inventory.sh

copy __appendfile inventory.sh

wait chmod 555 inventory.sh

wait bash inventory.sh

Thanks Garreth for the trick for converting { to {{.

Cheers!!!

Vipul

(imported comment written by Darknight)

Hi All,

i have prepared a shell script and executing it on hp-ux endpoint through task:

#!/sbin/sh
mkdir -p "/var/opt/BESClient/__BESData/actionsite/__HardwareInfo/"
rm /var/opt/BESClient/__BESData/actionsite/__HardwareInfo/inventory.txt
echo "Machine Serial Number:`getconf MACHINE_SERIAL`" >> /var/opt/BESClient/__BESData/actionsite/__HardwareInfo/inventory.txt
echo "CPU_CHIP_TYPE:`getconf CPU_CHIP_TYPE`" >> /var/opt/BESClient/__BESData/actionsite/__HardwareInfo/inventory.txt
echo "CPU VERSION:`getconf CPU_VERSION`" >> /var/opt/BESClient/__BESData/actionsite/__HardwareInfo/inventory.txt
echo "HW_CPU_SUPP_BITS:`getconf HW_CPU_SUPP_BITS`" >> /var/opt/BESClient/__BESData/actionsite/__HardwareInfo/inventory.txt
echo "logical processor:`print_manifest | perl -nle '/(\d+) logical processors/&&($x=$1);END{print "$x"}'`" >> /var/opt/BESClient/__BESData/actionsite/__HardwareInfo/inventory.txt
echo "cores:`print_manifest | awk '/([[:digit:]]+[[:space:]])(core|cores)([[:space:]]+$|$|,)/{gsub(/,/,x);print $1}'| tail -1`" >> /var/opt/BESClient/__BESData/actionsite/__HardwareInfo/inventory.txt

if i run the script manually on server its giving below output which is expected out of it :

cat /var/opt/BESClient/__BESData/actionsite/__HardwareInfo/inventory.txt

Machine Serial Number:VM01328001

CPU_CHIP_TYPE:553649156

CPU VERSION:768

HW_CPU_SUPP_BITS:64

logical processor:16

cores:1

but whenever i try to include this script in task and run it as shell script it provides output as below :

cat /var/opt/BESClient/__BESData/actionsite/__HardwareInfo/inventory.txt

Machine Serial Number:VM01328001

CPU_CHIP_TYPE:553649156

CPU VERSION:768

HW_CPU_SUPP_BITS:64

logical processor:
cores:

Can someone help me in understanding why this is happening . Do i have to make any changes in my script and then run it via IEM.