Convert Bash Shell Script to Action Script

Am trying to make this bash shell script into an action script. The syntax is correct except bigfix error on the line starting with “serial=”

delete __createfile

createfile until end

#!/bin/bash

base="L6-"
serial=/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Serial\ Number\ \(system\)/ {print $NF}'
/usr/sbin/scutil --set ComputerName “${base}${serial}”
/usr/sbin/scutil --set LocalHostName “${base}${serial}”
/usr/sbin/scutil --set HostName “${base}${serial}”

end

move __createfile myshellscript.sh

wait /bin/sh myshellscript.sh

Since your shell script contains curly braces ( { } ), you’ll have to escape them to avoid actionscript trying to perform relevance substitution. Please see https://www-01.ibm.com/support/docview.wss?uid=swg21506259 for more information.

Hi Aram

I will probably need some help with where to insert escaping “”. My best judgment would be where the line serial starts.

base=“L6-”
“serial=/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk ‘/Serial\ Number\ (system)/ {print $NF}’”
/usr/sbin/scutil --set ComputerName “${base}${serial}”
/usr/sbin/scutil --set LocalHostName “${base}${serial}”
/usr/sbin/scutil --set HostName “${base}${serial}”

It’s the curly braces that must be escaped. And in this case, that means adding an additional curly brace to the open curly brace:

delete __createfile

createfile until end
#!/bin/bash

base="L6-"
serial=/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Serial\ Number\ \(system\)/ {{print $NF}'
/usr/sbin/scutil --set ComputerName "${{base}${{serial}"
/usr/sbin/scutil --set LocalHostName "${{base}${{serial}"
/usr/sbin/scutil --set HostName "${{base}${{serial}"
end

move __createfile myshellscript.sh

wait /bin/sh myshellscript.sh

Another approach besides escaping the curly braces would be to upload the script to the BigFix server and then use the download actionscript command to retrieve it. Uploading the script can be easily done with the REST Api and a tool like Postman.

This method works best if the script will not need to be changed on a regular basis though. It also makes reviewing the content of the script more difficult but certainly solves the problem of escaping braces. A similar problem exists with PowerShell scripts.

Have you thought about just using the sh type instead of action script?

3 Likes