There are a few ways to find out who are logged on:
1. Use the w command
#>w
00:03:53 up 4:45, 1 user, load average: 0.00, 0.00, 0.00
SER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/1 192.168.1.107 00:03 0.00s 0.02s 0.00s w
2. Use who -a command.
Who -a command also provides list all the users who have an open session (currently logon)
#>who -a
Feb 24 19:18 518 id=si term=0 exit=0
system boot Feb 24 19:18
run-level 5 Feb 24 19:18 last=S
Feb 24 19:19 4465 id=l5 term=0 exit=0
LOGIN tty1 Feb 24 19:19 5706 id=1
LOGIN tty2 Feb 24 19:19 5709 id=2
Feb 24 19:19 5711 id=3
Feb 24 19:19 5727 id=4
Feb 24 19:19 5739 id=5
LOGIN tty6 Feb 24 19:19 5745 id=6
Feb 24 19:19 5746 id=x
root + pts/1 Feb 25 00:03 00:02 6610 (192.168.1.107)
root + pts/2 Feb 25 00:07 . 6646 (192.168.1.107)
3. Use the users coomand.
The user command shows user ids of the current login users.
#>users
root root
4. Use the last command.
The last command looks through /var/log/wtmp and displays a log of the last users logged on, including those currently logged on.
#>last
root pts/2 192.168.1.107 Thu Feb 25 00:07 still logged in
root pts/1 192.168.1.107 Thu Feb 25 00:03 still logged in
reboot system boot 2.6.9-89.ELsmp Wed Feb 24 19:18 (04:54)
root pts/1 192.168.1.107 Wed Feb 24 08:56 - down (00:02)
reboot system boot 2.6.9-89.ELsmp Tue Feb 23 19:28 (13:30)
root pts/2 192.168.1.102 Tue Feb 23 03:39 - 05:50 (02:11)
5. Check system messages log
You may need root privilege to see the messages
#>grep sshd /var/log/messages
Feb 25 00:03:50 pc-1 sshd(pam_unix)[6608]: session opened for user root by (uid=0)
Feb 25 00:07:16 pc-1 sshd(pam_unix)[6644]: session opened for user root by (uid=0)
Wednesday, February 25, 2009
Monday, February 23, 2009
SQL: Find Maximum and Minimum Values
Table Fruit
id fruit cultivar price
1 Apple FUJI 0.99
2 Apple limbertwig 1.50
3 Apple Macintosh 2.00
4 Orange valencia 1.29
5 Orange Sunkis 1.99
6 Pear bradford 2.99
7 Pear Bartlett 2.45
8 cherry Chelan 3.89
9 Cherry Bang 1.99
1. Find the most expensive (maximum price) fruit of each type. List them in a form of
fruit cultivar price
Apple Macintosh 2.00
cherry Chelan 3.89
Orange Sunkist 1.99
Pear Bradford 2.99
1) Use max() function
Most databases, MySql, Oracle, MS SQL Server, etc, has build in function to get the max value.
a) We can use the max() function to get
the maximum price of each fruit and then use a self-join to get the row.
select f.fruit, f.cultivar, f.price
from (
select fruit, max(price) as maxprice
from fruit group by fruit
) as f2 inner join fruit as f on f.fruit = f2.fruit and f.price = f2.maxprice;
b) We can also use the max() function with a correlated subquery.
This can be much less efficient.
select fruit, cultivar, price
from fruit f
where price = (select max(price) from fruit as f2 where f2.fruit = f.fruit);
2) Without using the max() function
We can also use only self-join to get the result.
SELECT f.fruit, f.cultivar, f.price
FROM fruit f
LEFT JOIN fruit f2 ON (f.fruit = f2.fruit
AND f.price <= f2.price)
GROUP BY f.fruit, f.price
HAVING COUNT(*) = 1 ;
The following query is for demonstration only. It is an inefficient query. Also, it will not produce correct result if there are more than one record with the same value (price).
select fruit, cultivar, price
from fruit f
where price = (select price from fruit as f2 where f2.fruit = f.fruit order by price desc limit 1);
2. Find the Minimum Price of each fruit
1) Use min() function a) using a self-join to get the row.
select f.fruit, f.cultivar, f.price
from ( select fruit, min(price) as minprice from fruit group by fruit ) as f2
inner join fruit as f
on f.fruit = f2.fruit and f.price = f2.minprice;
b) using a correlated subquery.
select fruit, cultivar, price
from fruit f
where price = (select min(price) from fruit as f2 where f2.fruit = f.fruit);
2) Without using the min() function
SELECT f.fruit, f.cultivar, f.price
FROM fruit f
LEFT JOIN fruit f2 ON (f.fruit = f2.fruit AND f.price = f2.price)
GROUP BY f.fruit, f.price
HAVING COUNT(*) = 1;
id fruit cultivar price
1 Apple FUJI 0.99
2 Apple limbertwig 1.50
3 Apple Macintosh 2.00
4 Orange valencia 1.29
5 Orange Sunkis 1.99
6 Pear bradford 2.99
7 Pear Bartlett 2.45
8 cherry Chelan 3.89
9 Cherry Bang 1.99
1. Find the most expensive (maximum price) fruit of each type. List them in a form of
fruit cultivar price
Apple Macintosh 2.00
cherry Chelan 3.89
Orange Sunkist 1.99
Pear Bradford 2.99
1) Use max() function
Most databases, MySql, Oracle, MS SQL Server, etc, has build in function to get the max value.
a) We can use the max() function to get
the maximum price of each fruit and then use a self-join to get the row.
select f.fruit, f.cultivar, f.price
from (
select fruit, max(price) as maxprice
from fruit group by fruit
) as f2 inner join fruit as f on f.fruit = f2.fruit and f.price = f2.maxprice;
b) We can also use the max() function with a correlated subquery.
This can be much less efficient.
select fruit, cultivar, price
from fruit f
where price = (select max(price) from fruit as f2 where f2.fruit = f.fruit);
2) Without using the max() function
We can also use only self-join to get the result.
SELECT f.fruit, f.cultivar, f.price
FROM fruit f
LEFT JOIN fruit f2 ON (f.fruit = f2.fruit
AND f.price <= f2.price)
GROUP BY f.fruit, f.price
HAVING COUNT(*) = 1 ;
The following query is for demonstration only. It is an inefficient query. Also, it will not produce correct result if there are more than one record with the same value (price).
select fruit, cultivar, price
from fruit f
where price = (select price from fruit as f2 where f2.fruit = f.fruit order by price desc limit 1);
2. Find the Minimum Price of each fruit
1) Use min() function a) using a self-join to get the row.
select f.fruit, f.cultivar, f.price
from ( select fruit, min(price) as minprice from fruit group by fruit ) as f2
inner join fruit as f
on f.fruit = f2.fruit and f.price = f2.minprice;
b) using a correlated subquery.
select fruit, cultivar, price
from fruit f
where price = (select min(price) from fruit as f2 where f2.fruit = f.fruit);
2) Without using the min() function
SELECT f.fruit, f.cultivar, f.price
FROM fruit f
LEFT JOIN fruit f2 ON (f.fruit = f2.fruit AND f.price = f2.price)
GROUP BY f.fruit, f.price
HAVING COUNT(*) = 1;
Wednesday, February 04, 2009
Mailx Error:can not write to queue directory /var/spool/clientmqueue/
Problem:
Try to use linux mail to send email and got error:
/bin/mailx -s "$SUBJECT" "$RECIPIENT"
can not write to queue directory /var/spool/clientmqueue/ (RunAsGid=51, required=101): Permission denied
can not write to queue directory /var/spool/clientmqueue/ (RunAsGid=51, required=101): Permission denied
Fix:
Check the owner and permission of /var/spool/clientmqueue.
Go to directory /var/spool, and used ls –ln command to see who is the owner and what is the permission are:
Shell>ls –ln
drwxrwx--- 2 51 51 4096 Jan 19 12:45 clientmqueue
The directory need to be owned by smmsp:smmsp.
If you only see the group id and user id display, check the /etc/passwd file to see is the group id belong to smmsp.
Shell>vi /etc/passwd
smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
If the group and user is not smmsp:smmsp, change them.
Shell> chown –R smmsp:smmsp clientmqueue.
Try to use linux mail to send email and got error:
/bin/mailx -s "$SUBJECT" "$RECIPIENT"
can not write to queue directory /var/spool/clientmqueue/ (RunAsGid=51, required=101): Permission denied
can not write to queue directory /var/spool/clientmqueue/ (RunAsGid=51, required=101): Permission denied
Fix:
Check the owner and permission of /var/spool/clientmqueue.
Go to directory /var/spool, and used ls –ln command to see who is the owner and what is the permission are:
Shell>ls –ln
drwxrwx--- 2 51 51 4096 Jan 19 12:45 clientmqueue
The directory need to be owned by smmsp:smmsp.
If you only see the group id and user id display, check the /etc/passwd file to see is the group id belong to smmsp.
Shell>vi /etc/passwd
smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
If the group and user is not smmsp:smmsp, change them.
Shell> chown –R smmsp:smmsp clientmqueue.
Subscribe to:
Comments (Atom)