LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-28-2018, 11:28 AM   #1
Sleepinfire
LQ Newbie
 
Registered: Aug 2018
Posts: 9

Rep: Reputation: Disabled
Question 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

Last edited by Sleepinfire; 08-28-2018 at 11:37 AM. Reason: Adding error info
 
Old 08-28-2018, 01:32 PM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,242
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
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"
 
Old 08-28-2018, 01:43 PM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 12,893
Blog Entries: 9

Rep: Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518
Quote:
Originally Posted by Sleepinfire View Post
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"
is this the script?
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:
bash: -c: line 1: syntax error: unexpected end of file
yes, this usually means you mistyped something, forgot a ';' or a 'fi' or a bracket or a quote or sth.
 
Old 08-28-2018, 08:07 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,191

Rep: Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039
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
 
Old 08-29-2018, 12:59 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 12,893
Blog Entries: 9

Rep: Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518Reputation: 3518
Quote:
Originally Posted by ondoho View Post
yes, this usually means you mistyped something, forgot a ';' or a 'fi' or a bracket or a quote or sth.
and according to what jlinkels wrote, the error is on line 1 because you wrote your whole script on one line... not very helpful.
https://startpage.com/do/dsearch?que...bash+scripting
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] error message in training program, line22: syntax error near unexpected token 'done' Mark_S Linux - Newbie 13 07-21-2015 07:23 PM
rsync error: syntax or usage error (code 1) at main.c(1490) [receiver=3.0.6] boby.kumar Linux - Newbie 4 11-22-2013 05:58 AM
script.pl with sed shell calls: sh error syntax error near unexpected token `(' MMaddoxx Programming 7 11-24-2011 09:00 AM
[python] syntax Error : invalid syntax Python_user Programming 2 09-06-2009 01:52 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 07:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration