1825160 Members
2275 Online
109679 Solutions
New Discussion

run script in HPUX

 
SOLVED
Go to solution
Naj
Valued Contributor

run script in HPUX

Hi Expert,

 

Please advice me how to execute this script in hpux 11.31 ?

I tried to vi and paste this script, but it won't and got some minor error

 

!/bin/sh
echo " "
print " We are going to calculate the physical memory and the available memory in this HPUX System."
typeset -i mem=$(grep Physical /var/adm/syslog/syslog.log | awk '{print $7}')
print $(hostname) has $mem bytes memory .+- $(( $mem /1024 )) mb
echo " "
print " This is the available memory ."
typeset -i mem1=$(grep Physical /var/adm/syslog/syslog.log | awk '{print $13}')
print $(hostname) has $mem1 bytes of available memory .+- $(( $mem1 /1024 )) mb
echo " "

Thanks


____________________________________________
:: Really appreciate if you could assign some points.
:: Don't know how to assign point? Click the KUDOS! star!
4 REPLIES 4

Re: run script in HPUX

 

Syntactically, the only major problem with this script is a missing "#" symbol at the start of the first line - cut and paste the following and it should run fine. Oh and also those values will be in KB, not Bytes

 

#!/bin/sh
echo " "
print " We are going to calculate the physical memory and the available memory in this HPUX System."
typeset -i mem=$(grep Physical /var/adm/syslog/syslog.log | awk '{print $7}')
print $(hostname) has $mem KB memory .+- $(( $mem /1024 )) MB
echo " "
print " This is the available memory ."
typeset -i mem1=$(grep Physical /var/adm/syslog/syslog.log | awk '{print $13}')
print $(hostname) has $mem1 KB of available memory .+- $(( $mem1 /1024 )) MB
echo " "

 

Of course that doesn't mean this is a good script! As a method for determining the amount of memory on a system just looking in syslog.log is not by any means reliable, as this log can be rotated or truncated meaning the information from boot time is no longer available.

 

And of course the value you calculate for "available memory" is meaningless, as it just tells you how much memory was available when the system booted, not how much is available (presumably you want to know "free" memory?) when the script is run. A quick and dirty, but more reliable script might be something like this:

 

#!/bin/sh
echo " "
print " We are going to calculate the physical memory and the available memory in this HPUX System."
mem=$(machinfo | grep ^Memory: | awk '{ print $2 }')
print $(hostname) $mem MB Physical Memory
echo " "
print " This is the available (free) memory ."
typeset -i free_pages=$(vmstat | tail -1 | awk '{ print $5 }')
typeset -i page_size=$(kctune -P current base_pagesize | cut -f 2)
(( mem1 = ${free_pages} * ${page_size} ))
print $(hostname) has $mem1 bytes of available memory .+- $(( $mem1 /1024 )) mb
echo " "

 


I am an HPE Employee
Accept or Kudo
James R. Ferguson
Acclaimed Contributor

Re: run script in HPUX

Hi:

 

Does an error message like, "...line 1: !bin/sh: No such file or directory" suggest anything?

 

Shell scripts should begin with a "she-bang" line also known as the interpreter line.  The special sequence "#!" tells which interpreter program to run.  In HP-UX, '/bin/sh' is the so-called POSIX shell used by HP ('/usr/bin/sh' or '/sbin/sh' for root).  In many Linux systems, '/bin/sh' is symlinked to the Bash shell.

 

In you case, the missing hash mark meant that no she-bang was recognized.  By default, your script was executed with the same shell interpreter as your session and was otherwise syntatically valid as a POSIX (or even 'ksh') shell.

 

Regards!

 

...JRF...

Naj
Valued Contributor

Re: run script in HPUX

Thanks for the answering.. but im newbie in script. could you confirm me below are true step to execute?

 

1. #pwd

/root/home/root/myfolder/

2. #touch checkmem.sh

3.#vi checkmem.sh

4. paste script and save file

5.#pwd ; ls

root/home/root/myfolder/

checkmem.sh

6.#./checkmem.sh

output

 

Is it true?

Please confirm me

 

Thanks

 

BR

Naj

 

 

 

 

 

 

 


____________________________________________
:: Really appreciate if you could assign some points.
:: Don't know how to assign point? Click the KUDOS! star!
Dennis Handly
Acclaimed Contributor
Solution

Re: run script in HPUX

>2. #touch checkmem.sh

 

No need for this.

 

3.#vi checkmem.sh

 

>checkmem.sh

 

chmod a+x checkmem.sh  # make it executable

 

6.#./checkmem.sh

output

 

>Is it true?

 

Assuming you have a "#!" with your shell on the first line, yes.

You can also syntax check your script with:

sh -n checkmem.sh