LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 11-17-2014, 03:06 PM   #1
dorlack
Member
 
Registered: Oct 2009
Location: Cambridge MA
Distribution: Any Linux
Posts: 122

Rep: Reputation: 2
Bash Help


Hey friends,

I have a little bash script here and I am not sure what I am missing. It fails on line 14.

line 14: syntax error near unexpected token `done'
line 14: `done'


Here is my short script I would like to run:

Code:
USR="root"
mkdir="mkdir /mnt/folder
mount=”nfsserver1:/exports/mountme”
mountpoint=”/data/mountpoint”

for host in rsc6cn{1..154}
do
echo “=====================================”
ssh $USR@$host “hostname -a && mkdir $dir && mount $mount $mountpoint”
echo “=====================================”
done


I look forward to finding out what I did wrong. I am trying to better my scripting skills.
 
Old 11-17-2014, 03:19 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Well, $dir doesn't seem to be defined (possibly you meant the "mkdir=..." line to be "dir=...")

But your error is actually on line 2 - you are missing a closing quote.
 
1 members found this post helpful.
Old 11-17-2014, 03:30 PM   #3
dorlack
Member
 
Registered: Oct 2009
Location: Cambridge MA
Distribution: Any Linux
Posts: 122

Original Poster
Rep: Reputation: 2
The quotes was a typo on my end when pasting. Also I am aware that I do not have the server and mount points defined. Those will be changed every time the scrip is run. To lesson confusion here is the live script.

# NAME TEXT
# Instruction Text
# Instruction Text
USR="root"
mkdir="mkdir /mnt/ERA01"
mount=”itmgt1:/media/ERAI01”
mountpoint=”/mnt/ERAI01”

for host in wtc6cn{1..10}
do
echo “=====================================”
ssh $USR@$host “hostname -a && if [ -d /dir ]; then mount -t nfs $mount $mointpoint; else mkdir /dir && mount -t nfs $mount $mointpoint; fi”
echo “=====================================”
done

Last edited by dorlack; 11-17-2014 at 03:40 PM.
 
Old 11-17-2014, 03:34 PM   #4
dorlack
Member
 
Registered: Oct 2009
Location: Cambridge MA
Distribution: Any Linux
Posts: 122

Original Poster
Rep: Reputation: 2
So the scripts job is:
check if the directory is created
if not mkdir /mnt/newdir
mount
finish
 
Old 11-17-2014, 03:40 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
well, your script doesn't create /mnt/newdir... it always creates /dir, which is not referenced anywhere in the script.

And there is still an error - mount -t nfs $mount $mointpoint; fi”... hm. I'll guess this is supposed to be part of the preceding line.

You would do better to put code blocks around the script.
 
1 members found this post helpful.
Old 11-17-2014, 03:51 PM   #6
dorlack
Member
 
Registered: Oct 2009
Location: Cambridge MA
Distribution: Any Linux
Posts: 122

Original Poster
Rep: Reputation: 2
okay thanks for catching my typos mainly. Urgh

I will add

Code:
USR="root"
dir="dir /mnt/thunder1"
mkdir="mkdir /mnt/thunder1"
mount=”wtadmin1:/exports/thunder1”
mountpoint=”/data/mountpoint”

for host in wtc6cn{1..10}
do
echo “=====================================”
ssh $USR@$host “hostname -a && mkdir $dir && mount $mount $mountpoint”
echo “=====================================”
done
Any hints on how to fix the error? I understand there is one, or maybe several.

Last edited by dorlack; 11-17-2014 at 04:02 PM.
 
Old 11-17-2014, 04:09 PM   #7
dorlack
Member
 
Registered: Oct 2009
Location: Cambridge MA
Distribution: Any Linux
Posts: 122

Original Poster
Rep: Reputation: 2
GOT IT!
Code:
if [ -d /dir ]; then mount -t nfs $....; else mkdir /dir && mount -t nfs ...; fi
thanks for your help finding my foolish errors, needed second set of eyes its been a long monday
 
Old 11-17-2014, 07:05 PM   #8
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,255

Rep: Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559
Both 'mount' and 'mountpoint' are actually commands it is really not a good idea to use vatiable names that clash with real commands, if you must use them then at least upper case them, so 'MOUNTPOINT' instead of 'mountpoint' you will find a loy less errors creeping in if you do, it also helps in debugging as its then obvious that you are refering to a variable or a command.
 
Old 11-18-2014, 02:24 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Quote:
it is really not a good idea to use vatiable names that clash with real commands
This x 1000 - seriously.. see also 'mkdir'

eg the middle part of post 6 becomes
Code:
mkdir dir /mnt/thunder1
Try setting
Code:
#!/bin/bash
set -xv
at the top of your code; 2nd line shows you exactly what the interpreter is seeing/doing
 
1 members found this post helpful.
Old 11-18-2014, 06:00 AM   #10
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,255

Rep: Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559
Missed the 'mkdir' just saw it as a command not as a variable which points up what both I and chrism01 have just said.
 
  


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
[To share Bash knowledge]Notes for Advanced Bash-Scripting Version 10 (Latest) jcky Programming 4 07-31-2014 10:24 AM
[SOLVED] Bash Script - Reading User Input while Processing output from Command within Bash cleeky Linux - General 5 05-27-2014 03:57 PM
Bash problem : -bash: [: /bin/bash: unary operator expected J.A.X Linux - Software 1 09-22-2011 06:52 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 12:10 PM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 07:42 PM


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

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