As we don’t provide support with custom scripts, I’m unable to help you out here.
However, I have a guess that it may not be working due to the fact that SMS messages may have troubles running the script. Instead, I suggest creating a script file within your device, editing it, inputting these commands, and then running the script file itself via a command instead of the commands themselves.
Please also double-check whether these commands are working properly by running them manually in the SSH.