Output.txt file for Exit Code is not working

Hi,

I am using below script to Extend Logical volume size in linux machine and script is doing the same but i am facing another issue with the exit code in output.txt.

error.txt file is getting created but output.txt is not getting created hence i am not able to get exit code 100, kindly help me to resolve this issue.

//   Write Parameter Here
action parameter query "Error_Folder" with description "Please enter the Error Folder path and name where you will get error output of this Fixlet" with default value ""
action parameter query "Volume_Group" with description "Please enter the Volume Group name which should already exists" with default value ""
action parameter query "Logical_Volume" with description "Please enter the Logical Volume name Whose Size You Want To Extend" with default value ""


//   Relevance and Action Script To Check Existence Of Folder And To Create Folder
if {not exists folder "Error_Folder"}
run mkdir -p {parameter "Error_Folder"}

endif


delete __createfile

createfile until EOF_EOF1

#!/bin/bash

#variables set for filesystem

output_folder="{parameter "Error_Folder"}"
VG="{parameter "Volume_Group"}"
LV="{parameter "Logical_Volume"}"

echo "Pls enter three variables in front of script volume group , logical volume" > $output_folder/error.txt

# checking volume group exists
echo "First check if volume group exists: $VG" >> $output_folder/error.txt

vgs $VG > /dev/null

if [ $? != 0 ]
then
echo "Volume Group : $VG  not found , we can't create partition and have to exit the script with the exit code 200" >> $output_folder/error.txt
echo "exit 200" >> $output_folder/error.txt
exit 200

else
	vgs $VG >> $output_folder/error.txt
	echo $? >> $output_folder/output.txt

	echo "Volume Group : $VG Found , now proceed ahead" >> $output_folder/error.txt
    
	
	########checking logical volume exists ##########################################

	echo "now check if logical volume exists:$LV" >> $output_folder/error.txt
	
	lvs /dev/$VG/$LV  &> /dev/null
	

	if [ $? != 0 ]
	then
	echo $? >> $output_folder/output.txt
	echo "Logical VOlume : $LV  not found , we can't extend the size and have to exit the script with the exit code 300" >> $output_folder/error.txt
	echo "exit 300" >> $output_folder/error.txt
	exit 300

	else
	
	lvs /dev/$VG/$LV  &>> $output_folder/error.txt
	echo $? >> $output_folder/output.txt
	
	echo "Logical volume : $LV is exists so extending the size" >> $output_folder/error.txt

	####Extend logical volume as per the requirement########

	echo "Now extending Logical Volume : $LV......" >> $output_folder/error.txt

	size=`vgdisplay  $VG |grep Free | cut -d"/" -f3 |  cut -d"<" -f2 |cut -d. -f1`

	echo "size variable is : $size" >> $output_folder/error.txt
	
		if [ "$size" -gt 1 ]
		then
		echo $? >> $output_folder/output.txt
	    echo "size is ok" >> $output_folder/error.txt
        
		lvextend -L +1G /dev/$VG/$LV >> $output_folder/error.txt
		
			if [ $? != 0 ]
			then
			echo $? >> $output_folder/output.txt
			echo "New size given (256 extents) not larger than existing size (374 extents), we can't extend the size and have to exit the script with the exit code 400" >> $output_folder/error.txt
			else 
			lvs /dev/$VG/$LV  &>> $output_folder/error.txt
			fi
		else
		echo $?  >> $output_folder>/output.txt
		echo " size : $size is less then the desire space" >> $output_folder/error.txt
		echo "exit 400" >> $output_folder/error.txt
		exit 400
		fi

fi

fi

EOF_EOF1


delete lvm_extend.sh
move __createfile lvm_extend.sh
wait /bin/sh "lvm_extend.sh"


if{exists file "output.txt" whose (exists line whose (it > "0") of it) of folders (parameter "Error_Folder")}
Exit 100
endif

I have seen in recent past days this type of question being asked so many times, I am posting similar post (one is from you as well) if you can get something from there -

1 Like