First thought is change the extension to
.sh. Should be able to run as
Second, if it's missing the
#!/bin/sh at the top of the file, it won't work then either.
Third, if you wind up having
sudo commands intermixed with commands that don't require
sudo, you can
echo <sudo_password> | command.
In this case, best practice (from an automation/QA perspective) is to run your command as
./FTL.sh <sudo_password> and capture the password to use later in the script for each command that will prompt for sudo password.
PW=$1 #sets first parameter
# non-sudo commands
echo $PW | command`
It's also not a bad idea to throw in a
yes | when your command asks if you want to continue for any reason. Then you can modify the above to
echo $PW | yes | command
I also typically capture all output during testing, which can be accomplished by appending
|& tee path/to/logfile.log to the end of any command, if you want to watch it progress in the console, or switch the
|& tee to
&> if it has a long run time or otherwise don't want to monitor progress.
if echo $PW | yes | command |& tee path/to/logfile.log; then
if sed -Fq "Validation Passed" path/to/logfile.log; then
echo "PASS: returned 'Validation Pass'"
else echo "FAIL: test did not return 'Validation Pass'"
else echo "Test Failed"
Just a quickie on the sed command,
-F allows you to specify the file name (instead of searching a process output) and
-q runs sed quietly and exits after it finishes searching the file/process. See sed documentation for more info.