|
|
slmingol posted this in tips & tricks on March 12th, 2010, @ 11:10 am
Background
A system’s BIOS is a treasure trove of a lot of useful info about the capabilities of a computer. BIOS, which stands for Basic Input/Output System, contains information such as:
* motherboard manufacturer
* system’s serial number
* amount of RAM installed
* the CPUs speed & signature
Normally the BIOS is accessible by pressing the delete key or the F1 key.
Problem
Occasionally I’ve wanted to check out the BIOS settings of a system without having to go through the hassle of rebooting. With the help of this nifty command line tool, dmidecode, BIOS info can be had, without having to reboot.
Solution
dmidecode is a tool for dumping a computer’s DMI (some say SMBIOS) table contents in a human-readable format. This table contains a description of the system’s hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision. Thanks to this table, you can retrieve this information without having to probe for the actual hardware. While this is a good point in terms of report speed and safeness, this also makes the presented information possibly unreliable.
The DMI table doesn’t only describe what the system is currently made of, it also can report the possible evolutions (such as the fastest supported CPU or the maximal amount of memory supported).
SMBIOS stands for System Management BIOS, while DMI stands for Desktop Management Interface. Both standards are tightly related and developed by the DMTF (Desktop Manage- ment Task Force).
Example output from a Thinkpad T42 laptop
When you first run the dmidecode command it tells you a summary of how many structures are present within your system’s BIOS.
1
2
3
4
5
| % dmidecode
# dmidecode 2.9
SMBIOS 2.33 present.
61 structures occupying 2126 bytes.
Table at 0x000E0010. |
Each structure is represented by a handle ID which is a hex value of the form 0×001F, followed by it’s type and it’s size.
System Info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
| ...
Handle 0x0000, DMI type 0, 20 bytes
BIOS Information
Vendor: IBM
Version: 1RETDPWW (3.21 )
Release Date: 06/02/2006
Address: 0xDC000
Runtime Size: 144 kB
ROM Size: 1024 kB
Characteristics:
PCI is supported
PC Card (PCMCIA) is supported
PNP is supported
APM is supported
BIOS is upgradeable
BIOS shadowing is allowed
ESCD support is available
Boot from CD is supported
Selectable boot is supported
EDD is supported
3.5"/720 KB floppy services are supported (int 13h)
Print screen service is supported (int 5h)
8042 keyboard services are supported (int 9h)
Serial services are supported (int 14h)
Printer services are supported (int 17h)
CGA/mono video services are supported (int 10h)
ACPI is supported
USB legacy is supported
AGP is supported
BIOS boot specification is supported
Handle 0x0001, DMI type 1, 25 bytes
System Information
Manufacturer: IBM
Product Name: 2373B09
Version: ThinkPad T42
Serial Number: 99N4BVC
UUID: 205A7001-46D4-22CB-B51D-FDE5F7FCD3CD
Wake-up Type: Power Switch
Handle 0x0002, DMI type 2, 8 bytes
Base Board Information
Manufacturer: IBM
Product Name: 2373B09
Version: Not Available
Serial Number: J1ZTY5031AP
Handle 0x0003, DMI type 3, 17 bytes
Chassis Information
Manufacturer: IBM
Type: Notebook
Lock: Not Present
Version: Not Available
Serial Number: Not Available
Asset Tag: No Asset Information
Boot-up State: Unknown
Power Supply State: Unknown
Thermal State: Unknown
Security Status: Unknown
OEM Information: 0x00000000 |
CPU Info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
| ...
Handle 0x0006, DMI type 4, 35 bytes
Processor Information
Socket Designation: None
Type: Central Processor
Family: Pentium M
Manufacturer: GenuineIntel
ID: D6 06 00 00 BF B3 A3 AF
Signature: Type 0, Family 6, Model 13, Stepping 6
Flags:
FPU (Floating-point unit on-chip)
VME (Virtual mode extension)
DE (Debugging extension)
PSE (Page size extension)
TSC (Time stamp counter)
MSR (Model specific registers)
MCE (Machine check exception)
CX8 (CMPXCHG8 instruction supported)
SEP (Fast system call)
MTRR (Memory type range registers)
PGE (Page global enable)
MCA (Machine check architecture)
CMOV (Conditional move instruction supported)
PAT (Page attribute table)
CLFSH (CLFLUSH instruction supported)
DS (Debug store)
ACPI (ACPI supported)
MMX (MMX technology supported)
FXSR (Fast floating-point save and restore)
SSE (Streaming SIMD extensions)
SSE2 (Streaming SIMD extensions 2)
SS (Self-snoop)
TM (Thermal monitor supported)
PBE (Pending break enabled)
Version: Intel(R) Pentium(R) M processor
Voltage: 1.3 V
External Clock: 400 MHz
Max Speed: 1600 MHz
Current Speed: 1600 MHz
Status: Populated, Enabled
Upgrade: None
L1 Cache Handle: 0x000A
L2 Cache Handle: 0x000B
L3 Cache Handle: Not Provided
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
... |
RAM Info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| ...
Handle 0x0007, DMI type 5, 20 bytes
Memory Controller Information
Error Detecting Method: None
Error Correcting Capabilities:
None
Supported Interleave: One-way Interleave
Current Interleave: One-way Interleave
Maximum Memory Module Size: 1024 MB
Maximum Total Memory Size: 2048 MB
Supported Speeds:
Other
Supported Memory Types:
DIMM
SDRAM
Memory Module Voltage: 2.9 V
Associated Memory Slots: 2
0x0008
0x0009
Enabled Error Correcting Capabilities:
None
Handle 0x0008, DMI type 6, 12 bytes
Memory Module Information
Socket Designation: DIMM Slot 1
Bank Connections: 0 1
Current Speed: Unknown
Type: DIMM SDRAM
Installed Size: 1024 MB (Double-bank Connection)
Enabled Size: 1024 MB (Double-bank Connection)
Error Status: OK
Handle 0x0009, DMI type 6, 12 bytes
Memory Module Information
Socket Designation: DIMM Slot 2
Bank Connections: 2 3
Current Speed: Unknown
Type: DIMM SDRAM
Installed Size: 1024 MB (Double-bank Connection)
Enabled Size: 1024 MB (Double-bank Connection)
Error Status: OK
... |
Cache Info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| ...
Handle 0x000A, DMI type 7, 19 bytes
Cache Information
Socket Designation: Internal L1 Cache
Configuration: Enabled, Socketed, Level 1
Operational Mode: Write Back
Location: Internal
Installed Size: 32 KB
Maximum Size: 32 KB
Supported SRAM Types:
Synchronous
Installed SRAM Type: Synchronous
Speed: Unknown
Error Correction Type: Unknown
System Type: Other
Associativity: 8-way Set-associative
Handle 0x000B, DMI type 7, 19 bytes
Cache Information
Socket Designation: Internal L2 Cache
Configuration: Enabled, Socketed, Level 2
Operational Mode: Write Back
Location: Internal
Installed Size: 2048 KB
Maximum Size: 2048 KB
Supported SRAM Types:
Burst
Installed SRAM Type: Burst
Speed: Unknown
Error Correction Type: Multi-bit ECC
System Type: Unified
Associativity: 8-way Set-associative
... |
Port Info (USB, Infrared, Parallel, etc.)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
| ...
Handle 0x000D, DMI type 8, 9 bytes
Port Connector Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: Infrared
External Connector Type: Infrared
Port Type: Other
Handle 0x000E, DMI type 8, 9 bytes
Port Connector Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: Parallel
External Connector Type: DB-25 female
Port Type: Parallel Port ECP/EPP
Handle 0x000F, DMI type 8, 9 bytes
Port Connector Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: External Monitor
External Connector Type: DB-15 female
Port Type: Video Port
Handle 0x0015, DMI type 8, 9 bytes
Port Connector Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: Microphone Jack
External Connector Type: Mini Jack (headphones)
Port Type: Audio Port
Handle 0x0016, DMI type 8, 9 bytes
Port Connector Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: Headphone Jack
External Connector Type: Mini Jack (headphones)
Port Type: Audio Port
Handle 0x0017, DMI type 8, 9 bytes
Port Connector Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: S-Video-Out
External Connector Type: Other
Port Type: Video Port
Handle 0x0019, DMI type 8, 9 bytes
Port Connector Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: Modem
External Connector Type: RJ-11
Port Type: Modem Port
Handle 0x001A, DMI type 8, 9 bytes
Port Connector Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: Ethernet
External Connector Type: RJ-45
Port Type: Network Port
Handle 0x001B, DMI type 8, 9 bytes
Port Connector Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: USB 1
External Connector Type: Access Bus (USB)
Port Type: USB
Handle 0x001C, DMI type 8, 9 bytes
Port Connector Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: USB 2
External Connector Type: Access Bus (USB)
Port Type: USB
... |
CardBus Slot Info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| ...
Handle 0x0022, DMI type 9, 13 bytes
System Slot Information
Designation: CardBus Slot 1
Type: 32-bit PC Card (PCMCIA)
Current Usage: Available
Length: Other
ID: Adapter 0, Socket 0
Characteristics:
5.0 V is provided
3.3 V is provided
PC Card-16 is supported
Cardbus is supported
Zoom Video is supported
Modem ring resume is supported
PME signal is supported
Hot-plug devices are supported
Handle 0x0023, DMI type 9, 13 bytes
System Slot Information
Designation: CardBus Slot 2
Type: 32-bit PC Card (PCMCIA)
Current Usage: Available
Length: Other
ID: Adapter 1, Socket 0
Characteristics:
5.0 V is provided
3.3 V is provided
PC Card-16 is supported
Cardbus is supported
Zoom Video is supported
Modem ring resume is supported
PME signal is supported
Hot-plug devices are supported
... |
RAM Modules Info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
| ...
Handle 0x002C, DMI type 16, 15 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 1 GB
Error Information Handle: Not Provided
Number Of Devices: 2
Handle 0x002D, DMI type 17, 27 bytes
Memory Device
Array Handle: 0x002C
Error Information Handle: No Error
Total Width: 64 bits
Data Width: 64 bits
Size: 1024 MB
Form Factor: SODIMM
Set: None
Locator: DIMM 1
Bank Locator: Bank 0/1
Type: DDR
Type Detail: Synchronous
Speed: Unknown
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Handle 0x002E, DMI type 17, 27 bytes
Memory Device
Array Handle: 0x002C
Error Information Handle: No Error
Total Width: 64 bits
Data Width: 64 bits
Size: 1024 MB
Form Factor: SODIMM
Set: None
Locator: DIMM 2
Bank Locator: Bank 2/3
Type: DDR
Type Detail: Synchronous
Speed: Unknown
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Handle 0x002F, DMI type 18, 23 bytes
32-bit Memory Error Information
Type: OK
Granularity: Unknown
Operation: Unknown
Vendor Syndrome: Unknown
Memory Array Address: Unknown
Device Address: Unknown
Resolution: Unknown
Handle 0x0030, DMI type 19, 15 bytes
Memory Array Mapped Address
Starting Address: 0x00000000000
Ending Address: 0x0007FFFFFFF
Range Size: 2 GB
Physical Array Handle: 0x002C
Partition Width: 0
Handle 0x0031, DMI type 20, 19 bytes
Memory Device Mapped Address
Starting Address: 0x00000000000
Ending Address: 0x0003FFFFFFF
Range Size: 1 GB
Physical Device Handle: 0x002D
Memory Array Mapped Address Handle: 0x0030
Partition Row Position: 1
Handle 0x0032, DMI type 20, 19 bytes
Memory Device Mapped Address
Starting Address: 0x00040000000
Ending Address: 0x0007FFFFFFF
Range Size: 1 GB
Physical Device Handle: 0x002E
Memory Array Mapped Address Handle: 0x0030
Partition Row Position: 1
... |
Pointing Device Info
1
2
3
4
5
6
7
8
9
10
11
12
13
| ...
Handle 0x0033, DMI type 21, 7 bytes
Built-in Pointing Device
Type: Track Point
Interface: PS/2
Buttons: 3
Handle 0x0034, DMI type 21, 7 bytes
Built-in Pointing Device
Type: Touch Pad
Interface: PS/2
Buttons: 0
... |
The End
There are some additional handles related to system logging, hardware security, and OEM information that I ommited to keep this post from just becoming a complete dump of the output but needless to say dmidecode is a pretty exhaustive and sweet command.
Check out the dmidecode website or the man page for more information.
slmingol posted this in tips & tricks on September 27th, 2009, @ 3:17 am
Now that I’ve been using OpenVZ for several months I’d gotten to the point where I wanted/needed to “yum update” all my VEs. I currently have 11 images running on my OpenVZ Server. I thought I could just vzctl exec … yum -y update all the VEs, but quickly ran into some issues with this brute force approach. Doing the yum -y update broke several of my VEs so I opted to restore the unrecoverable ones from backups.
For my second attempt, I opted to do each VE independently, to get a better understanding of what the best approach would be for doing mass upgrades like this now, and in the future. The first hurdle to overcome had to do with some of the VEs running out of memory (RAM) during the upgrade process.
NOTE: A VE = Virtual Environment (aka. a virtual host), while HN = Host Node
Issue #1, not enough RAM for yum to run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| # RAM budgets for VEs
# NOTE: values are in # of pages (1 pg. = 4K)
% (printf "vm feature held maxheld barrier limit failcnt\n"; grep privvm /proc/bc/1*/resources)|column -t
vm feature held maxheld barrier limit failcnt
/proc/bc/101/resources: privvmpages 31904 82215 65536 69632 2
/proc/bc/102/resources: privvmpages 119803 196620 166400 179200 9517
/proc/bc/103/resources: privvmpages 27125 35974 65536 69632 0
/proc/bc/104/resources: privvmpages 56251 107250 104960 115200 0
/proc/bc/105/resources: privvmpages 73559 82926 98304 103304 0
/proc/bc/106/resources: privvmpages 30219 68097 65536 69632 0
/proc/bc/108/resources: privvmpages 30081 84291 65536 69632 1
/proc/bc/109/resources: privvmpages 32790 74199 98304 103304 0
/proc/bc/110/resources: privvmpages 40497 69408 65536 69632 1
/proc/bc/111/resources: privvmpages 26990 35371 65536 67840 0
# NOTE: converted the columns to megabytes (MB), it's just easier to read
(printf "vm feature held maxheld barrier limit failcnt\n"; grep privvm /proc/bc/1*/resources|awk '{sub($3,$3*4096/2^20) sub($4,$4*4096/2^20) sub($5,$5*4096/2^20) sub($6,$6*4096/2^20)}1')|column -t
vm feature held maxheld barrier limit failcnt
/proc/bc/101/resources: privvmpages 124.625 321.152 256 272 2
/proc/bc/102/resources: privvmpages 467.98 768.047 650 700 9517
/proc/bc/103/resources: privvmpages 105.957 140.523 256 272 0
/proc/bc/104/resources: privvmpages 219.73 418.945 410 450 0
/proc/bc/105/resources: privvmpages 287.34 323.93 384 403.531 0
/proc/bc/106/resources: privvmpages 118.043 266.004 256 272 0
/proc/bc/108/resources: privvmpages 117.504 329.262 256 272 1
/proc/bc/109/resources: privvmpages 128.086 289.84 384 403.531 0
/proc/bc/110/resources: privvmpages 158.191 271.125 256 272 1
/proc/bc/111/resources: privvmpages 105.43 138.168 256 265 0 |
According to this data 4 of the 11 images had gone over their allocation of RAM. So I tried restarting these and re-running yum update within the problem VEs. Again the update failed and so I needed to increase their allocation of memory. I didn’t want to devote more memory permanently, just a enough temporarily to do the upgrade. So I used this trick to temporarily bump up a VEs allocated memory.
1
2
3
4
5
6
7
8
9
| # increase the RAM by 100MB
vzctl set 101 --privvmpages $((256+100))m:$((272+100))m --save
# ...
# do the upgrade (yum update)
# ...
# decrease the RAM back to the original value
vzctl set 101 --privvmpages 256m:272m --save |
For the remaining 3 VEs that needed additional memory I used these commands to increase their allocations of RAM
1
2
3
4
5
6
7
8
9
| # cmds. to increase RAM by 100MB
vzctl set 102 --privvmpages $((650+100))m:$((700+100))m --save
vzctl set 108 --privvmpages $((256+100))m:$((272+100))m --save
vzctl set 110 --privvmpages $((256+100))m:$((272+100))m --save
# cmds. to decrease
vzctl set 102 --privvmpages 650m:700m --save
vzctl set 108 --privvmpages 256m:272m --save
vzctl set 110 --privvmpages 256m:272m --save |
Issue #2, not enough diskspace for yum to run
The next snag I ran into had to do with a couple of the VEs running out of diskspace. And here’s the commands I used to reconfigure more diskspace.
…. Continue reading → Keeping CentOS 5 OpenVZ images up to Date with Yum »»
slmingol posted this in tips & tricks on September 5th, 2009, @ 1:13 am
As it is with UNIX & Linux there is always another way. In my previous article [one-liner]: Filtering ps from ps, one reader, Christoph, mentioned an alternative method to the one I outlined. In this case, I would consider his to be a better way, so I thought I would take a second to demonstrate this alternative method. The alternative? Use the command pgrep.
The Original Approach
My original post offered the following one-liner:
1
2
3
4
5
6
7
8
9
10
| % ps -eaf | grep "[h]ttpd"
root 2683 1 0 2008 ? 00:20:31 /usr/sbin/httpd
apache 17146 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17147 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17149 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17150 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17151 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17152 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17153 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17154 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd |
This one-liner provided a list of all the httpd processes running, while filtering out the actual string from the grep httpd command.
The Alternative Approach
By using the command pgrep, the same effect can be achieved and a lot more. For starters, you can get a list of all the httpd PIDs:
1
2
3
4
5
6
7
8
9
| # list of httpd PIDs
% pgrep httpd
1608
7645
9739
10051
27712
27859 |
This could be useful in a shell script, if needed, to check for any running httpd processes. For example:
1
2
3
4
| # test for httpd processes
% [ -z "`pgrep httpd`" ] || echo "running"
running |
Here are some other examples:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| # list of PIDs with corresponding command name
% pgrep -l httpd
1608 httpd
7645 httpd
9739 httpd
10051 httpd
27712 httpd
27859 httpd
# list of PIDs with corresponding command name owned by user root
% pgrep -l -u root httpd
1608 httpd
# list of PIDs, separated with a comma delimiter
% pgrep -d, httpd
1608,7645,9739,14119,14162,27859
# detailed list of httpd PIDs via ps
# NOTE: $(...) runs the command above, returning the list of PIDs to ps
% ps -fp $(pgrep -d, httpd)
UID PID PPID C STIME TTY TIME CMD
root 1608 1 0 Aug03 ? 00:00:05 /usr/sbin/httpd
apache 7645 1608 0 Sep04 ? 00:00:47 /usr/sbin/httpd
apache 9739 1608 0 Sep04 ? 00:01:50 /usr/sbin/httpd
apache 14119 1608 0 Sep04 ? 00:00:13 /usr/sbin/httpd
apache 14162 1608 0 Sep04 ? 00:00:13 /usr/sbin/httpd
apache 27859 1608 0 Sep04 ? 00:07:19 /usr/sbin/httpd |
Thanks again to Christoph for pointing out this alternative.
NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.
slmingol posted this in tips & tricks on September 4th, 2009, @ 1:13 pm
Background
This is a pretty handy trick to know when you want to filter out the command you’re running, so that it’s not included in ps output. This proves handy when writing a shell script that needs to parse output from ps.
NOTE: The command ps, allows you to see all the processes being run on a UNIX/Linux system. You typically use it with the switches “-eaf” or “-ef”.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| # columns description:
# UID = user who owns the process
# PID = process #
# PPID = parents' process #
# C =
# STIME = start time
# TTY = terminal type (has to do with which shell command ran from)
# TIME = system time its run
# CMD = command (aka. program name)
% ps -eaf
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 2008 ? 00:24:46 init [5]
root 2 0 0 2008 ? 00:00:00 [kthreadd]
root 3 2 0 2008 ? 00:01:58 [migration/0]
root 4 2 0 2008 ? 00:23:13 [ksoftirqd/0]
root 5 2 0 2008 ? 00:00:00 [watchdog/0]
root 6 2 0 2008 ? 00:02:35 [migration/1]
root 7 2 0 2008 ? 00:09:55 [ksoftirqd/1]
root 8 2 0 2008 ? 00:00:00 [watchdog/1]
root 9 2 0 2008 ? 00:06:36 [events/0]
root 10 2 0 2008 ? 00:06:16 [events/1]
root 11 2 0 2008 ? 00:00:10 [khelper]
root 54 2 0 2008 ? 00:19:26 [kblockd/0] |
Problem
Here’s an example where we want to see if a program is running, so we grep the output of ps like so:
1
2
3
4
5
6
7
8
9
10
11
| % ps -eaf | grep httpd
root 2683 1 0 2008 ? 00:20:31 /usr/sbin/httpd
user1 13188 3984 0 12:45 pts/1 00:00:00 grep httpd
apache 17146 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17147 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17149 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17150 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17151 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17152 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17153 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17154 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd |
The problem? Notice that a portion of our command, “grep httpd” is polluting our ps output. How can we get rid of it?
The Trick
You can alter what you are grepping for, without actually altering the results, by using a benign regular expression.
1
2
3
4
5
6
7
8
9
10
| % ps -eaf | grep "[h]ttpd"
root 2683 1 0 2008 ? 00:20:31 /usr/sbin/httpd
apache 17146 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17147 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17149 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17150 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17151 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17152 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17153 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd
apache 17154 2683 0 Aug30 ? 00:00:02 /usr/sbin/httpd |
Explanation
…. Continue reading → [one-liner]: Filtering ps from ps »»
slmingol posted this in tutorials on August 20th, 2009, @ 2:31 am
If you’ve followed my blog for a while you’ve probably noticed that I like to automate just about everything. I can’t stand doing anything manual, at least more than once. So of course when I setup a network printer, I like to have the Windows drivers that go along with each printer available automagically over the network. This technique isn’t glaringly obvious so I thought I’d quickly document how I accomplished it.
Background
This technique requires that you already have both Samba & CUPS servers setup and configured. You should also already have the printer whose drivers we’re going to install configured and working through CUPS. You can read how I did this for the MFC-8480DN printer in this previous post.
Getting Started
First things first, you typically want to grab a copy of the Windows drivers for your particular printer. Remember, in this example I’m using the network capable, Brother MFC-8480DN, that I discussed in this previous post. I downloaded the Windows drivers from the Brother’s website here. Here’s a link the specific driver bundle that I used. Brother calls this bundle the “Add Printer Wizard Driver”. I then set them aside, so I could focus on getting the special Samba share, print$, configured. This is a special share where print drivers for all versions of Windows can be staged, for later consumption by Windows client systems that add this printer.
Samba
adding the print$ share
For my setup, which is a CentOS 5 system, I added the following stanza to my /etc/samba/smb.conf file.
1
2
3
4
5
6
7
8
9
| # /etc/samba/smb.conf
[print$]
comment = Printer Driver Download Area
path = /etc/samba/drivers
browseable = yes
guest ok = yes
read only = yes
write list = @samba-printers, root |
NOTE: The unpacked driver files that get added to the print$ share will be stored under /etc/samba/drivers on the Samba server. You can put them really anywhere, but I chose to keep them with the Samba config. files.
samba-printers Linux Group
Next, I created a special Linux group that I arbitrarily called samba-printers. Users in this group, in addition to root, will be the only users that have permission to add Windows drivers to the print$ Samba share. I accomplished this by adding the line below to the /etc/group file on the Samba server.
1
2
3
| # /etc/group file on Samba server
samba-printers:x:1020:root,user1,user2 |
The 2 user accounts, user1 & user2, are both Linux accounts as well as Windows accounts. In my home network I typically create them this way to make things like this simpler. If you happen to user different user accounts on Windows vs. Linux you can map the Windows accounts to Linux accounts through the Samba config. file /etc/samba/smbusers.
creating /etc/samba/drivers
Next, I created the directory /etc/samba/drivers and permissioned it with our newly created Linux group using these commands:
1
2
| mkdir -m ug+rwx,o-w,g+s /etc/samba/drivers
chgrp samba-printers /etc/samba/drivers |
…. Continue reading → Howto Install Windows Print Drivers onto a Central Samba Share »»
slmingol posted this in tips & tricks on August 15th, 2009, @ 2:02 am
Here’s a little trick that I learned how to do the other day while at work. I’ve done this before using ssh in a linux terminal but hadn’t had the chance to actually do it from a windows box using PuTTY.
Objective
To access a web server (on a remote linux box) which is listening on port 80 through an ssh connection. We want to access the web server through port 10001 on the localhost. This can be accomplished by mapping localhost’s port 10001 to port 80 on the remote host.
Here’s a diagram that attempts to represent what’s going on with the ports, the hosts, and the ssh connection.
 ports diagram
Setup
In this scenario we have 2 hosts, the local host (i.e. localhost) and the remote host (homer). Running PuTTY on the localhost, we specify that we want to login to homer as a user on that system, i.e. root, for example. It doesn’t have to be root, this just happens to be the user that I’m using in this example.
 putty dialog #1
Next in the PuTTY Configuration dialog box, expand the category SSH, and select the category Tunnels. In Tunnels’ configuration, specify the Source port, 10001, and the Destination, homer:80. Then click the Add button.
 putty dialog #2
…. Continue reading → [one-liner]: Port Forwarding Using PuTTY »»
|