execute rsync and mount command in a shell script

Hello,

I have create the following shell script :
$ORACLE_HOME/bin/rman target sys/manager nocatalog cmdfile=/oracle/backup.par log=/oracle/LOG/rman_result_$ORACLE_SID.log
sleep 10
sudo -i
mount -t cifs -o 'username=test','password=test','uid=oracle
','gid=oinstall' //d2d/BKP_SQL /mnt/d2d
rsync -avz /backup/oracle/ /mnt/d2d/oracle/
sleep 10
umount /mnt/d2d

Open in new window

The rman command successfully completed but the commands sudo, mount, rsync and umount are not executed.
Why?
Thanks
Regards
bibi92Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

johnsoneSenior Oracle DBACommented:
You need to redirect input to sudo.  I believe that this will only work if sudo is not going to prompt for a password:
$ORACLE_HOME/bin/rman target sys/manager nocatalog cmdfile=/oracle/backup.par log=/oracle/LOG/rman_result_$ORACLE_SID.log
sleep 10
sudo -i << EOF
mount -t cifs -o 'username=test','password=test','uid=oracle
','gid=oinstall' //d2d/BKP_SQL /mnt/d2d
rsync -avz /backup/oracle/ /mnt/d2d/oracle/
sleep 10
umount /mnt/d2d
exit
EOF

Open in new window

If sudo will prompt for a password, then you are not going to be able to use a shell script.  The best option I know of for doing something like that is expect.  It is a different scripting language and can handle prompting for passwords and spawning of a separate shell.  It is not typically installed by default either.
0
omarfaridCommented:
If you are not prompted for password, then you could run commands as below:

$ORACLE_HOME/bin/rman target sys/manager nocatalog cmdfile=/oracle/backup.par log=/oracle/LOG/rman_result_$ORACLE_SID.log
sleep 10
sudo -i "mount -t cifs -o 'username=test','password=test','uid=oracle
','gid=oinstall' //d2d/BKP_SQL /mnt/d2d"
sudo -i "rsync -avz /backup/oracle/ /mnt/d2d/oracle/"
sudo -i "sleep 10"
sudo -i "umount /mnt/d2d"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bibi92Author Commented:
I have tested the two solutions and it does not work.

Thanks

Regards
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

johnsoneSenior Oracle DBACommented:
What about it doesn't work?  Error message?  If you execute the commands interactively, what happens?  Does sudo prompt for a password?  We aren't mind readers.
0
bibi92Author Commented:
No error message the script hang after rman backup
0
johnsoneSenior Oracle DBACommented:
So, if you run the commands interactively, I'm guessing that sudo prompts for a password.  Is that correct?
0
bibi92Author Commented:
no I use sudo -i and not having prompts for a password.
0
johnsoneSenior Oracle DBACommented:
I would put this at the top of the script and see exactly what command it hangs on:

#!/bin/sh -x
0
bibi92Author Commented:
Thanks I have removed sleep 10
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.