LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here.

Notices

Reply
 
Thread Tools
Old 10-24-2009, 04:45 PM   #1
kebabbert
Member
 
Registered: Jul 2005
Posts: 374
Thanked: 1
quick shell question


[Log in to get rid of this advertisement]
I need to copy 1.3TB to two drives. I have two drives, called Movies1 and Movies2. Each drive is one zpool. Thus, I have two zpools. I want identical copies of my 1.3TB data. I want to do one command at a time, and not simultaneous:
# zfs send tank/Video@now | zfs receive Movies1/now1
# zfs send tank/Video@now | zfs receive Movies2/now2

I do not want to do them simultaneously. I want to do one copy, and when it has finished copying, I want to start the next copy. So how do I do that?

If I write both lines into a shell file and execute the shell, then the first command will execute and return after 1 second, and then the other command will execute 1 second later? I want the first command to execute, which may take 2 hours, and then the other command to execute. How can I do that?

Actually, I want to do this:
# zfs send tank/Video@now | zfs receive Movies1/now1
# zfs scrub Movies1
# zfs send tank/Video@now | zfs receive Movies2/now2
# zfs scrub Movies2

But I do not want the copying to be simultaneous. As soon as the first "zfs..." ends, I want "zfs scrub" to start and immediately I want the second "zfs..." to start. So Movies1 will be scrubbed while I copy again.
solaris kebabbert is offline     Reply With Quote
Old 10-24-2009, 05:22 PM   #2
choogendyk
Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 854
Thanked: 34
If you end the line with a semicolon, that means that command should finish before proceeding. I typically use that in ksh, but I'm pretty sure it should apply to sh as well.

You could also put '&& \' at the end of the lines. That's different, and says, if this command succeeds then proceed. Of course the "\" is just continuing the lines so that the next command is considered as a continuation of the first line.

So, perhaps

Code:
# zfs send tank/Video@now | zfs receive Movies1/now1;
# zfs scrub Movies1
# zfs send tank/Video@now | zfs receive Movies2/now2;
# zfs scrub Movies2
Check out this http://www.ncsa.illinois.edu/UserInf...l_features.htm page and look down to where it describes the shell term "list" and the separators that can be used.
macos choogendyk is offline     Reply With Quote
Old 10-25-2009, 04:10 AM   #3
kebabbert
Member
 
Registered: Jul 2005
Posts: 374
Thanked: 1

Original Poster
Thanks. I did something like
command1 & command2 ; command3 & command4 ; command5 & command6
on one big line. This means that command1 and command2 will be performed simultaneuosly. And then, when they have finished, command3 and command4 will start. commmand3 and command4 will wait until their turn.
solaris kebabbert is offline     Reply With Quote
Old 10-26-2009, 04:49 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris, under a rock ...
Distribution: Solaris & OpenSolaris based distros, Ubuntu
Posts: 8,134
Thanked: 86
Note that a trailing semicolon has no particular effect.
The shell executes the commands sequentially so doesn't start running a command before the previous one has finished (daemons, background and pipelines commands excepted).
solaris jlliagre is offline     Reply With Quote
Old 10-26-2009, 08:57 AM   #5
kebabbert
Member
 
Registered: Jul 2005
Posts: 374
Thanked: 1

Original Poster
I didnt get that. Could you please explain again?
windows_xp_2003 kebabbert is offline     Reply With Quote
Old 10-26-2009, 01:09 PM   #6
catkin
Senior Member
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Slackware 13.0
Posts: 1,853
Blog Entries: 6
Thanked: 226
If you write a shell script like (I have no idea what these commands do, BTW)
Code:
zfs send tank/Video@now
zfs scrub Movies1
Then the script will wait until the first returns and then execute the second command, it's as simple as that.

It gets complicated if the first command returns before it completes (for example it backgrounds itself or turns itself into a daemon) or if you want execution of the second command to be conditional on the first command succeeding or failing -- but if you want "normal" commands to be executed in sequence then just put them one after another in the script.
linux catkin is offline     Reply With Quote
Old 10-26-2009, 04:54 PM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris, under a rock ...
Distribution: Solaris & OpenSolaris based distros, Ubuntu
Posts: 8,134
Thanked: 86
Yes. I was commenting that statement:

Quote:
If you end the line with a semicolon, that means that command should finish before proceeding.
which tells a semicolon has an effect. When located at the end of a command line, a semicolon is a no-op.
solaris jlliagre is offline     Reply With Quote
Old 10-26-2009, 08:01 PM   #8
choogendyk
Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 854
Thanked: 34
OK, I have two senior members, both of whom I typically trust, telling me I'm wrong.

I tried researching it today (searching through the O'Reilly book "Learning the Korn Shell", as well as putting my google fu to the test), and couldn't find anything to support what I had said. My boss, who is a Unix guru going way back, has said this many times ("the semicolon forces completion"), and I could swear we have had problems with cron scripts where putting in all the semicolons fixed it. But, hey, there's enough uncertainty in all that and nothing concrete to prove me right. So I guess I have to concede.

If I ever find anything concrete in my favor, I'll come back here with a link. But, that doesn't seem likely at the moment.
macos choogendyk is offline     Reply With Quote
Old 10-27-2009, 03:34 AM   #9
catkin
Senior Member
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Slackware 13.0
Posts: 1,853
Blog Entries: 6
Thanked: 226
Quote:
Originally Posted by choogendyk View Post
OK, I have two senior members, both of whom I typically trust, telling me I'm wrong.
Thanks but take care -- I don't trust me!

But the GNU Bash Reference Manual is definitive (until proven wrong!). It says "Note that wherever a ‘;’ appears in the description of a command's syntax, it may be replaced with one or more newlines".
linux catkin is offline     Reply With Quote
Old 10-27-2009, 09:54 AM   #10
kebabbert
Member
 
Registered: Jul 2005
Posts: 374
Thanked: 1

Original Poster
choogendyk, do you have Erdos number 4? Great respect in that case.
windows_xp_2003 kebabbert is offline     Reply With Quote
Old 10-27-2009, 07:31 PM   #11
choogendyk
Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 854
Thanked: 34
Lucky. Paper I published in 1984 (http://deepblue.lib.umich.edu/handle/2027.42/24683). My co-author is very active in mathematical publishing. Sometime around 2000 or so, he published a paper with someone who had an Erdös 2. That gave him a 3 and me a 4. Just a lucky shot out of the blue.
macos choogendyk is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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
Quick shell scripting question Komelore Programming 3 03-12-2007 09:39 AM
Quick Challange for shell scripters! neocookie Programming 2 09-12-2005 11:13 AM
Quick Shell Question youssefe2k Linux - Software 2 04-10-2005 10:47 PM
I need a quick shell script. 360 Programming 3 03-22-2002 05:44 PM


All times are GMT -5. The time now is 02:11 AM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration