script to autorestart if uptime greater than... help needed.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers script to autorestart if uptime greater than... help needed.
# 1  
Old 01-14-2005
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  
Old 01-14-2005
try this ....

uptime | cut -d "," -f 1 | tr -s " " | cut -d " " -f 4
# 3  
Old 01-14-2005
Complete script ....

if test `uptime | cut -d "," -f 1 | tr -s " " | cut -d " " -f 4` -gt 10 ; then
echo "yes"
fi
# 4  
Old 01-14-2005
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  
Old 01-14-2005
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  
Old 01-14-2005
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  
Old 01-14-2005
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to pull uid greater than 1000 from remote server

Hello, I am trying to get UID # greater than 1000 from all linux server, I tried this script getting this error message, someone please suggest. $for i in `cat hostlist.0709.org` ; do ssh -t $i 'awk -F':' "{ if($3 >= 1000) print $0 }" /etc/passwd ' >> output ; done $ cat output hostname1... (4 Replies)
Discussion started by: bobby320
4 Replies

2. Shell Programming and Scripting

Shell Script if $2 is greater than 10 then echo $1

Hi, I have a file output.txt 3258 14 32647 10 32649 10 32650 10 32651 10 32652 10 32653 10 32654 10 32655 10 32656 10 32515 09 32478 08 32555 08 35888 08 (4 Replies)
Discussion started by: amit_spl
4 Replies

3. Shell Programming and Scripting

Uptime script

How to write a shell script which can generate server uptime report from the UNIX servers? (3 Replies)
Discussion started by: paventhan
3 Replies

4. Shell Programming and Scripting

Expect script help needed- script failing if router unavailable

Hey all. Sometimes I'm tasked to change some router configs for the entire network (over 3,000 Cisco routers). Most of the time its a global config parameter so its done with a loop and an IP list as its the same configuration change for all routers. This is working OK. However, sometimes an... (3 Replies)
Discussion started by: mrkz1974
3 Replies

5. Shell Programming and Scripting

Extract the uptime from the output of the uptime command

Hi! I want to extract the uptime from the output of the uptime command. The output: 11:53 up 3:02, 2 users, load averages: 0,32 0,34 0,43 I just need the "3:02" part. How can I do this? Dirk (6 Replies)
Discussion started by: Dirk Einecke
6 Replies

6. Homework & Coursework Questions

linux service script for storing uptime

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Can you please advise a script for the following: write linux service named system_up_duration .This service... (6 Replies)
Discussion started by: fed.linuxgossip
6 Replies

7. Shell Programming and Scripting

linux service script for storing uptime

Hi, Can you please advise a script for the following: write linux service named system_up_duration .This service will create one file named uptime in directory ‘/temp/'. In this file the service will store the total time for which the system is up and running .The file will be updated after... (1 Reply)
Discussion started by: fed.linuxgossip
1 Replies

8. Shell Programming and Scripting

shell script to check file size greater than 50M

Hi All, OS:AIX 64 bits using korn shell. Requirement: shell script to check file size greater than 50M and send mail alert. Thanks for your time! Regards, (3 Replies)
Discussion started by: a1_win
3 Replies

9. IP Networking

Automate FTP process and autorestart on link failure

Hi Guys, i have this lil challenge; i am to implement an automated script that searches/scans a directory for files then picks and sends this files to a very remote server via an ftp link. the challenge here is that the ftp link fails due to netwrk issues maybe; i therefore need to develop... (5 Replies)
Discussion started by: sdcoms
5 Replies

10. Shell Programming and Scripting

calculate server uptime in % (99.98), using ksh script

Let me preface by saying, I have looked through many threads that deal with keep the decimal, however I'm not sure that any one resolution meets my needs, ok, ok, they could. So maybe it's just that I am not understanding the resolution - therefore I am posting a new thread. myknowledgebase=at... (2 Replies)
Discussion started by: cml2008
2 Replies
Login or Register to Ask a Question