Sponsored Content
Top Forums Shell Programming and Scripting parsing simple output help needed Post 302532352 by graysky on Monday 20th of June 2011 05:08:47 PM
Old 06-20-2011
MySQL parsing simple output help needed

Goal: for each hostname (mars, phobos, and deimos grab the value of state = in a variable so I work on it further.

I figured I'll need to use sed to find the target host name, then substitute the "linefeed and what I am assuming is a tab state =" to null and grab the state (in this case "free") into a variable. What I don't know how to do is: see the output of the command showing all non-printable characters so I can setup a grep or sed line. How is this accomplished in bash?
Code:
$ pbsnodes
mars
     state = free
     np = 4
     ntype = cluster
     status = rectime=1308479899,varattr=,jobs=0.localhost.localdomain,state=free,netload=1638547057,
gres=,loadave=2.69,ncpus=4,physmem=8195892kb,availmem=7172508kb,totmem=8195892kb,
idletime=24772,nusers=1,nsessions=5,sessions=1333 1349 1353 1388 9095,
uname=Linux mars 2.6.39-ck #1 SMP PREEMPT Sat Jun 18 14:19:01 EDT 2011 x86_64,opsys=linux
     mom_service_port = 15002
     mom_manager_port = 15003
     gpus = 2

phobos
     state = free
     np = 2
     ntype = cluster
     status = rectime=1308479933,varattr=,jobs=,state=free,netload=1085755815,
gres=,loadave=2.84,ncpus=2,physmem=4019704kb,availmem=5753552kb,totmem=6116852kb,
idletime=7324,nusers=2,nsessions=6,sessions=1565 1562 1691 1716 1737 1851,
uname=Linux phobos 2.6.37-ck #1 SMP PREEMPT Sun Apr 3 17:16:35 EDT 2011 x86_64,opsys=linux
     mom_service_port = 15002
     mom_manager_port = 15003
     gpus = 1

deimos
     state = free
     np = 2
     ntype = cluster
     status = rectime=1308479890,varattr=,jobs=2.localhost.localdomain,state=free,netload=527239670,
gres=,loadave=0.52,ncpus=2,physmem=4057808kb,availmem=3955624kb,totmem=4057808kb,
idletime=644,nusers=1,nsessions=1,sessions=865,
uname=Linux deimos 2.6.39-ck #1 SMP PREEMPT Sat Jun 11 12:36:21 EDT 2011 x86_64,opsys=linux
     mom_service_port = 15002
     mom_manager_port = 15003
     gpus = 1

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

simple script help needed

I am relatively new to *nix and have set up a small home network with a red hat server, what i would like to do is write a small script to check to see if a computer is connected by using the ip address of the computer. can get the ping to return but cant get the echo line working. the output i... (3 Replies)
Discussion started by: nobius
3 Replies

2. Programming

newbie to unix programming in C, needed a few simple prgs on these functions!

Hi all, I am a newbie to unix programming using C.. So i would like to have a few simple C programs to start off with.. I wanted programs on learning , abort,kill and raise,alarm and pause,I would also like to know how to use the vfork() in a prg It would be really great if i can have... (1 Reply)
Discussion started by: wrapster
1 Replies

3. Shell Programming and Scripting

Parsing xml using awk - more help needed

As per another thread - https://www.unix.com/shell-programming-scripting/81027-how-can-i-parse-xml-file-2.html I am using the following to extract the Subaccid and RecAccTotal from the xm file below awk -v v=SubaccId -F'' '$2==v{s=$3;getline;a+=$3}END {for (i in a)print v,i,a}' file Can... (6 Replies)
Discussion started by: frustrated1
6 Replies

4. Shell Programming and Scripting

Simple Batch File Help Needed

I have access to a large unix parallel computing cluster. To submit jobs I simply run a script called "submit" followed by options relevant to that particular job. Very simple and easy, "submit" can be run from any directory. I am trying to make a batch file that automatically runs "submit"... (5 Replies)
Discussion started by: cpabrego
5 Replies

5. UNIX for Dummies Questions & Answers

Help needed to run simple java program in linux

Hi guys , This is the first time i m running java application inside linux. i have installed jdk-6u20-linux-i586-rpm.bin jre-6u20-linux-i586-rpm.bin in my linux machine. and set JAVA_HOME and JRE_HOME variables respectively. # echo $JAVA_HOME /usr/java/jdk1.6.0_20/ # echo $JRE_HOME... (6 Replies)
Discussion started by: pinga123
6 Replies

6. Shell Programming and Scripting

Help needed for parsing large XML with awk.

My XML structure looks like: <?xml version="1.0" encoding="UTF-8"?> <SearchRepository> <SearchItems> <SearchItem> ... </SearchItem> <SearchItem> ... ... (1 Reply)
Discussion started by: jasonjustice
1 Replies

7. Shell Programming and Scripting

XML parsing using nawk help needed

i need one help, below is one more xml file with diff pattern i tried it but dint get it , iam sure its a peice of cake for you guys. <xn:MeContext id="LSVLKY001"> <xn:ManagedElement id="1"> <un:RncFunction id="1"> <un:UtranCell... (2 Replies)
Discussion started by: tech_frk
2 Replies

8. Shell Programming and Scripting

Urgent simple script needed

Good Day All, I need your urgent support to get the following script (bash), (it should be as simple as possible please) : The script will check the .csv file( attached example) The script will generated 3 files from the initial one. The script must check one field “NEType”, and then ... (2 Replies)
Discussion started by: engkemo2002
2 Replies

9. Shell Programming and Scripting

Simple if statement help needed please

if ]; then echo "successssssssssssssssssss" $filename = "<font color='red'>$i</font>" else echo "failureeeeeeeeeeeeeeeeeeeee" $filename = "$i" fi; I'm just trying to see is this - read a file name and highlight... (2 Replies)
Discussion started by: vmanda
2 Replies

10. Shell Programming and Scripting

Simple awk script needed

but I'm stumped...please help I have a file like this....... 1000 1 34 1000 10 34 1000 11 35 1000 20 35 1000 21 36 1000 30 36 2000 1 34 2000 10 34 which I would like printed out as 40 lines 1000 1 34 1000 2 34 1000 3 34 1000 4 ... (2 Replies)
Discussion started by: garethsays
2 Replies
SHELL-QUOTE(1)						User Contributed Perl Documentation					    SHELL-QUOTE(1)

NAME
shell-quote - quote arguments for safe use, unmodified in a shell command SYNOPSIS
shell-quote [switch]... arg... DESCRIPTION
shell-quote lets you pass arbitrary strings through the shell so that they won't be changed by the shell. This lets you process commands or files with embedded white space or shell globbing characters safely. Here are a few examples. EXAMPLES
ssh preserving args When running a remote command with ssh, ssh doesn't preserve the separate arguments it receives. It just joins them with spaces and passes them to "$SHELL -c". This doesn't work as intended: ssh host touch 'hi there' # fails It creates 2 files, hi and there. Instead, do this: cmd=`shell-quote touch 'hi there'` ssh host "$cmd" This gives you just 1 file, hi there. process find output It's not ordinarily possible to process an arbitrary list of files output by find with a shell script. Anything you put in $IFS to split up the output could legitimately be in a file's name. Here's how you can do it using shell-quote: eval set -- `find -type f -print0 | xargs -0 shell-quote --` debug shell scripts shell-quote is better than echo for debugging shell scripts. debug() { [ -z "$debug" ] || shell-quote "debug:" "$@" } With echo you can't tell the difference between "debug 'foo bar'" and "debug foo bar", but with shell-quote you can. save a command for later shell-quote can be used to build up a shell command to run later. Say you want the user to be able to give you switches for a command you're going to run. If you don't want the switches to be re-evaluated by the shell (which is usually a good idea, else there are things the user can't pass through), you can do something like this: user_switches= while [ $# != 0 ] do case x$1 in x--pass-through) [ $# -gt 1 ] || die "need an argument for $1" user_switches="$user_switches "`shell-quote -- "$2"` shift;; # process other switches esac shift done # later eval "shell-quote some-command $user_switches my args" OPTIONS
--debug Turn debugging on. --help Show the usage message and die. --version Show the version number and exit. AVAILABILITY
The code is licensed under the GNU GPL. Check http://www.argon.org/~roderick/ or CPAN for updated versions. AUTHOR
Roderick Schertler <roderick@argon.org> perl v5.16.3 2010-06-11 SHELL-QUOTE(1)
All times are GMT -4. The time now is 04:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy