On 02.10, Davis, Kevin wrote:
... However, running a script (sh or bash, makes no difference in this case), I get this when it runs. It actually doesn't matter what ONTAP command I send, they all give the same "Vserver name: Invalid." error (the /bin/ssh​ lines are just echo statements in the script so I can see that it's building and sending the right command line):
If you want to see what command is actually being sent, use ssh with "-v". E.g. it will then log something like "debug1: Sending command: ..."
/bin/ssh admin@foo 'snapshot create -vserver foo3 -volume Foo04 -snapshot 20231003-foo -expiry-time 11/02/2023 00:00:00' Last login time: 10/2/2023 12:46:39
Error: Vserver name: Invalid. The Vserver name must begin with a letter or an underscore. Maximum supported length: 41 if Vserver is type "sync-source", 47 otherwise.
Be careful with those single quotes in a script, nothing within those will be substituted e.g. $SVM_NAME will remain literally "$SVM_NAME".
If you pass a SVM name begining with "$" to ONTAP you may well get the error above ...
Try changing your script to do something simple first e.g. run a single word command such as "version". Does that work?
The script is so simple it's embarrassing. Define a few variables and optargs, build 3 simple SSH commands to send to the toaster, and run them. Everything up until these commands reach the toaster is working as expected. It just breaks when it gets there.
If your script is so simple, you should show it.
By way of example, here's one I wrote as a test: [root@agrajag ~]# cat toast #!/bin/sh -
# Goal: # [root@agrajag ~]# ssh admin@192.168.8.10 'snapshot show -vserver stowa-02 -volume vol0 -snapshot nightly.0'
USER="admin" SSHOPTS="-xT" ONTAPOPTS="set diag" FILER="192.168.8.10" SVM="stowa-02" CMD="$ONTAPOPTS ; snapshot show -vserver $SVM -volume vol0 -snapshot nightly.0"
ssh $SSHOPTS $USER@$FILER $CMD
The ONTAP command line is built up by adding variables to "$CMD".
That works for me here (via ssh from UNIX to an ONTAP 9.7 simulator) Of course in reality there should be more error checking and parsing ...
Alternatively, use Ansible ;-)
Cheers, Robb.