Hello guys.
i have several backup servers which i have to monitor them daily.
now i want an script to use the backup directory and put it in output variable.
my backup files look like this:
[ll -hrt
total 151G
-rw-r----- 1 oracle oinstall 68G Jan 23 00:21 full_ORCL_20150122_7277_1.bck
-rw-r----- 1 oracle oinstall 1.3G Jan 23 00:24 arch_ORCL_20150123_7279_1.bck
-rw-r----- 1 oracle oinstall 444M Jan 24 21:12 level1_ORCL_20150124_7281_1.bck
-rw-r----- 1 oracle oinstall 1.3G Jan 24 21:16 arch_ORCL_20150124_7283_1.bck
-rw-r----- 1 oracle oinstall 11M Jan 24 21:16 c-1229942357-20150124-01
-rw-r----- 1 oracle oinstall 664M Jan 25 21:16 level1_ORCL_20150125_7285_1.bck
-rw-r----- 1 oracle oinstall 11M Jan 25 21:16 c-1229942357-20150125-00
-rw-r----- 1 oracle oinstall 1.2G Jan 25 21:35 arch_ORCL_20150125_7287_1.bck
-rw-r----- 1 oracle oinstall 11M Jan 25 21:35 c-1229942357-20150125-01
-rw-r----- 1 oracle oinstall 870M Jan 26 21:32 level1_ORCL_20150126_7289_1.bck
-rw-r----- 1 oracle oinstall 11M Jan 26 21:32 c-1229942357-20150126-00
-rw-r----- 1 oracle oinstall 1.2G Jan 26 21:42 arch_ORCL_20150126_7291_1.bck
-rw-r----- 1 oracle oinstall 11M Jan 26 21:42 c-1229942357-20150126-01
-rw-r----- 1 oracle oinstall 1.2G Jan 27 21:16 level1_ORCL_20150127_7293_1.bck
-rw-r----- 1 oracle oinstall 11M Jan 27 21:16 c-1229942357-20150127-00
-rw-r----- 1 oracle oinstall 1.2G Jan 27 21:33 arch_ORCL_20150127_7295_1.bck
-rw-r----- 1 oracle oinstall 11M Jan 27 21:33 c-1229942357-20150127-01
-rw-r----- 1 oracle oinstall 1.4G Jan 28 21:31 level1_ORCL_20150128_7297_1.bck
-rw-r----- 1 oracle oinstall 11M Jan 28 21:31 c-1229942357-20150128-00
-rw-r----- 1 oracle oinstall 1.2G Jan 28 21:51 arch_ORCL_20150128_7299_1.bck
-rw-r----- 1 oracle oinstall 11M Jan 28 21:51 c-1229942357-20150128-01
-rw-r----- 1 oracle oinstall 68G Jan 30 07:01 full_ORCL_20150129_7301_1.bck
-rw-r----- 1 oracle oinstall 11M Jan 30 07:02 c-1229942357-20150130-00
-rw-r----- 1 oracle oinstall 1.4G Jan 30 07:05 arch_ORCL_20150130_7303_1.bck
-rw-r----- 1 oracle oinstall 11M Jan 30 07:05 c-1229942357-20150130-01
drwxr-xr-x 2 oracle oinstall 16K Jan 31 21:01 rman
-rw-r----- 1 oracle oinstall 436M Jan 31 21:13 level1_ORCL_20150131_7305_1.bck
-rw-r----- 1 oracle oinstall 11M Jan 31 21:13 c-1229942357-20150131-00
-rw-r----- 1 oracle oinstall 1.4G Jan 31 21:16 arch_ORCL_20150131_7307_1.bck
-rw-r----- 1 oracle oinstall 11M Jan 31 21:17 c-1229942357-20150131-01
as you can see file names contain the date and the type of backup(just level and full are important to me)
now i want return the values like this:
if the backup date belong to today or yesterday and backup type was full return 10
if the backup date belong to today or yesterday and backup was level return 5
and if non of them was true return 0.
i have no idea how can:
1- put the files name in a string.
2- how can extract the last backup date and type?
3- how can compare the date with current day?
sorry for asking questions like this. i just start shell scripting but this one is kind of emergency.
thank you so much.
thank you dear Don.
I'm using red hat. but i don't know what kind of shell I'm using!!
my time zone is: IRST.
date output is: Sun Feb 1 10:08:39 IRST 2015
thank you.
First, never tell us: "i use your command and make this script but it wouldn't work"! Show us the exact output from running the script that explains to us exactly what didn't work. If you don't show us how it isn't working, it makes it a huge guessing game for all of us (especially those of us who are using a different operating system and shell than you're using).
Second, there is a HUGE difference between running a program and feeding its output to awk as RudiC suggested with:
ls -l | awk ...
and running a program, saving its output in a variable, executing a fixed string, and feeding the results of the command named by that string to awk as your code is doing:
output=$(ls -l $1)
"output" | awk ...
Why are you storing the output from ls in a variable.
Third: You have an extraneous single quote before the -F option to awk .
And, fourth: I don't see how this script is going to work if you use ls -l instead of ls without the -l option. (With ls -l output, $1 in awk is never going to match Full nor level .)
Please try running your script more like RudiC suggested:
You assigned the ls result to the "output" variable. To get at its contents, the shell needs to expand it: $output , to keep the shell from swallowing redundant spaces etc, quote it: "$output". To pipe it into sth. else, echo it: echo "$output" .
Why don't you pipe ls 's results immediately, as I alluded in my post?
Thank you dear Singh.
but your command doesn't work.
dear Don . i use the ssh to get the directory info. so i had to run and put it in a variable.
i use your shell command and it work but not the way i want it.
result:
i want just return a value. your shell script return a value for each directory name.
let me put it this way:
i want check the directory for backup status. valid backup lifetime is less than two days. now
if the script return the "10" i found out i have a full backup which is valid.
if the script return the "5" i found out i have a level backup which is valid.
in other wise i dont have a valid backup file.
thank you dear RudiC.
i use the ssh to get the directory info. so i had to run and put it in a variable.
I don't see the necessity to use a variable if you run an ssh command. From what you showed in post #1, there is an entire directory listing to be processed, and you did not specify the output format desired.
Please provide the entire picture of what you need to do so we can provide a fit soulition.
Ok. let me explain what exactly i want.
I'm using zenoss to monitor my servers. in the zenoss i cant handle the plain text. i just can use the numerical values. now i want create an alert to warn me if there was no back up files.
so i decided to wrote an script to do this.
now if you guys have better idea please share it with me.
i really appreciate any sort of help.
thank you.
Sorry, I can't imagine the picture from what you post. Wildly guessing: Do you need a script to be run on every server that checks all files and, if a full/level backup found within the last two days, sends a number (10/5) back? How do you intend to send the date parameter if you can handle numbers only? How do you want to store the script?
ye exactly.
i don't want to send any date parameters. just a simple yes or no is enough for now.
the script store in my zenoss server and run via ssh(with pki and without password authentication.)
Thank you.