ps command in scripts

I want to write 2 scripts that:
script named "users" - List of users logged into the system;
script named "ps" - List of all processes in the operating system;

# is it true?
#!bin/bash 
echo 'content-type: text/html'
echo
users # for script named users
#!bin/bash
echo 'content-type: text/html'
echo 
ps -a  # for script named ps

but when i use another OS (Ubuntu). for script "users" - nothing to show, and
for script "ps" - just show "PID TTY TIME CMD" :confused:
is there anyone can help me?

#!/bin/bash should be the very first line. When you make it the second line, it's useless.

The output of ps is different in different versions of UNIX, yes.

Which kind and version of UNIX do you have? -- there are lots, UNIX is just a generic term. If you don't know, uname -a will tell you.

Wouldn't help either as first line. There is a typo:

#!bin/bash

should be

#!/bin/bash

#!/bin/bash => it's just my typing mistake here (in my CentOs - true) :slight_smile:
to Corona688: scripts in CentOS: version 2.6.18
check html in Ubuntu: linux ubuntu 2.6.35-28

Neither of those are UNIX at all.

It's entirely possible for a server to have no logged-in users, but make sure you're running it with the absolute path - /usr/bin/users

To show all processes in the operating system in Linux, ps aux

following you advice: just receive that:
in CentOs:

in Ubuntu:(not show as we want)

That's not an ubuntu problem in particular, it ought to have the same version of ps as most other Linux. You may be in a chroot or otherwise restricted, unable to access that sort of information/

What does ls /proc do?

on CentOs:

on Ubuntu

I don't mean from terminal. I mean from CGI.

As the so called ubuntu output looks like being from a browser, this should work better:

#!/bin/bash
echo "content-type: text/html"
echo
echo "<pre>"
ps aux
echo "</pre>"

CGI for all files: -rwxrwxrwx

---------- Post updated 04-01-12 at 01:49 AM ---------- Previous update was 03-31-12 at 07:28 PM ----------

you're true if using only one OC (in your case: Ubuntu). but i have to write scripts in CentOs and check it in Ubuntu. this cause a problem that i said above:wall:

so, ls /proc from your cgi scripts on both OSes show -rwxrwxrwx, only -rwxrwxrwx, and absolutely nothing but -rwxrwxrwx ? Very strange.

Again, I think this has nothing to do with centos vs ubuntu, but the way these systems have been configured. You appear to have been denied access to ps either accidentally or intentionally.

i just wrote ps script in CentOs :slight_smile:

Off topic (maybe?). It is not advisable to call an executable script the same name as a system command. In this case ps .

not ls ps.

not even ls /ps.

ls /proc

What is an OC ?

Can you clarify again what is the problem you are trying to solve ? You keep posting new screen-shots but there is nothing unexpected in them. Can you post another one (or better, just cut and pasted text with code tags) clearly exhibiting the issue and showing the context of the command ?