MOON
Server: Apache
System: Linux vps.erhabenn.com.br 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User: sonne (1011)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //opt/microsoft/omsconfig/Scripts/calcPythonPath.sh
#!/bin/bash

if [ "$#" -ne 0 ]
then
	# Checking which python version is available 
	# python3
	if [[ -z $(python2 --version 2>&1 | grep 'not found') ]]
	then
		#echo "python exists"; 
		pythonVer="python2"
	elif [[ -z $(python3 --version 2>&1 | grep 'not found') ]]
	then
		#echo "python3 exists"; 
		pythonVer="python3"
	else 
		echo "'python2' or 'python3' not found on this machine. Please install python."
		exit 1
	fi

	# Detemine file location
	echo "You provided the following argument(s): $@"
	if [ "$pythonVer" == "python2" ] 
	then
		filePath="/opt/microsoft/omsconfig/Scripts/"
	else
		filePath="/opt/microsoft/omsconfig/Scripts/python3/"
	fi

	# Construct command from arguments
	for args in "$@"; do
		filePath+=$args
		filePath+=" "
	done
	echo "The path provided is: "
	echo $(ls $filePath)
	
	# Construct command
	echo "sudo su omsagent -c '$pythonVer $filePath'"
	sudo su omsagent -c "$pythonVer $filePath"
else
	echo "No parameters were passed."
fi