LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell script to copy the logs from production to DR (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-to-copy-the-logs-from-production-to-dr-4175480434/)

abhilashsriram 10-11-2013 11:07 AM

Shell script to copy the logs from production to DR
 
Hello,
I am trying to write a shell script to copy the archivelogs from production server to the DR server but i am not able to make it. I am attaching the code what i have tried please send me your answers.



#!/bin/bash
df -h |grep /var > mount_space
cat mount_space | awk '{print $4}' > free_space
if [ $b >= 1G ]
then
ls -lrth /home/prod/dr > lst_dr
tail -1 lst_dr | awk '{print $9}' > last_dr
ls -lrth /home/prod/prod > lst_prod
tail -1 lst_prod | awk '{print $9}' > last_prod
for ((i=last_dr;i<=lat_prod;i++))
do
cp /home/prod/prod/*.Z /home/prod/dr/
done
else
echo 'insufficient space to copy'
fi



Thanks,
Abhilash sriram

rm2629 10-11-2013 12:02 PM

For starters, the test $b is invalid, you have not created, nor assigned a variable 'b'.

Try the following:

Code:

b=`cat mount_space | awk '{print $4}'`
Also, after your first line, add a line:

Code:

set -xv
When you re-run your script, it will print out some debug with those flags enabled. Post if there are further problems.

abhilashsriram 10-25-2013 10:10 AM

Shell script
 
Hi i have tried your code but its not working i am posting the information please go through the script and do the need full and also i am posting the output of the code. By setting the "set -xv" line after the first line the entire program is shown in the output once again i dont need that. Please go through the information.

[oracle@dbalab6 abhi]$ sh shell.sh
df -h |grep /var > mount_space
+ df -h
+ grep /var
b=`cat mount_space | awk '{print $4}'`
cat mount_space | awk '{print $4}'
++ cat mount_space
++ awk '{print $4}'
+ b=1.7G
if [ $b >= 1G ]
then
ls -lrth /home/prod/dr > lst_dr
tail -1 lst_dr | awk '{print $9}' > last_dr
ls -lrth /home/prod/prod > lst_prod
tail -1 lst_prod | awk '{print $9}' > last_prod
for ((i=last_dr;i<=lat_prod;i++))
do
cp /home/prod/prod/*.Z /home/prod/dr/
done
else
echo 'insufficient space to copy'
fi
+ '[' 1.7G 1G ']'
shell.sh: line 5: [: 1.7G: unary operator expected
+ echo 'insufficient space to copy'
insufficient space to copy

--> I do have checked the mount point space but its fine even though it is throwing the error.

--> I do have one more idea for this can we use rsync command to copy the logs but the problem in using this command is crosschecking of the archives is not happening.


All times are GMT -5. The time now is 12:34 AM.