Fedora Linux Support Community & Resources Center
  #1  
Old 8th March 2008, 06:22 PM
vanesta Offline
Registered User
 
Join Date: Mar 2008
Posts: 1
Bash newbie - how to execute multiple command?

hi Guys, Victoria here!

I'm new to the forum, and in need of a guide on how to run multiple command on linux command line.

I want to rsync multiple folders

I know the rsync command but how to i make it into 1 script backup.sh

mount /dev/sdb1 /iscsi
rsync -vrplogDtH /var/lib/mysql/ /iscsi/mysql/
rsync -vrplogDtH /home/ /iscsi/home/

and how can i make them finished 1 command before jumping to another with verbose output.

Thank you so much guys!
Reply With Quote
  #2  
Old 8th March 2008, 07:57 PM
scottro's Avatar
scottro Offline
Retired Community Manager -- Banned from Texas by popular demand.
 
Join Date: Sep 2007
Location: NYC
Posts: 8,142
Do you mean complete successfully? Actually, as you have it written, it should do what you want. It will finish the first command, then execute the next line.

If you do
rsync -vrplogDtH /var/lib/mysql/ /iscsi/mysql/ &&

It will only execute the second command if the first one completed successfully.
Reply With Quote
  #3  
Old 8th March 2008, 08:59 PM
dshaw256 Offline
Registered User
 
Join Date: Mar 2006
Location: Virginia
Age: 59
Posts: 246
I don't want to comment on the wisdom of running those two particular commands at the same time, because I don't know what they are doing. But in general, you can issue a command with an & behind it, and it will run in the background. And if you direct stdout to a file, you can catch all the output from each command..

So:
Code:
mount /dev/sdb1 /iscsi
rsync -vrplogDtH /var/lib/mysql/ /iscsi/mysql/ > cmd1.txt &
rsync -vrplogDtH /home/ /iscsi/home/ > cmd2.txt &
...should work to run those two commands at the same time.
__________________
Dave Shaw
Registered Linux user #412525
Dell Latitude D610 / FC13
dshaw256@centurylink.net

no problem is so bad that a moron with root can't make it much worse

Last edited by dshaw256; 8th March 2008 at 09:04 PM.
Reply With Quote
  #4  
Old 8th March 2008, 09:48 PM
marko's Avatar
marko Offline
Registered User
 
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 5,442
She wanted the commands to run serially and not in the background
so don't use ampersands, also she wanted verbosity but not necessarily
to dump to files, so I'd suggest making a file called backup.sh that
contains:
Code:
#!/bin/sh
mount /dev/sdb1 /iscsi
rsync -vrplogDtH /var/lib/mysql/ /iscsi/mysql/
rsync -vrplogDtH /home/ /iscsi/home/

this is already verbose because of the -v option being used
on rsync. To retain the verbose output to a file just do:

if the shell is tcsh or csh: backup.sh >& outputfile
if the shell is bash or sh: backup.sh > output 2>&1


If you always want to write to the file, it makes more sense to put
the redirection in the backup.sh
Code:
#!/bin/sh
mount -v /dev/sdb1 /iscsi > outputfile 2>&1
rsync -vrplogDtH /var/lib/mysql/ /iscsi/mysql/ >> outputfile 2>&1
rsync -vrplogDtH /home/ /iscsi/home/ >> outputfile 2>&1
There's a few correctness things wrong with this, nowadays you'd
usually not do:
mount /dev/sdb1 /iscsi > outputfile 2>&1

but rather use mount's -L option flag to mount the device by
the filesystem label (you'd have to use e2label to set the
filesystems label to MyBackup)

mount -vL MyBackup > outputfile

and your /etc/fstab would have a related entry to associate
that with /iscsi:

LABEL=MyBackup /iscsi ext3 defaults,noatime 1 2

The problem with hardcoding /dev/sdb1 is that
sometime you might plug in some other usb devices before the
drive that has your iscsi named volume. That might make linux
map it to /dev/sdc1 and your script will break. Since mount -L
uses the actual label in the filesystem it mounts the right drive
each time no matter what the order the devices are found.


Mark

Last edited by marko; 8th March 2008 at 09:52 PM.
Reply With Quote
  #5  
Old 9th March 2008, 02:22 PM
dshaw256 Offline
Registered User
 
Join Date: Mar 2006
Location: Virginia
Age: 59
Posts: 246
Whups. Sorry. Misread her intent.
__________________
Dave Shaw
Registered Linux user #412525
Dell Latitude D610 / FC13
dshaw256@centurylink.net

no problem is so bad that a moron with root can't make it much worse
Reply With Quote
Reply

Tags
bash, command, execute, multiple, newbie

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: cannot execute binary file manditri Using Fedora 1 17th July 2008 07:32 PM
Execute command at runlevel-1 ??? buttari Using Fedora 2 21st January 2007 04:15 PM
how-to execute a command with an email paul_mat Servers & Networking 3 5th September 2006 03:37 PM
How do I Execute command on display :1 pobman Using Fedora 2 5th May 2006 08:49 AM
Newbie question: Can not execute scripts in BASH pradovic Using Fedora 4 17th October 2004 04:10 AM


Current GMT-time: 16:57 (Saturday, 18-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat