Syntax error
This will probably be an easy one for yall... Let me explain a what I'm trying to accomplish and hopefully I'm going about it the right way.
I am working with VMware vSphere 6.0 and some virtual machines and datastores. I am wanting to do a VM level backup of the servers in the environment. To do this, I have created a Centos 7 VM as my backup server. This VM will SSH into each ESXi host and backup each VM. First it will create a snapshot of the vm, then SCP the files from one datastore to another. Then run stat against the two .vmdk files and indicate a success or failure based off the file size. Then it will remove the snapshot. For logging I have it running under the script command which is being saved on the VM, (I haven't gotten this far-->) and then I'd like it to send an email indicating success or failure SSH is setup for the secure automated login, I'm brand new at scripting and have been googling my way through this, so if anybody can help educate me here I'd greatly appreciate it. Thanks! script -q -c "ssh -t 192.168.0.203 vim-cmd vmsvc/snapshot.create 3 Backup$(date); scp -rp /vmfs/volumes/59d7ffef-31c1a41d-9591-9c8e99197ca8/testbk /vmfs/volumes/5b59d89d-a083d558-a0dc-842b2b6b0464/; if stat -c%s /vmfs/volumes/59d7ffef-31c1a41d-9591-9c8e99197ca8/testbk/testbk.vmdk = stat -c%s /vmfs/volumes/5b59d89d-a083d558-a0dc-842b2b6b0464/testbk/testbk.vmdk; then echo "Backup Success!" else echo"Backup Failure!"fi; vim-cmd vmsvc/snapshot.remove 20" > /scp/logs/testbk"$(date).log" When I execute the script no output occurs on the prompt. When I view the log file it saves it says: bash: -c: line 1: syntax error: unexpected end of file |
I think the problem is you are using double quotes all throughout. I would switch all internal quotes from double to singles and have the only double quote at the beginning and end.
It should look something like this: "start 'something here' 'something else here' end" |
Quote:
are you sure you want to use the "script" command here? do you know what it does? executing a script is not the same as executing a command called "script". see "man script". Quote:
|
One of the first lessons in scripting: make your code readable to yourself. Next, if the code seems correct, and it still doesn't work, then post the code, well formatted and in tags so it is readable to others. The "#" in the formatting bar. We try to help with Linux problems, not do code formatting for you.
jlinkels |
Quote:
https://startpage.com/do/dsearch?que...bash+scripting |
All times are GMT -5. The time now is 12:58 AM. |