The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 3 Weeks Ago
chinniforu2003 chinniforu2003 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 14
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
  #2 (permalink)  
Old 3 Weeks Ago
frans's Avatar
frans frans is offline
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 100
A self sheduling script (by using at) seems me the best. I use such a procedure to get hourly satellite images from a website)
Code:
# if the file has been updated (if the datestamp is newer than the previsously saved one)
# then save it and get the datestamp
# calculate the difference between actaul time and datestamp
# if the difference is too big (i.e. > 30 minutes) exit, error, report in logfile etc.
# calculate the time of the next check (15 minutes + 1 or 2 minutes delay depending on the precison of the update time and the delay between timestamp and availability of the file) (That will synchronize the checking with the updating)
# activate the differed launching of this script
# report in logfile
The advantage of at is that if the system is down at sheduled time it will launch the script at the next startup (not possible with cron)
Do tou have other suggestions ?
I can code that in bash if needed but yo
  #3 (permalink)  
Old 3 Weeks Ago
chinniforu2003 chinniforu2003 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 14
Scripting needed for newbie

Thanks For your reply

Could you please code for me since i am new to shell scripting
  #4 (permalink)  
Old 3 Weeks Ago
frans's Avatar
frans frans is offline
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 100
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
nothing more before 7:00 or 8:00 GMT
Code:
frans@localhost-$ sleep 8 hours

Last edited by frans; 3 Weeks Ago at 07:15 PM.. Reason: it's late
  #5 (permalink)  
Old 3 Weeks Ago
redhead's Avatar
redhead redhead is offline
Registered User
  
 

Join Date: Feb 2002
Location: Denmark
Posts: 67
Quote:
(not possible with cron)
How about the
Code:
@reboot
from crontab(5) ?
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0