Linux / UNIX find out what other users are doing?

last updated in Categories , , , , , ,

Q. Can you explain the command to find what users are doing on my UNIX / Linux system?

A. Both Linux and UNIX (FreeBSD/Solaris) has w command to show who is logged on and what they are doing.

The w command prints a summary of the current activity on the system, including what each user is doing.

=> The first line displays the current time of day

=> How long the system has been running

=> The number of users logged into the system

=> The load averages. The load average numbers give the number of jobs in the run queue averaged over 1, 5 and 15 minutes.

You can also use ps command which shows you process that are running on the system.

Type w command displays information about the users currently on the machine, and their processes.

Show who is logged on and what they are doing with w command

The fields output are the user’s login name, the name of the terminal the user is on, the host from which the user is logged in, the time the user logged on, the time since the user last typed anything, and the name and arguments of the current process.
$ w
Output:

radm    pS 66.90.90.102     Sun01PM  1day -bash
raj     pW 192.168.1.100.  7:42AM     5 ssh root@202.54.1.20
miku    pX a80-186-82-84.el  7:28AM    10 screen irssi
vivek   pY 196.15.193.111    4:11AM     0 nano -w hireme
rani    q0 dslbr0.bsnl.in    7:32AM    12 lynx http://slashdot.org/
jadmin  q2 dslbr5.bsnl.in    7:33AM     0 ssh jadmin@host.cyberciti.info
gad     q3 dslbr76.bsnl.in   7:40AM     0 -ksh
bencs   q5 dslbr22.bsnl.in   7:44AM     5 -zsh
vivek   q6 gw11-vsnl.in      7:47AM    11 -bash

You can use the ps command shows you processes that are running on the system:

$ ps -au | more
$ ps -au | less

So you can use both w and ps commands to find out who’s doing what.

How can I find out who is logged on my UNIX / Linux system?

last updated in Categories , , , , , ,

Q. How do I display who is on the UNIX / Linux system?

A. On a Linux (on Solaris/FreeBSD or any other UNIX) system, many users will be sharing the same server.

Users will use telnet (outdated and insecure) or ssh (secure and highly recommended) to login remotely.

So if you want to find out your friend or a coworker is logged in or not, use the following commands.

If you want to find out who’s logged in on the Linux server including what time they logged in and from which network computer then you can use who command:

who command ~ show who is logged on

who commands works with almost all Linux and UNIX like oses. It show who is logged on to your system. It displays information about currently logged in users. By default, this includes the login name, tty name, date and time of login and remote hostname if not local.
$ who
Output:

raj     ttypV    Jan 17 07:23   .     (192.168.1.10)
ben     ttypW    Jan 17 07:42   .     (192.168.1.11)
miku    ttypX    Jan 17 07:28   .     (user-del-net-202.vsnl.net.in)
root    ttypY    Jan 17 04:11   .     (196.15.183.151)
roomy   ttyq0    Jan 17 07:32   .     (org-rev-1.bsnl.net.in)
anita   ttyq2    Jan 17 07:33   .     (192.168.5.112)
gads    ttyq3    Jan 17 07:40   .     (gtw-1.nixcraft.in)
bencs   ttyq5    Jan 17 07:44   .     (dsl5.bsnl.co.in)
pol20um ttyq6    Jan 17 07:47   .     (gtw-2.nixcraft.co.in)

Sometime you just want to find out if user raj logged in or not then you can use grep command:

$ who | grep raj

Try out following command if you have more than 20+ users logged in (so that you can see one page of logged in users at a time):

$ who | less
$ who | more

Solaris: Forcefully unmount a disk partition to get rid of device busy error

last updated in Categories

Under Solaris, umount come does not allow a file system to be unmounted if a file on the file system is busy i.e. open by other programs/process or by user. You will get device busy error. To get rid of this message you can pass -f option to umount command. Suppose you would like to forcefully unmount a /cdrom/cdrom0 then you can type following command (login as a root user):
# umount -f /cdrom/cdrom0

Please note that using this option can cause data loss for open files; program(s) which access files after the file system has been unmounted will get an error.

How do I find what dependencies a rpm file has?

last updated in Categories

RPM is a Package Manager for popular distribution such as Red Hat, Suse and many others. It is a powerful command line package management system for installing uninstalling, verifying, querying, and updating Linux computer software packages.

You can finding out what dependencies a rpm file has i.e. it will tell you what you need to install package with following command:
rpm -qpR {.rpm-file}
rpm -qR {package-name}

Find out what dependencies a uninstalled rpm file called mediawiki-1.4rc1-4.i586.rpm:
# rpm -qpR mediawiki-1.4rc1-4.i586.rpm

It will print list of dependencies on screen (output):

mod_php
php-session
php-gettext
php-zlib
php-mysql
ImageMagick-Magick++
tetex
cjk-latex
rpmlib(PayloadFilesHavePrefix)

