Register
It is currently Thu Oct 02, 2014 6:26 am

Need help creating uptime shell script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sun Mar 07, 2010 12:01 am   

Joined: Sun Jul 06, 2008 7:43 pm
Posts: 6
I would like input on how I would go about crating an uptime script. I know there is the uptime command yet I am tasked to produce something that writes to file every minute to make sure the mounted file systems are still available. Here is what I am thinking:

REQUIREMENTS:
-check to make sure that exported shares are available
-create an uptime folder on each share
-create a daily file and inside the file should be a per minute string that might say system is up i.e. Up as of 1:02:03
-records a per minute "up as of <time> from 00:00 to 24:00 then resets for the following day
-each day is a new file

PLAN(I have not quite figured out how to write it yet). Here is kinda what I think:

Let's say I have 2 exported share /mnt/data; /mnt/data2
-check if the uptime directory exist; if not create it
-execute touch /mnt/data/uptime/file_for_the_day on each share
-if touch is successful echo to file_of_the_day up as of date +"%H:%M:%S"


Top
 Profile YIM  
 PostPosted: Sun Mar 07, 2010 12:55 am   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
You can have cron call a script every minute. The following script handles one of the mounted systems (it's easy to make it handle both):
Code:
#!/bin/bash

UPTIME_DIR1=/mnt/data

if [ ! -d "$UPTIME_DIR1" ]; then
    mkdir "$UPTIME_DIR1"
    if [ $? -ne 0 ]; then
        exit 1
    fi
fi

filename=`date +%m_%d_%Y`
date +"%D - %H:%M:%S" >> "$UPTIME_DIR1/$filename"
if [ $? -ne 0 ]; then
    exit 1
fi
exit 0


And then for cron (use 'crontab -e' to edit):
Code:
# m h dom mon dow  comand
   * * * * * /usr/bin/uptime.sh


- thobbs


Top
 Profile  
 PostPosted: Wed Mar 31, 2010 12:38 am   

Joined: Wed Mar 31, 2010 12:17 am
Posts: 4
Quote:
Here is a uptime script we wrote in class for 20 minutes once a minute it writes to the file


Code:
#!/bin/bash

# logs uptime prepended by today's date
x=0
while ((x<=20));do
$x>>/home/wm/Documents/"bash class"/log.txt
date +%Y/%m/%d>>/home/wm/Documents/"bash class"/log.txt   
         # uses ISO             # date format, not US, for easy sorting
uptime>>/home/Documents/log.txt
users>>/home/Documents/log.txt
sleep 60   # 60 is one minute
let x++
done



Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP