CLI script for emailing alert if files missing in dir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting CLI script for emailing alert if files missing in dir
# 1  
Old 02-25-2015
Computer CLI script for emailing alert if files missing in dir

thread removed

Last edited by billabongjimmy; 02-27-2015 at 05:35 PM.. Reason: Add ICODE tags.
# 2  
Old 02-25-2015
Is this a homework assignment? If so, please refile in the Homework & Coursework Questions forum following the directions specified here.

If not, what have you tried?

What operating system and shell are you using?
# 3  
Old 02-25-2015
removed

Last edited by billabongjimmy; 02-27-2015 at 05:36 PM..
# 4  
Old 02-26-2015
Here is example to use ksh93 shell, which include builtin date calculation properties.

In other shell you can use ex. GNU date like:
Code:
from="20140226"
epoc=$(date --date="$from" +"%s")

Code:
#!/bin/ksh93

smail()
{

/usr/lib/sendmail -t -i <<EOF
From: myemail@some.com
To: alert@some.com
Subject: Missing

$*

Thats all.

-checker-

EOF
}

####MAIN###################
epocnow=$(printf "%(%#)T" now)
nowyyyymmddhh=$(printf "%(%Y%m%d%H)T" now)

datestr=$(printf "%(%Y-%m-%d %H:00)T" now)
epocnow2=$(printf "%(%#)T" "$datestr")
# length of day (seconds) = 86400
((hour=60*60))
((day=24*hour))

startstr="2015-02-23 00:00"
epoc=$(printf "%(%#)T" "$startstr")

print "$epocnow - $nowyyyymmddhh - $epocnow2 - $datestr :: $epoc"

mailstr=""
prev=""
lf=$'\x0a'
while (( epoc < epocnow ))
do
        file=$(printf "%(%Y%m%d/%H)T" "#$epoc")
        path=$(printf "%(%Y%m%d)T" "#$epoc")
        print "$path $file"
        [ ! -d "$path" -a "$path" != "$prev" ] && prev=$path && mailstr="$mailstr${lf}path missing $path"
        [ ! -f "$file" ] && mailstr="$mailstr${lf}-file missing $file"
        (( epoc+=hour ))
done

smail "$mailstr"


Last edited by kshji; 02-26-2015 at 12:29 PM.. Reason: better ...
This User Gave Thanks to kshji For This Post:
# 5  
Old 02-26-2015
removed

Last edited by billabongjimmy; 02-27-2015 at 05:36 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Shell Programming and Scripting

Alert for missing file in directory

Deleting code (6 Replies)
Discussion started by: Adfire
6 Replies

3. Shell Programming and Scripting

Script to move all files in a dir into a certain dir

Hello all, I'm very new to shell scripting and need quite urgently to do this thing for my student job. I have a directory called "vectors" with a bunch of files all named ".vector". also i have for each of those files a directory with the name . I now want to move each of those *.vector files... (2 Replies)
Discussion started by: sherresh
2 Replies

4. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

5. Shell Programming and Scripting

Need a script to move the files from one dir to other other dir

Need a script to move the files from one dir to other dir and at the same time it has to read the log in the source dir. Please help me ASAP. (4 Replies)
Discussion started by: viswanathkishor
4 Replies

6. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

7. Shell Programming and Scripting

moving files from a dir in one machine to a dir in another machines

Hi, I am a unix newbie.I need to write a shell script to move my oracle READ WRITE datafiles from one serevr to another. I need to move it from /u01/oradata/W1KK/.. to /u01/oradata/W2KK, /u02/oradata/W1KK/.. to /u02/oradata/W2KK. That is, I actaully am moving my datafiles from one database to... (2 Replies)
Discussion started by: mathews
2 Replies

8. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

9. Shell Programming and Scripting

How to copy specified files from list of files from dir A to dir B

Hello, fjalkdsjfkldsajflkajdskl (3 Replies)
Discussion started by: pmeesara
3 Replies

10. Shell Programming and Scripting

Copying files and emailing them out

Hello everybody, I'm trying to create a script that will cd into a directory and then copy the file with yesterday's date on it and then cd into another directory doing the same thing. Afterwards, i'm trying to zip up the two files, and email them out to people. Can anyone help? thanks a... (1 Reply)
Discussion started by: jhofilena
1 Replies
Login or Register to Ask a Question