Script has no result!! -gt -lt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script has no result!! -gt -lt
# 8  
Old 11-23-2015
The name of the variable isn't the issue. The reason your latest script is working is that you separated the variables from the opening and closing square bracket pairs with spaces.

You might, however, try a simpler method:
Code:
#!/bin/ksh
uptime | ( read _ _ days _
	years=$((days / 365))
	echo "$(hostname) has been running $years to $((years + 1)) years ($days days)."
)

or, if you're using a 1993 or later version of ksh, you might want something more like:
Code:
#!/bin/ksh
uptime | ( read _ _ days _
	years=$((days / 365.25))
	printf '%s has been running about %.2f years (%d days).\n' \
	    "$(hostname)" "$years" "$days"
)


Last edited by Don Cragun; 11-23-2015 at 06:03 AM.. Reason: Add ksh93 sample with fractional years.
# 9  
Old 11-23-2015
Hi...

Perhaps this might be of help, manually using OSX 10.7.5, default bash terminal:-
Code:
Last login: Mon Nov 23 11:02:51 on ttys000
AMIGA:barrywalker~> up=`uptime |awk {'print$3'}`
AMIGA:barrywalker~> echo "$up"
1:54,
AMIGA:barrywalker~> _

Perhaps $up is NOT a number...
# 10  
Old 11-23-2015
Quote:
Originally Posted by wisecracker
Hi...

Perhaps this might be of help, manually using OSX 10.7.5, default bash terminal:-
Code:
Last login: Mon Nov 23 11:02:51 on ttys000
AMIGA:barrywalker~> up=`uptime |awk {'print$3'}`
AMIGA:barrywalker~> echo "$up"
1:54,
AMIGA:barrywalker~> _

Perhaps $up is NOT a number...
Hi wisecracker,
The output you're showing looks like it came from printing $5; not $3. The normal output from uptime on OS X 10.11.1 looks something like:
Code:
 3:14  up 32 days, 11:43, 10 users, load averages: 1.72 1.61 1.57

But, the output format could have changed between 10.7.5 and 10.11.1.
# 11  
Old 11-23-2015
Hi Don...

Hmmm, perhaps there is a discrepancy...
Code:
Last login: Mon Nov 23 11:34:21 on console
AMIGA:barrywalker~> uptime
11:37  up 4 mins, 2 users, load averages: 0.63 0.44 0.19
AMIGA:barrywalker~> _

# 12  
Old 11-23-2015
Quote:
Originally Posted by wisecracker
Hi Don...

Hmmm, perhaps there is a discrepancy...
Code:
Last login: Mon Nov 23 11:34:21 on console
AMIGA:barrywalker~> uptime
11:37  up 4 mins, 2 users, load averages: 0.63 0.44 0.19
AMIGA:barrywalker~> _

Ah, yes. It appears that the format changes depending on how long the system has been running.
# 13  
Old 11-23-2015
Hi Don...

11:37 up 4 mins, 2 users, load averages: 0.63 0.44 0.19

The third field is NOT 4 days but 4 minutes, and this could be considered a bug except the OP has put and upper and lower limit on his requirements.
This value could be from 1 to 59 and must be taken into account if there was not a lower limit...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to compare the current result with previous line result.?

Hi Gurus, I have requirement to compare current result with previous reuslt. The sample case is below. 1 job1 1 1 job2 2 1 job3 3 2 job_a1 1 2 job_a2 2 2 job_a3 3 3 job_b1 1 3 job_b2 2 for above sample file, GID is group ID, for input line, the job run... (1 Reply)
Discussion started by: ken6503
1 Replies

2. Programming

Query result from shell script

Hi, I wrote the below script to get the query result from a Syabase DB. isql -s -U **** -P **** SYBASE SERVERNAME USE ***(Database name in Sybase) @command.sql But im not getting the output. Can anyone help me on this (2 Replies)
Discussion started by: rohan G
2 Replies

3. Shell Programming and Scripting

Script to write result to a file

Hello, How can I run this script every 1 hour and save its result to result.txt ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' Regards Shaan (5 Replies)
Discussion started by: Shaan_Shaan
5 Replies

4. Shell Programming and Scripting

Script not spooling in result file

Hi everyone and nice to meet you :) I'm having some issues with a script I'm writing. It's probably most chaotic, I'm no ksh guru, but the idea is to extract an ID with that query, spool it into a file, and read that file making the ID a variable. This has to be done for every row extracted by... (10 Replies)
Discussion started by: Arkadia
10 Replies

5. Shell Programming and Scripting

Use the print result of a script as an argument

Hi all, Say I have a script named script.sh. What it does is to print a line like "abc" #! /usr/bin/ksh print "abc" I would like to pass this value to an external variable, var1="script.sh" However when I echo $var1 I got "script.sh" itself instead of the result? Thanks (3 Replies)
Discussion started by: isaacniu
3 Replies

6. Shell Programming and Scripting

shell script - unexpected result

I hv a file --am executing a script which is giving me unexpected results COntents of file: f1 CMT_AP1_CONT:/opt/sybase/syboc125:150:ASE12_5::Y:UX: CMT_AP1:/opt/sybase/syboc125:150:ASE12_5::Y:UX f1.tmp CMT_AP1_CONT:/opt/sybase/syboc125:150:ASE12_5::Y:UX:... (2 Replies)
Discussion started by: rajashekar.y
2 Replies

7. Shell Programming and Scripting

shell script result to file

Since I'm not an expert in shell scripting, I have question on sending script result to file. I have script like this... if condition=0: then echo "service is not running" | mail -s "Server Status" uname@companyname fi sleep 10 if configtion=1: then echo "service is not running" | mail -s... (3 Replies)
Discussion started by: s_linux
3 Replies

8. Shell Programming and Scripting

get result from database into shell script

hi, I have a script that will logon to a database siebel and do the select query and then get the result in command prompt of unix.Below the script. #!/bin/ksh . $HOME/conf/systemProperties/EnvSetup.properties #set -x while read i do echo $i connect1=`sqlplus -silent... (1 Reply)
Discussion started by: ali560045
1 Replies

9. Shell Programming and Scripting

Could any one tell me how to do get result in fraction in shell script

Could any one tell me how to do get result in fraction in shell script. I am using expr for division of 2 number but it is giving Quitent. I need it in full fraction value. please helpp. how to do it using "dc" or "bc" (5 Replies)
Discussion started by: Neerajjaiswal
5 Replies

10. UNIX for Dummies Questions & Answers

Parameter from result of a script

Hi, I have a situation where I need a parameter value to pick from a file can I use it in this way File_name.txt contains names of files a.jpg b.jpg c.jpg now I want to assign the file name to parameter FTP_INPUT_FILE=a.jpg for first run once it is processed we can delete onve they are... (2 Replies)
Discussion started by: mgirinath
2 Replies
Login or Register to Ask a Question