print system("uname -n") is not working .Pls help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting print system("uname -n") is not working .Pls help
# 1  
Old 02-25-2011
print system("uname -n") is not working .Pls help

Code:
awk '{if ($1 == "State:" && $2 == "Okay") {print system("uname -n")}}'

---------- Post updated at 01:20 AM ---------- Previous update was at 01:19 AM ----------

it is printing uname -n instead of printing the output of the command

Last edited by Franklin52; 02-25-2011 at 03:48 AM.. Reason: Please use code tags
# 2  
Old 02-25-2011
You could use:

Code:
{ system( "uname -n" ) }

Without print. The stdout will go to your terminal.

If you need to manipulate that information further,
you could save it in an awk variable:

Code:
{ "uname -n" | getline sn }

The machine name will be stored in the sn variable.
# 3  
Old 02-25-2011
Question

Code:
awk '{if ($1 == "State:" && $2 == "Okay") {"uname -n"|getline sn; print $sn}}'

tried this it is not working.

Code:
awk '{if ($1 == "State:" && $2 == "Okay") {system( "uname -n" )}}'

this also is not working.


I work in KSH

Last edited by radoulov; 02-25-2011 at 07:12 AM.. Reason: Code tags, please!
# 4  
Old 02-25-2011
In the first case it should be:

Code:
print sn

Note that there is no dollar sign.

If the expression $1 == "State:" && $2 == "Okay" evaluates to true and the uname command is accessible and executable, the second one should work.
# 5  
Old 02-25-2011
Code:
#metastat -t|grep State|awk '{if ($1 == "State:" && $2 == "Okay") {"uname -n"|getline sn; print sn}}'
awk: syntax error near line 1
awk: illegal statement near line 1
 # metastat -t|grep State |awk '{if ($1 == "State:" && $2 == "Okay") {system( "uname -n" )}}'
# metastat -t|grep State |awk '{if ($1 == "State:" && $2 == "Okay"){print "Hi"}}'
Hi
Hi
Hi
Hi
# metastat -t|grep State |awk '{if ($1 == "State:" && $2 == "Okay"){print "Hi"}}'
Hi
Hi
Hi
Hi
#

copied from terminal..

---------- Post updated at 06:23 AM ---------- Previous update was at 06:21 AM ----------

yes uname works .

Last edited by radoulov; 02-25-2011 at 07:22 AM.. Reason: Code tags, please!
# 6  
Old 02-25-2011
Could you post an example output from memstat -t?

---------- Post updated at 01:35 PM ---------- Previous update was at 12:40 PM ----------

You should use nawk or /usr/xpg4/bin/awk on Solaris.
# 7  
Old 02-25-2011
# memstat -t
ksh: memstat: not found
XXXXXX:/ # uname -n
XXXXXX

---------- Post updated at 08:09 AM ---------- Previous update was at 08:07 AM ----------

nawk works
thanks a lot Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

What does "force devmap reload" as in "multipath -r" means for my system and stability of my system?

Cannot present unpresented disks back again. On a test server tried this as a solution "multipath -r" and it worked. Too worried to try it in production before I know all the information. Any info would be appreciated! Also some links to the documentation on this specific issue could help a... (1 Reply)
Discussion started by: jsteppe
1 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

Why awk print is strange when I set FS = " " instead of FS = "\t"?

Look at the following data file(cou.data) which has four fields separated by tab. Four fields are country name, land area, population, continent where it belongs. As for country name or continent name which has two words, two words are separated by space. (Data are not accurately... (1 Reply)
Discussion started by: chihuyu
1 Replies

4. Shell Programming and Scripting

awk "date" and "system" command

Hello experts! I need your help please I have a file.txt of which I want to extract 3rd and 4th columns with date with the form e.g.: 2016-11-25 03:14:50and pass them to "date" command, but also append the 9th column in a file as well. So I want to execute date -d '2016-11-25 03:14:50' ... (2 Replies)
Discussion started by: phaethon
2 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Solaris

How to check "faulty" or "stalled" print queues - SAP systems?

Hi all, First off, sorry for a long post but I think I have no other option if I need to explain properly what I need help for. I need some advise on how best to check for "faulty" or "stalled/jammed' print queues. At the moment, I have three (3) application servers which also acts as print... (0 Replies)
Discussion started by: newbie_01
0 Replies

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. Shell Programming and Scripting

"Print" not working in script

Hello everybody, I've gotten a script together that is designed to open a .bin file and read it 32 bits at a time and then add it to the checksum. However, the only issue that I have is that it will not print anything at the end. Can anyone help me? Also, is the & symbol used for restraining... (2 Replies)
Discussion started by: TeamUSA
2 Replies

9. Shell Programming and Scripting

if [[ "$(uname)" = "SunOS" ]]

What does the following script do? if ] ; then PATH="/usr/xpg4/bin:${PATH}" if ] ; then alias expr="/usr/ucb/expr" fi fi (1 Reply)
Discussion started by: neeto
1 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question