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:

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:

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:

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?

Sorry, let me try again. How about something like:

hostname=$(uname -n)
ps -Ao "user,args" | while read line
do      printf "%s\t%s\n" "$hostname" "$line"
done

Try changing the IFS variable, Something like this:

ifso=$IFS; IFS=""; for PS in `ps`; do echo "`uname -n`, $PS"; done; IFS=$ifso;
[ -z "$HOST" ] && HOST=`uname -n | cut -f1 -d.`
ps -eo user,args |
while read user args
do
  echo "$HOST, $user, $args"
done

Hi the output from this script is:

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

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 ----------

PERFECT!!!!!

.... i LOVE YOU. CAN YOU EPXPLAIN THE PORTION

[ -z "$HOST" ] && HOST

Also how do i mark this as resolved?

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.