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?
 
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
 
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
 
bibi92Author Commented:
I have tested the two solutions and it does not work.

Thanks

Regards
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.