However RPM has in build mechanism to tell you about dependencies. Just try to install package and it will give you list of dependencies.
# rpm -ivh mediawiki-1.4rc1-4.i586.rpm

Output:

error: Failed dependencies:
   mod_php is needed by mediawiki-1.4rc1-4
   php-session is needed by mediawiki-1.4rc1-4
   php-gettext is needed by mediawiki-1.4rc1-4
   php-zlib is needed by mediawiki-1.4rc1-4
   php-mysql is needed by mediawiki-1.4rc1-4
   ImageMagick-Magick++ is needed by mediawiki-1.4rc1-4
   tetex is needed by mediawiki-1.4rc1-4
   cjk-latex is needed by mediawiki-1.4rc1-4

Note:

  • .rpm file: File with .RPM extension. Typically this file is not installed. It may be on CD or you just downloaded from Internet.
  • package-name: It is installed RPM file.

You can solve dependencies problem by installing each individual package(s). If you are using Red hat Linux then you can try this tip. If you are using Fedora core Linux then try yum. If you are using Suse linux then use Yast to install rpms.

How do I find the url for my cgi-bin?

last updated in Categories , ,

The CGI is acronym for Common Gateway Interface. It is a standard for interfacing external applications with Apache Web servers. A CGI program is executed in real-time, so that it can output dynamic information. It can be written in Perl, Php, Bash, C/C++ or other programming languages. But how do I find the url for my cgi-bin? It’s not in my /var/www/ directory.
Apache web server use ScriptAlias directive defines cgi-bin directory that contain server scripts. You can use open Apache web server configuration file using text editor such as vi and look for ScriptAlias directive:

httpd.conf file location:
Debian Linux:

$ vi /etc/apache-perl/httpd.conf

Red Hat/ Fedora Core Linux:

$ vi  /etc/httpd/conf/httpd.conf

FreeBSD:

$ vi  /usr/local/etc/httpd.conf

You can also use grep command as follows to find out your cgi-bin directory:

$ grep 'ScriptAlias'  /etc/httpd/conf/httpd.conf
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

/usr/lib/cgi-bin/ is cgi-bin directory. If you have public_htm directory then cgi-bin directory should be inside this directory. Once you located cgi-bin directory you can use it.

Default cgi-bin directory locations:

  • Red Hat Linux: /var/www/cgi-bin/
  • Fedora Linux: /var/www/cgi-bin/
  • Debian Linux: /usr/lib/cgi-bin/
  • FreeBSD: /usr/local/www/cgi-bin/

Finally your url location depends upon directory location. You can use http://ip-address/cgi-bin or http://ip-address/~yourname/cgi-bin (replace ip-address with your domain name)

How do I run X windows program as normal user?

last updated in Categories

Microsoft windows XP has runas command which allows a user to run specific tools and programs with different permissions than the user’s current logon provides. Linux and other UNIX like operating system provides the su or sudo command for same purpose. However, su/sudo command is not so useful when it comes to X program. For example when you logged in as a normal user, you need to run an X window application as root. If I run application as follows:

$ su -
Password
# xeyes

It will bump you back with an error:
(program:15082): Gtk-WARNING **: cannot open display:
OR
** WARNING ** cannot open display

However both KDE and Gnome come with tools to deal with this problem.

Method # 1:
If you are using KDE then use following command at shell prompt:
kdesu command-name

$ kdesu xeyes

Method # 2:
If you are using Gnome then use following command at shell prompt:

$ gksuexec

Or use GUI itself, click on Applications > System tools > Select Run as different user
Method # 3:
Create runas alias as follows:

$ alias runas='su -c $@'

Add above alias to your bash startup script

$ echo "alias runas='su -c $@'" >> .bash_profile

You can now use alias as follows to start any x program

$ runas program-name
$ runas xeyes

Method # 4: The old way
The problem is with two environment variable DISPLAY and XAUTHORITY. You need to setup them correctly to run X windows program as a root user while logged in as a normal user. So how do you fix this problem? Simply set these two variables to point to current logged in users environment variable. Let us assume you are currently login as vivek user.

Step # 1 Become super-use

vivek@debian:~$ su -
debian:~#

Step # 2 Setup variables

# export DISPLAY=0:0
# export XAUTHORITY=/home/vivek/.Xauthority

Step # 3 Execute X program as a root user

# xeyes

How do I find out what network services are running or listing under Linux?

last updated in Categories ,

Q. How do I find out what network service are running under Linux operating system?

A. For security reason it is necessary to find out what services are running. With the help of netstat command, you can print information about the Linux networking subsystem including running services. It can display program name and PID for each socket belongs to. Use netstat as follows:

$ netstat -atup

OR

$ netstat -atup | grep LISTEN

Where,

  • -t : Select all TCP services
  • -u : Select all UDP services
  • -a : Display all listening and non-listening sockets.
  • -p : Display the PID and name of the program to which each socket belongs