![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| scripting newbie... some help please? | jmd9qs | Shell Programming and Scripting | 13 | 03-03-2009 05:31 PM |
| Hi Needed help for Unix Newbie | prashant_jsw | Shell Programming and Scripting | 2 | 01-04-2009 08:04 AM |
| scripting newbie needs help | irishluck66 | Shell Programming and Scripting | 0 | 05-23-2008 12:22 PM |
| Scripting Newbie | Kymmers7 | Shell Programming and Scripting | 5 | 10-19-2007 11:52 AM |
| Newbie help needed connecting to Internet | FattyLumpkin | UNIX Desktop for Dummies Questions & Answers | 3 | 07-05-2002 07:58 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Scripting needed for newbie
Hi,
I am newbie in shell scripting I have a file name like simple.txt which comes from Mainframe systems onto windows dir every 15 minutes daily. File name is same. Every 15 minutes it updates. I need to write shell script to check if the file arrived every 15 min or not. If the new file has not arrived after 30 min, I need to exit and send message and also generate log file with start-time and end-time. At the end of the day I also need to generate another log with Start time and end-time as fields. Please help me in scripting |
|
|||||
|
Here code that doesn't use at but sleep; it doesn't need external storage of data but runs continuously.
Wat i suggest is to log evrything in the beginning by echoing the variables to the logfile, mainly the Delay to see if you have to adjust the tolerance at another value. I let you code the different logs you want to make (i can help u) but try first the functioning of the script. You can add lines for monitoring purpose by echoing commands or start the script with the -x parameter like bash -x simple.sh Code:
#!/bin/bash
File1=simple.txt # The file to check
LogFile=simple.log # The log file
DelayMax=30 # Timeout delay
Tolerance=2
# BEGIN ##############################
while true
do
StampNow=$(date +%s)/60 # stamp in minutes
StampFile=$(date -r "$File1" +%s)/60
let Delay=$StampNow-$StampFile
if [ $Delay -gt $DelayMax ]
then
echo "$(date) : ERROR : Timeout" >> $LogFile
# etc.
exit 1
elif [ $StampFile -eq $StampOld ]
then
sleep $Tolerance minutes # Retry a bit later
else
StampOld=$StampFile
let NewDelay=$StampNow-$StampFile+15+$Tolerance # To synchronize with the updating
sleep $NewDelay minutes
fi
done
![]() Code:
frans@localhost-$ sleep 8 hours Last edited by frans; 3 Weeks Ago at 07:15 PM.. Reason: it's late |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|