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.
# 8  
Old 01-14-2005
No spaces around the equals sign. And display the variable to see what is going on...
Code:
    var=`uptime | cut -d "," -f 1 | tr -s " " | cut -d " " -f 4`
    echo var = $var
    if test $var -gt 10
    then
         echo "Yes"
    fi

# 9  
Old 01-19-2005
Quote:
Originally Posted by Perderabo
No spaces around the equals sign. And display the variable to see what is going on...
Code:
    var=`uptime | cut -d "," -f 1 | tr -s " " | cut -d " " -f 4`
    echo var = $var
    if test $var -gt 10
    then
         echo "Yes"
    fi

var returns nothing... exactly this:

Code:
var =

if i set var = "test" then it returns "test" but it doesn't return the function if set to that. this seems so trivial but i appreciate your help!
# 10  
Old 01-19-2005
You may need an OS X expert to get this going. But we should at least be able to see where it is failing...

Code:
var=`uptime`
echo step 1  var = $var
var=`uptime | cut -d "," -f 1`
echo step 2  var = $var
var=`uptime | cut -d "," -f 1 | tr -s " "`
echo step 3  var = $var
var=`uptime | cut -d "," -f 1 | tr -s " " | cut -d " " -f 4`
echo step 4  var = $var

# 11  
Old 01-19-2005
Try Perderabo's suggestions, but if you can't get it to work with cut, you may want to use awk, which is my preferred method for pulling out columns.

Code:
var=`uptime | awk -F, '{print $1}'| awk '{print $3}'`

Worked for me in HP-UX. You may have to switch the column numbers, depending on what output you get from uptime in OSX. I created a script called uptme.

Code:
user[/myhome/user]>cat uptme

var=`uptime | awk -F, '{print $1}'| awk '{print $3}'`
echo var = $var
    if test $var -gt 10
    then
         echo "Yes"
    fi


user[/myhome/user]>uptme
var = 20
Yes

# 12  
Old 01-19-2005
thanks guys. i got it working.
 
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