Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CSH Run 2 things at once

Posted on 2011-03-25
11
Medium Priority
?
409 Views
Last Modified: 2012-08-13
I have some code written is CSH.
The code backs up data to a drive then displays on the screen as each step finishes.
I need to back up the data to 2 drives for redundancy. So currently it backs up the data to the first drive then backs it up to the second drive. I would like to speed up the process by backing up to both at the same time.

Is there a way to spawn both at the same time and output any echos I have back to the terminal in CSH?

Below is a sample of the code I am using to give you an idea.

 
echo "Writing to Backup System 1 Please Wait"
    rsync -vlrptog  --stats  $dir/ $pnpath/$filedate > $pnpath/$filedate/$project-$filedate.log
    cp $pnpath/$filedate/$project-$filedate.log $dir/.
    cp $pnpath/$filedate/$project-$filedate.log /$drive/log/.
    echo "rsync -vlrptogn  --stats $dir/ $pnpath/$filedate" >> $pnpath/$filedate/$project-$filedate.log
    set bytes = `grep "Total file" $pnpath/$filedate/$project-$filedate.log | cut -d: -f2 | cut -d' ' -f2`
    set kilobytes = `echo "scale=3; $bytes/1024" | bc`
    set megabytes = `echo "scale=3; $kilobytes/1024" | bc`
    set gigabytes = `echo "scale=3; $megabytes/1024" | bc`

    mutt -c xxxxx@xxxx.com -s "Linux Backup Drive 1  $gigabytes gb   $project $filedate " xxxx@xxxx.com < $pnpath/$filedate/$project-$filedate.log
    echo ""
    echo " "
    echo " "
    echo "Drive 1 Complete $project"


echo "Writing to Backup System 2 Please Wait"
    rsync -vlrptog  --stats  $dir/ $pnpath/$filedate > $pnpath/$filedate/$project-$filedate.log
    cp $pnpath/$filedate/$project-$filedate.log $dir/.
    cp $pnpath/$filedate/$project-$filedate.log /$drive/log/.
    echo "rsync -vlrptogn  --stats $dir/ $pnpath/$filedate" >> $pnpath/$filedate/$project-$filedate.log
    set bytes = `grep "Total file" $pnpath/$filedate/$project-$filedate.log | cut -d: -f2 | cut -d' ' -f2`
    set kilobytes = `echo "scale=3; $bytes/1024" | bc`
    set megabytes = `echo "scale=3; $kilobytes/1024" | bc`
    set gigabytes = `echo "scale=3; $megabytes/1024" | bc`

    mutt -c xxxxxxxx@xxxx.com -s "Linux Backup Drive 1  $gigabytes gb   $project $filedate " xxxx@xxx.com < $pnpath/$filedate/$project-$filedate.log
    echo ""
    echo " "
    echo " "
   echo "Drive 2 Complete $project"

Open in new window



Thanks
Fixitben

0
Comment
Question by:fixitben
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35219321
Hi,

either turn your single script into two distinct scripts, one for each task, and start them (maybe in a wrapper script) like:

#!/bin/csh
echo "Start of Parallel Backup"
backup1.csh &
backup2.csh &
echo "End of Parallel Backup"
exit

or change your existing script like below.

Note the parentheses  "(  )"  around each of the two code blocks followed by "&"

Please note also that with either method the messages issued will overlap, so it might be better writing them to logfiles.

wmp
( echo "Writing to Backup System 1 Please Wait"
    rsync -vlrptog  --stats  $dir/ $pnpath/$filedate > $pnpath/$filedate/$project-$filedate.log
    cp $pnpath/$filedate/$project-$filedate.log $dir/.
    cp $pnpath/$filedate/$project-$filedate.log /$drive/log/.
    echo "rsync -vlrptogn  --stats $dir/ $pnpath/$filedate" >> $pnpath/$filedate/$project-$filedate.log
    set bytes = `grep "Total file" $pnpath/$filedate/$project-$filedate.log | cut -d: -f2 | cut -d' ' -f2`
    set kilobytes = `echo "scale=3; $bytes/1024" | bc`
    set megabytes = `echo "scale=3; $kilobytes/1024" | bc`
    set gigabytes = `echo "scale=3; $megabytes/1024" | bc`

    mutt -c xxxxx@xxxx.com -s "Linux Backup Drive 1  $gigabytes gb   $project $filedate " xxxx@xxxx.com < $pnpath/$filedate/$project-$filedate.log
    echo ""
    echo " "
    echo " "
    echo "Drive 1 Complete $project" ) &


( echo "Writing to Backup System 2 Please Wait"
    rsync -vlrptog  --stats  $dir/ $pnpath/$filedate > $pnpath/$filedate/$project-$filedate.log
    cp $pnpath/$filedate/$project-$filedate.log $dir/.
    cp $pnpath/$filedate/$project-$filedate.log /$drive/log/.
    echo "rsync -vlrptogn  --stats $dir/ $pnpath/$filedate" >> $pnpath/$filedate/$project-$filedate.log
    set bytes = `grep "Total file" $pnpath/$filedate/$project-$filedate.log | cut -d: -f2 | cut -d' ' -f2`
    set kilobytes = `echo "scale=3; $bytes/1024" | bc`
    set megabytes = `echo "scale=3; $kilobytes/1024" | bc`
    set gigabytes = `echo "scale=3; $megabytes/1024" | bc`

    mutt -c xxxxxxxx@xxxx.com -s "Linux Backup Drive 1  $gigabytes gb   $project $filedate " xxxx@xxx.com < $pnpath/$filedate/$project-$filedate.log
    echo ""
    echo " "
    echo " "
   echo "Drive 2 Complete $project" ) &

Open in new window

0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35219341
Forgot to "wait" in the wrapper script, sorry!

#!/bin/csh
echo "Start of Parallel Backup"
backup1.csh &
backup2.csh &
wait
echo "End of Parallel Backup"
exit
0
 
LVL 7

Author Comment

by:fixitben
ID: 35219521
It complains about "too many ('s"  when using the ()&. I think that might be because I am using CSH.

Thanks
Fixitben
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 35219774
Yes,

you're right, csh would not tolerate line breaks inside the parentheses
(I just tested it here, didn't know that up to now).

I can't see anything specific to csh in the code, so why don't you use bash?
Just put "#!/bin/bash" into the first line of your script, instead of "#/bin/csh".

If you insist in csh you could use the "two scripts" method.

You could also terminate each line inside the parentheses (including blank lines) with ";\", i.e. a command separator plus a line continuation character. I tested this as well, it works, but it seems a bit too tedious, don't you think?

 
( echo "Writing to Backup System 1 Please Wait" ;\
    rsync -vlrptog  --stats  $dir/ $pnpath/$filedate > $pnpath/$filedate/$project-$filedate.log ;\
    cp $pnpath/$filedate/$project-$filedate.log $dir/. ;\
    cp $pnpath/$filedate/$project-$filedate.log /$drive/log/. ;\
    echo "rsync -vlrptogn  --stats $dir/ $pnpath/$filedate" >> $pnpath/$filedate/$project-$filedate.log ;\
    set bytes = `grep "Total file" $pnpath/$filedate/$project-$filedate.log | cut -d: -f2 | cut -d' ' -f2` ;\
    set kilobytes = `echo "scale=3; $bytes/1024" | bc` ;\
    set megabytes = `echo "scale=3; $kilobytes/1024" | bc` ;\
    set gigabytes = `echo "scale=3; $megabytes/1024" | bc` ;\
;\
    mutt -c xxxxx@xxxx.com -s "Linux Backup Drive 1  $gigabytes gb   $project $filedate " xxxx@xxxx.com < $pnpath/$filedate/$project-$filedate.log ;\
    echo "" ;\
    echo " " ;\
    echo " " ;\
    echo "Drive 1 Complete $project" ) &


( echo "Writing to Backup System 2 Please Wait" ;\
    rsync -vlrptog  --stats  $dir/ $pnpath/$filedate > $pnpath/$filedate/$project-$filedate.log ;\
    cp $pnpath/$filedate/$project-$filedate.log $dir/. ;\
    cp $pnpath/$filedate/$project-$filedate.log /$drive/log/. ;\
    echo "rsync -vlrptogn  --stats $dir/ $pnpath/$filedate" >> $pnpath/$filedate/$project-$filedate.log ;\
    set bytes = `grep "Total file" $pnpath/$filedate/$project-$filedate.log | cut -d: -f2 | cut -d' ' -f2` ;\
    set kilobytes = `echo "scale=3; $bytes/1024" | bc` ;\
    set megabytes = `echo "scale=3; $kilobytes/1024" | bc` ;\
    set gigabytes = `echo "scale=3; $megabytes/1024" | bc` ;\
;\
    mutt -c xxxxxxxx@xxxx.com -s "Linux Backup Drive 1  $gigabytes gb   $project $filedate " xxxx@xxx.com < $pnpath/$filedate/$project-$filedate.log ;\
    echo "" ;\
    echo " " ;\
    echo " " ;\
   echo "Drive 2 Complete $project" ) &

Open in new window

0
 
LVL 7

Author Comment

by:fixitben
ID: 35244497
Is there a way to direct the std out back to the parent process?

Attached is the output.


I would like to see the entire output of  (echo "Writing to Primary Backup System Please Wait"; rsync -vlrptog --stats  ... )

Thanks
Fixitben
Creating Folder Structure for Primary Drive
Folder Created for Primary Drive
Creating Folder Structure on Secondary Drive
Folder Created for Secondary Drive Starting Backup

Writing to Primary Backup System Please Wait
[1] 15994

Writing to Secondary Backup System Please Wait
[2] 15996
[2]    Done                          ( echo "Writing to Secondary Backup System Please Wait"; rsync -vlrptog --stats ...
[1]  + Done                          ( echo "Writing to Primary Backup System Please Wait"; rsync -vlrptog --stats  ...



Complete 114418

Open in new window

0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35244674
What do you mean with "entire output"?

There is generally no need to redirect anything back, stdout is used and displayed as always.

Nearly all of your output is redirected to logfiles (if you use the snippet I posted),
except for "Writing to ..." which is indeed displayed, and the "Drive complete .." stuff - which is somewhat incomplete, but this should not happen! Did you actually use the code I posted?

wmp

0
 
LVL 7

Author Comment

by:fixitben
ID: 35244889
Yeah that will work I added the echo "Drive 1 Complete $project"  to each and that helps.
I was worried that the errors where going to get lumped into the one line and I wouldn't be able to see them.

Thanks for your help.

Thanks
Fixitben
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35244923
Didn't you find (one or several of) my comments helpful?

Why would you accept your own answer as a solution?
0
 
LVL 7

Author Comment

by:fixitben
ID: 35244933
I messed up I am submitting a request to have it changed. I clicked mine thinking it was yours.

Sorry I will get it fixed.

Thanks
Fixitben
0
 
LVL 7

Author Comment

by:fixitben
ID: 35246983
Assigned to me by mistake
0
 
LVL 7

Author Closing Comment

by:fixitben
ID: 35247002
Thanks sorry about the points.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question