[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

CSH Run 2 things at once

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
fixitben
Asked:
fixitben
  • 6
  • 5
1 Solution
 
woolmilkporcCommented:
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
 
woolmilkporcCommented:
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
 
fixitbenAuthor Commented:
It complains about "too many ('s"  when using the ()&. I think that might be because I am using CSH.

Thanks
Fixitben
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
woolmilkporcCommented:
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
 
fixitbenAuthor Commented:
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
 
woolmilkporcCommented:
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
 
fixitbenAuthor Commented:
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
 
woolmilkporcCommented:
Didn't you find (one or several of) my comments helpful?

Why would you accept your own answer as a solution?
0
 
fixitbenAuthor Commented:
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
 
fixitbenAuthor Commented:
Assigned to me by mistake
0
 
fixitbenAuthor Commented:
Thanks sorry about the points.
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now