Host name in front of ps output


 
Thread Tools Search this Thread
Operating Systems Solaris Host name in front of ps output
# 1  
Old 03-19-2014
Host name in front of ps output

hello All. I am working on something that should be really simply.
It turns out that its not. I am trying to produce output to list the hostname along with all the current running programs.

the script im using is:
Code:
for PS in `ps -Ao "user,args" | cut -d' ' -f1,2`
do
 echo "`uname -n`, $PS" 
done

The desired output would look something like this:
Code:
host name, user, /some/dir/program
 
TRS0021, jblow, /usr/bin/vmstat 60 140

Nothing seems to be working for me. either the output comes out on several lines such as:
Code:
TRS0021, jblow
TRS0021 /usr/bin/vmstat 
TRS0021,60 
TRS0021,140

Or the output comes out in some other undesirable form.

Any one have any ides?
# 2  
Old 03-19-2014
Sorry, let me try again. How about something like:
Code:
hostname=$(uname -n)
ps -Ao "user,args" | while read line
do      printf "%s\t%s\n" "$hostname" "$line"
done


Last edited by Don Cragun; 03-19-2014 at 02:40 PM.. Reason: Misread original post…
# 3  
Old 03-19-2014
Try changing the IFS variable, Something like this:
Code:
ifso=$IFS; IFS=""; for PS in `ps`; do echo "`uname -n`, $PS"; done; IFS=$ifso;

# 4  
Old 03-19-2014
Code:
[ -z "$HOST" ] && HOST=`uname -n | cut -f1 -d.`
ps -eo user,args |
while read user args
do
  echo "$HOST, $user, $args"
done

# 5  
Old 03-19-2014
Quote:
Originally Posted by Don Cragun
Sorry, let me try again. How about something like:
Code:
hostname=$(uname -n)
ps -Ao "user,args" | while read line
do      printf "%s\t%s\n" "$hostname" "$line"
done

Hi the output from this script is:
Code:
root /var/adm/perfmgr/bin/srmSUN -vunlep
root sh -c /usr/bin/iostat -x 60 1440
root /usr/sbin/cron

So on and so forth.....

Id like it to be
Code:
hostname, root, /var/adm/perfmgr/bin/srmSUN -vunlep
hostname, root, sh -c /usr/bin/iostat -x 60 1440
hostname, root, /usr/sbin/cron

---------- Post updated at 01:19 PM ---------- Previous update was at 01:15 PM ----------

Quote:
Originally Posted by MadeInGermany
Code:
[ -z "$HOST" ] && HOST=`uname -n | cut -f1 -d.`
ps -eo user,args |
while read user args
do
  echo "$HOST, $user, $args"
done


PERFECT!!!!!

.... i LOVE YOU. CAN YOU EPXPLAIN THE PORTION
Code:
[ -z "$HOST" ] && HOST

Also how do i mark this as resolved?
# 6  
Old 03-19-2014
This line is only for portability (define HOST if not yet defined); you can omit it on Linux/bash.
Likewise ps -eo is supposed to work everywhere, while ps -Ao is Linux-only.

---------- Post updated at 03:14 PM ---------- Previous update was at 01:24 PM ----------

Just seeing that Solaris also has ps -Ao.
Seems even be demanded by Posix.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Output top line for each unique host

Hi All, Please can you help with the output whole line for each host (column 3) and the top line of column 9 - the lastest only What is being outputted 243272484 3 nbmedln1p03 LDN_TEST_UX_JM 1488198368 0000000007 1 INC_1MTH 0 ********** 243272492 3 nbmedln1p03 LDN_TEST_UX_JM... (10 Replies)
Discussion started by: Junes
10 Replies

2. UNIX for Dummies Questions & Answers

How to get/print host string only from tnsping output?

Hello All, I am using Linux OS. My idea is get the host name when we do tnsping in oracle. output of : tnsping DOELO01 TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 15-OCT-2015 20:20:05 Copyright (c) 1997, 2011, Oracle. All rights reserved. Used parameter files:... (2 Replies)
Discussion started by: Ariean
2 Replies

3. Solaris

Host name in front of pkginfo output

hello all I am trying to create a comma seperated file of the pkginfo command. The follwoing works pretty well. pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' ORS=', ' however, there are two issues. 1, For some reason it does not load into excel properly. It loads as... (7 Replies)
Discussion started by: busi386
7 Replies

4. Shell Programming and Scripting

rsh to many hosts the ftp output to single host

Hi guys. i need some help, i need to create a script in tcsh that rsh into all my hosts that we have at our business, then cd to a directory (cd /apps/users) then grab a file from the users folder and ftp it back to my windows machine. can someone please help? Kind regards. Brian Behrens (2 Replies)
Discussion started by: brian112
2 Replies

5. Shell Programming and Scripting

ssh to multiple hosts and saving the output in the local host

hi I have a script to login from a host "A" to a list of hosts in a file and perform some commands inside it...its somethin like this for i in `cat file` do ssh -t $i " command1 ; command2; ..." done I wanna save the outputs in a file in the current host "A" i.e from where I am... (3 Replies)
Discussion started by: ningy
3 Replies

6. UNIX for Advanced & Expert Users

Help! How to find the local host after few ssh hops to remote host???

I do a ssh to remote host(A1) from local host(L1). I then ssh to another remote(A2) from A1. When I do a who -m from A2, I see the "connected from" as "A1". => who -m userid pts/2 2010-03-27 08:47 (A1) I want to identify who is the local host who initiated the connection to... (3 Replies)
Discussion started by: gomes1333
3 Replies

7. Shell Programming and Scripting

running commands to remote host from centralized host

Gurus/Experts We have a centralized UNIX/Solaris server from where we can actually ssh to all other UNIX/Solaris servers...I need to write a script that reside on this centerlized server and do FileSystem monitoring (basically run df -h or -k) of other remote servers and then send an email to me... (6 Replies)
Discussion started by: anjum.suri
6 Replies

8. Solaris

How to delete the files from local host to remote host

Hi all, i am copying .gz files from production server to development server using "scp" command.my requirement is after copying .gz files i want to delete old .gz files(two days back) in development server from production server. like this way i need to delelte .log ,.z and .dmp files... (3 Replies)
Discussion started by: krishna176
3 Replies

9. UNIX for Dummies Questions & Answers

Sending tar output to a remote host

Our group has recently inherited 15 servers that have not been maintained for over a year. My first action is to backup the units however there is not enough disk space on most of them to run tar. My supervisor said to look at piping the tar output to another machine, however I have been unable... (3 Replies)
Discussion started by: thumper
3 Replies

10. IP Networking

QNX host cannot ping SCO host, vice versa

The problem I am facing now is that the QNX host could not ping the SCO host and vice versa. They are in the same domain, ie, 172.20.3.xx. As I am very new to Unix, I guess I must have missed out some important steps. Pls help... Thanx alot (2 Replies)
Discussion started by: gavon
2 Replies
Login or Register to Ask a Question