The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Automate FTP process and autorestart on link failure sdcoms IP Networking 5 08-14-2008 06:45 PM
vmstat vs uptime? gfhgfnhhn UNIX for Advanced & Expert Users 2 08-28-2006 05:06 AM
uptime qfwfq UNIX for Dummies Questions & Answers 1 06-16-2006 02:38 PM
Getting uptime Freefall UNIX for Dummies Questions & Answers 2 06-17-2003 05:10 PM
uptime xiamin UNIX for Dummies Questions & Answers 2 02-19-2003 04:51 AM

Closed Thread
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 01-14-2005
alternapop alternapop is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 13
script to autorestart if uptime greater than... help needed.

i'm trying to write a script that will check my os x box for uptime and autorestart gracefully if the uptime is greater than a certain number of days.

thus far i have this:

if uptime | cut -d ',' -f 1 | cut -d ' ' -f 4 -gt 10 ; then
echo "yes"
fi

this doesn't work and i've tried brackets, parenthesis, etc to get it to work. can someone direct me to the correct syntax please?
thanks!
  #2 (permalink)  
Old 01-14-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
try this ....

uptime | cut -d "," -f 1 | tr -s " " | cut -d " " -f 4
  #3 (permalink)  
Old 01-14-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
Complete script ....

if test `uptime | cut -d "," -f 1 | tr -s " " | cut -d " " -f 4` -gt 10 ; then
echo "yes"
fi
  #4 (permalink)  
Old 01-14-2005
alternapop alternapop is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 13
Quote:
Originally Posted by bhargav
Complete script ....

if test `uptime | cut -d "," -f 1 | tr -s " " | cut -d " " -f 4` -gt 10 ; then
echo "yes"
fi
sorry but it doesn't work as expected. cut returns "days"

removing the middle part to return the value i'm looking for still doesn't work either:

if test `uptime | cut -d "," -f 1 | cut -d " " -f 4` -gt 10 ; then
echo "yes"
fi

it doesn't return "yes". i'm using bash.
thanks
  #5 (permalink)  
Old 01-14-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
What unix u have ...
for AIX ... See the following working for me ...
$ uptime | cut -d "," -f 1 | tr -s " " | cut -d " " -f 4
23

Can u try ... putting 3 instead 4 for the last cut

try the following and let me know ....
uptime | cut -d "," -f 1 | tr -s " " | cut -d " " -f 3
  #6 (permalink)  
Old 01-14-2005
alternapop alternapop is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 13
Quote:
Originally Posted by bhargav
try the following and let me know ....
uptime | cut -d "," -f 1 | tr -s " " | cut -d " " -f 3
using apple OS X... the uptime line works by itself in the terminal. when i add it to the if-then script and call the script from the terminal it doesn't work. i'm guessing it has something to do with the quotes or possibly bracketing it right.
  #7 (permalink)  
Old 01-14-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
1)which quote are u using ? Is it the one below ESC key on the key-board.
You have to use that quote only.

2) If that does n't work ....
put that whole command to variable and include that variable
for ' if ' syntax.

var = `uptime | cut -d "," -f 1 | tr -s " " | cut -d " " -f 4`
if test $var -gt 10
then
echo "Yes"
fi

3) Check 'if' syntax as per apple OS.
Closed Thread

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 08:55 PM.


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