Shell script to check for a Occurance


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to check for a Occurance
# 1  
Old 06-20-2013
Shell script to check for a Occurance

Hi All, I am very new to this forum and Unix too...
I need to create a script which has to check for a file's occurrence in a specified location for 4 hours and send out a email when ever the file has arrived.
It should also have a timer to send the status message for every 15 minutes if the file is not received.
Kindly request your help; I was able to complete till below:
Thanks,
=====================================
Code:
if [ ! -s /file_path/file_name* ];
then
echo "\n file is not available in /file_path folder \n
\n Regards" | mailx -s "file not received" @userid.com
else
echo "\n file is available in /file_path folder \n
\n Regards" | mailx -s "file arrived" @userid.com

=====================================

Last edited by Scrutinizer; 06-20-2013 at 04:17 PM.. Reason: code tags
# 2  
Old 06-20-2013
You could do something like:
Code:
 
#!/bin/ksh
S_EPOCH=$( date +"%s" )
while :
do
        C_EPOCH=$( date +"%s" )
        DIFF=$(( C_EPOCH - S_EPOCH ))
        if [ $DIFF -gt 14400 ]
        then
                print "Script ran for 4 hours. Exiting."
                exit 1
        fi
 
        if [ -f "/file_path/file_name" ]
        then
                print "File: /file_path/file_name received" | mailx -s "File Received" user@domain.com
                exit 1
        else
                print "File /file_path/file_name missing" | mailx -s "File Missing" user@domain.com
        fi
 
        print "Sleeping for 15 minutes..."
        sleep 900
done

# 3  
Old 06-20-2013
My script is below:
Code:
#!/bin/bash
now_time=$(date +%Y-%m-%d\ %H:%m:%S)
echo "***Start at: $now_time***"
i=0
while [ i -lt 16 ]
do
        if [ ! -e /path/to/filename ]
        then
                echo -e "The file is not available in /path/to folder.\n" | mailx -s "file not received." @userid.com
                sleep 900
                i=`expr $i + 1`
        else
                echo -e "The file is available in /path/to folder.\n" | mailx -s "file arrived." @userid.com
                break
        fi
done
future_time=$(date +%Y-%m-%d\ %H:%m:%S)
[ i -eq 16 ] && echo "Not received till the cows come home."
echo "***Finish at: $future_time***"

Remember replace the "/path/to" by the actual path and replace the "filename" by the actual name.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need shell script to check file

Hi Experts, I am not good in writing script. Just stared.I am looking for shell script to check following parameters. 1) Number of files on remote Linux SUSE server.- Any directory and sub directory. 2) I should define number of files in script. Files should be variable. 3) Age of... (2 Replies)
Discussion started by: ApmPerfMonitor
2 Replies

2. Shell Programming and Scripting

Bash shell script to check if script itself is running

hi guys we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
Discussion started by: hedkandi
8 Replies

3. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

4. Shell Programming and Scripting

Shell script to check numbers!

Hello All, I have 3 types of files. The names of which starts with P,I,M like P********* D********* M********* now I need to do some operations witht hese files.. so if file name starts with P or p then do the operation for P file... fi else (20 Replies)
Discussion started by: smarty86
20 Replies

5. Shell Programming and Scripting

Help with shell script to check the condition.

:) Hi, I want to script for this scenerio, OSR Settings Scenario : We are looking to find all the *.a files from the following locations in the filesystem of a server. OSR Directories /etc /bin /usr/bin /usr/sbin /var/adm These *.a files should have the permissions on... (12 Replies)
Discussion started by: sakthilinux
12 Replies

6. Shell Programming and Scripting

IP check with shell script

hi guys ..newbie here i would like to create a simple script tat will detect wether the machine has IP or not ... but it seems that my script doesnt really work it kept rebooting... i set this script during boot so that it will check else it will reboot it a shell script thou... ... (5 Replies)
Discussion started by: bladez
5 Replies

7. Shell Programming and Scripting

How to insert values in 1st occurance out of two occurance in a file

Hi I have a file which contains the following two lines which are same But I would like to insert the value=8.8.8.8 in the 1st occurance line and value=9.9.9.9 in the 2nd occurance line. <parameter name="TestIp1" value=""> <parameter name="TestIp1" value=""> Please suggest (1 Reply)
Discussion started by: madhusmita
1 Replies

8. Shell Programming and Scripting

script check the users in SHELL ?

could you please find a solution for this script that checks if any of a list of users given on the command line is logged in. For each user the script should say whether this user is logged in or not. The script prints an error message if no parameter is given. And ask the user to enter a name... (3 Replies)
Discussion started by: anything
3 Replies

9. Shell Programming and Scripting

check my first shell script

I have written the below script to determine whether a string is palindrome or not ? But its not working, any help to debug it ? I am new to this forum but when I searched for my question, I found that many people refused to answer this question thinking that its Homework question, Therefore I... (2 Replies)
Discussion started by: gridview
2 Replies

10. Shell Programming and Scripting

check in unix shell script so that no one is able to run the script manually

I want to create an automated script which is called by another maually executed script. The condition is that the no one should be able to manually execute the automated script. The automated script can be on the same machine or it can be on a remote machine. Can any one suggest a check in the... (1 Reply)
Discussion started by: adi_bang76
1 Replies
Login or Register to Ask a Question