Hello All,
I’m trying to run the below action script on an Ubuntu machine to find and delete the folder and unset the environment variable by creating a script using “createfile until EOF1” condition in the action script. Everything is working fine as mentioned in fixlet, and I am getting exit code 0, but whatever is written on the script is not working as expected, like not capturing the environment variable and not deleting the folder or unsetting the environment variable. through fixlet…
Just to update, the same script if I run manually on a Ubuntu machine is working perfectly and removing all mentioned folders and unsetting variables with both sudo bash and source commands from the terminal.
I’m requesting to check and help me if I’m missing anything.
Action script:
createfile until Eof1
#! /bin/bash
#Find and delete the SPARK home directory
folder_name=$(printenv "SPARK_HOME") ** this is not capturing the variable of SPARK_HOME but same command is working fine when running manually ***
if [ -d "$folder_name" ]; then
sudo rm -rf "$folder_name"
echo " Folder deleted succussfully"
else
echo "Folder does not exit"
fi
#Remove entry from .bashrc file
if [ -f ~/.bashrc ]; then
if grep -q "export SPARK_HOME" ~/.bashrc; then
sed -i 'export SPARK_HOME/d' ~/.bashrc
echo "Spark entry removed"
else
echo "spark entry does not exist"
fi
#unset entry from PATH and variable
unset SPARK_HOME
export PATH=$(echo $PATH | sed -e 's/:\/opt\/spark\/bin//g')
echo "Spark entry removed"
source ~/.bashrc
Eof1
delete __Download/script.sh
move __createfile /var/opt/BESClient/__Download/script.sh
wait chmod +x /var/opt/BESClient/__Download/script.sh
wait /var/opt/BESClient/__Download/script.sh
===========================================================
Note:
I have tried execute this script with below commands none of it worked.
- wait /bin/bash -c /var/opt/BESClient/__Download/script.sh
- wait /bin/bash -c “source /var/opt/BESClient/__Download/script.sh”
- wait /bin/sh -c /var/opt/BESClient/__Download/script.sh
Also, I have tried creating a sh script directly on the fixlet, but still, it’s not working.