Wednesday, March 31, 2010

Is kern.openfiles more reliable than fstat?

Is kern.openfiles more reliable than fstat?

> I'm running Apache with MySQL and for the first time yesterday I hit
> the maximum file table length of my kernel, so I've been trying to
> monitor the number file descriptors in order to track down the rogue
> process that is causing the problem.
>
> However, I can't seem to figure out which of these two commands
> actually returns the number of active file descriptors:
>
> % fstat | wc -l
> % sysctl kern.openfiles
>
> Now I totally understand if fstat and kern.openfiles are not exact in
> their results (since the system is going to be in different states and
> both commands themselves contribute to the total number of open files),
> but they are usually in vast disagreement sometimes by as much as 250
> file descriptors. In some cases fstat indicates there are far more
> files open than kern.maxfiles allows, which doesn't make sense either.
>
> % fstat | wc -l ; sysctl kern.openfiles
> 1702
> kern.openfiles: 1458
>
> Here's some of the information from sysctl:
>
> kern.ostype: FreeBSD
> kern.osrelease: 4.7-RELEASE-p28
> kern.osrevision: 199506
> kern.version: FreeBSD 4.7-RELEASE-p28 #43: Wed Jul 20 09:35:30 MDT 2005
> root@fc2:/usr/src/sys/compile/VKERN
> kern.maxvnodes: 239578
> kern.maxproc: 150
> kern.maxfiles: 1600
> kern.argmax: 65536
> kern.maxfilesperproc: 11095
> kern.maxprocperuid: 5547
> kern.openfiles: 1465
> kern.maxusers: 384
>
> Any help is greatly appreciated,
>
> --Randall

kern.openfiles indicates the number of structures representing files
are in uses in the kernel. "fstat | wc -l" gives a sum over all
processes of where these files are attached to processes. These are
slightly different things.

For example, if a process forks, then the parent and child processes
will both have the file open (so that's two instances as far as
fstat is concerned) but these can reference the same structure in the
(only one reference for kern.openfiles).

Alternatively, if file discriptor that is passed from one process
to another, is closed by the sender but not yet received by the
receiver, then this file discriptor is currently attached to no
processes. That's one for kern.openfiles but zero for fstat.

Files which are only memory mapped do not usually show up in fstat's
output, but I think they will count towards kern.openfiles. Giving
fstat the "-m" option should encourage it to show you the mmapped
files. This might help you track down what's going on.

(Also, file discriptors that are leaked due to kernel bugs will be
counted by kern.openfiles but are unlikely to show up in fstat.
Thankfully these should be rare, but I do have some patches for
fstat to make it show the list of all files rather than the list
of files attached to processes.)

David.

Install the lsof utility from ports. You may find it helpful.

Apache mpm 模組 ( worker 和 prefork 的差別 )

Apache mpm 模組 ( worker 和 prefork 的差別 )
分享

阿舍在 Ubuntu 9.10 上安裝 PHP5 的時候,發現它會安裝 Apache 的 MPM 模組,而且,這個 MPM 還分成 workerprefork 兩個子模組,阿舍一時好奇,就去查了一下,這個模組是做什麼的 & 有什麼差別 ??

Apache 的 MPM 是 Multi-Processing Module 的縮寫,是讓 Apache 以多重處理器的方式來處理要求 ( Request ),可以讓 Apache 更有效率的以較少的資源處理更多的服務要求,而實做這項功能的方式有二種,一種是採用 Multi-Thread (多重執行緒 ) 的方式,另一種便是 Pre-forking (預載分流 ) 的方式。

其中的 Multi-Thread 的方式便是 worker 模組的運作方式,適合運用在多核心的 CPU 上,而 Pre-Forking 的方式則是 prefork 的運行方式,適合在多顆 CPU 執行環境。

在Ubuntu 上,Apach2 MPM 的相關設定會存放在 /etc/apache2/apach2.cnf 裡。

Note: 如果想 enable thread,你必需 用 Worker;用 Prefork 的話,thread 不會被 enable。
# httpd -V

Server MPM: Prefork
threaded: no

FreeBSD Statistic Tools

On this page I provide a list of statistical tools for FreeBSD to monitor your
system. There are a lot of them, so if I missed one please mail me (ronald at
echteman dot nl).

fstat The fstat utility identifies open files.
gstat The gstat utility can be used to monitor I/O transactions of geom(4)
devices.
iostat
The iostat utility displays kernel I/O statistics on terminal, device and cpu
operations.
netstat The netstat command symbolically displays the contents of various
network-related data structures.
nfsstat The nfsstat command displays statistics kept about NFS client and server
activity.
pstat The pstat utility displays open file entry, swap space utilization,
terminal state, and vnode data structures.
top Top displays the top processes on the system and periodically updates this
information.
systat The systat utility displays various system statistics in a screen oriented fashion.
vmstat The vmstat utility reports certain kernel statistics kept about process,
virtual memory, disk, trap and cpu activity.

  • fstat

    The fstat utility identifies open files.
    USER     CMD          PID   FD MOUNT      INUM MODE         SZ|DV R/W
    ronald   fstat       1087 root /             2 drwxr-xr-x     512  r
    ronald   fstat       1087   wd /usr     824321 drwxr-xr-x    3584  r
    ronald   fstat       1087 text /usr     1038656 -r-xr-sr-x   14624  r
    ronald   fstat       1087    0 /dev        126 crw--w----   ttyp1 rw
    ronald   fstat       1087    1 /dev        126 crw--w----   ttyp1 rw
    ronald   fstat       1087    2 /dev        126 crw--w----   ttyp1 rw
    ronald   fstat       1087    3 /dev         15 crw-r-----     mem  r
    ronald   fstat       1087    4 /dev         16 crw-r-----    kmem  r
    ronald   fstat       1087    5 /          8700 -rw-r--r--   40960  r
    ronald   vim         1025 root /             2 drwxr-xr-x     512  r
    ronald   vim         1025   wd /tmp          2 drwxrwxrwt     512  r
    ronald   vim         1025 text /usr     329983 -rwxr-xr-x  1266616  r
    ronald   vim         1025    0 /dev        129 crw--w----   ttyp3 rw
    ronald   vim         1025    1 /dev        129 crw--w----   ttyp3 rw
    
    

  • gstat

    The gstat utility can be used to monitor I/O transactions of geom(4) devices.
    dT: 0.504  flag_I 500000us  sizeof 240  i -1
     L(q)  ops/s    r/s   kBps   ms/r    w/s   kBps   ms/w   %busy Name
        1     91     91    964    3.6      0      0    0.0   33.2| ad0
        1     91     91    964    3.7      0      0    0.0   33.4| ad0s1
        0      0      0      0    0.0      0      0    0.0    0.0| acd0
        0      0      0      0    0.0      0      0    0.0    0.0| ad0s1a
        0      0      0      0    0.0      0      0    0.0    0.0| ad0s1b
        0      0      0      0    0.0      0      0    0.0    0.0| ad0s1c
        0      0      0      0    0.0      0      0    0.0    0.0| ad0s1d
        1     91     91    964    3.7      0      0    0.0   33.7| ad0s1e
        0      0      0      0    0.0      0      0    0.0    0.0| md0
    
  • iostat

    The iostat utility displays kernel I/O statistics on terminal, device and cpu
    operations.
          tty             ad0              fd0             cpu
     tin tout  KB/t tps  MB/s   KB/t tps  MB/s  us ni sy in id
      16  567 13.22  17  0.22   0.00   0  0.00   9  0  3  1 86
     821  880 64.00   0  0.02   0.00   0  0.00   8  0  3  1 89
     844  864  0.00   0  0.00   0.00   0  0.00   7  0  3  1 89
     945  965 64.00   0  0.02   0.00   0  0.00   6  0  4  1 89
     961  981 64.00   0  0.02   0.00   0  0.00   6  0  3  3 88
     961  981  0.00   0  0.00   0.00   0  0.00   6  0  2  1 90
     961  981 64.00   0  0.02   0.00   0  0.00   8  0  2  1 89
    
    
  • netstat

    The netstat command symbolically displays the contents of various
    network-related data structures. There are a number of output formats,
    depending on the options for the information presented.
    Active Internet connections
    Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
    tcp4       0      0  192.168.0.2.63566      193.69.116.13.http     CLOSE_WAIT
    tcp4       0      0  192.168.0.2.52783      216.239.41.104.http    ESTABLISHED
    tcp4       0      0  192.168.0.2.49413      solo.cs.vu.nl.imap     ESTABLISHED
    tcp4       0      0  192.168.0.2.65519      ronald.echteman..imap  ESTABLISHED
    tcp4       0      0  192.168.0.2.49324      ronald.echteman..imap  ESTABLISHED
    tcp4       0      0  192.168.0.2.50677      192.168.0.1.ssh        ESTABLISHED
    udp4       0      0  localhost.ntp          *.*                    
    udp4       0      0  192.168.0.2.ntp        *.*                    
    udp4       0      0  localhost.domain       *.*                    
    udp4       0      0  192.168.0.2.domain     *.*                    
    Active UNIX domain sockets
    Address  Type   Recv-Q Send-Q    Inode     Conn     Refs  Nextref Addr
    c15fe348 stream      0      0        0 c15fed20        0        0 /tmp/.X11-unix/X0
    c15fed20 stream      0      0        0 c15fe348        0        0
    c19ed118 stream      0      0        0 c15fd1a4        0        0
    c15fd1a4 stream      0      0        0 c19ed118        0        0
    c15fe118 stream      0      0        0 c15fe3d4        0        0
    
  • nfsstat

    The nfsstat command displays statistics kept about NFS client and server
    activity.
    Client Info:
    Rpc Counts:
      Getattr   Setattr    Lookup  Readlink      Read     Write    Create    Remove
            0         0         0         0         0         0         0         0
       Rename      Link   Symlink     Mkdir     Rmdir   Readdir  RdirPlus    Access
            0         0         0         0         0         0         0         0
        Mknod    Fsstat    Fsinfo  PathConf    Commit
            0         0         0         0         0
    Rpc Info:
     TimedOut   Invalid X Replies   Retries  Requests
            0         0         0         0         0
    Cache Info:
    Attr Hits    Misses Lkup Hits    Misses BioR Hits    Misses BioW Hits    Misses
            0         0         0         0         0         0         0         0
    BioRLHits    Misses BioD Hits    Misses DirE Hits    Misses
            0         0         0         0         0         0
    
    Server Info:
      Getattr   Setattr    Lookup  Readlink      Read     Write    Create    Remove
            0         0         0         0         0         0         0         0
       Rename      Link   Symlink     Mkdir     Rmdir   Readdir  RdirPlus    Access
            0         0         0         0         0         0         0         0
        Mknod    Fsstat    Fsinfo  PathConf    Commit
            0         0         0         0         0
    Server Ret-Failed
                    0
    Server Faults
                0
    Server Cache Stats:
       Inprog      Idem  Non-idem    Misses
            0         0         0         0
    Server Write Gathering:
     WriteOps  WriteRPC   Opsaved
            0         0         0
    

  • pstat

    The pstat utility displays open file entry, swap space utilization, terminal
    state, and vnode data structures.
      LINE RAW CAN OUT IHIWT ILOWT OHWT LWT     COL STATE  SESS      PGID DISC
      ttyv0  0   0   0  7680  6720 2052 256       0 OCc         683   694 term
      ttyv1  0   0   0  7680  6720 2052 256       0 OCc         684   711 term
      ttyv2  0   0   0  7680  6720 2052 256       7 OCc         685   685 term
      ttyv3  0   0   0  7680  6720 2052 256       7 OCc         686   686 term
      ttyv4  0   0   0  7680  6720 2052 256       7 OCc         687   687 term
      ttyv5  0   0   0  7680  6720 2052 256       7 OCc         688   688 term
      ttyv6  0   0   0  7680  6720 2052 256       7 OCc         689   689 term
      ttyv7  0   0   0  7680  6720 2052 256       7 OCc         690   690 term
      ttyv8  0   0   0  7680  6720 1296 256       2 OCc           0     0 term
        0,0  0   0   0     0     0    0   0       0 -             0     0 term
        0,0  0   0   0     0     0    0   0       0 -             0     0 term
        0,0  0   0   0     0     0    0   0       0 -             0     0 term
        0,0  0   0   0     0     0    0   0       0 -             0     0 term
        0,0  0   0   0     0     0    0   0       0 -             0     0 term
        0,0  0   0   0     0     0    0   0       0 -             0     0 term
        0,0  0   0   0     0     0    0   0       0 -             0     0 term
    consolectl  0   0   0  7680  6720 1296 256       0 -             0     0 term
      ttyp0  0   0   0  7680  6720 2052 256       0 OCc         729   943 term
      ttyp1  0   0  76  7680  6720 2052 256       0 OCc         754  1279 term
      ttyp2  0   0   0  7680  6720 2052 256   96221 OCc         778  1217 term
      ttyp3  0   0   0  7680  6720 2052 256       0 OCc         807   807 term
      cuaa0  0   0   0  7680  6720 1296 256     336 OCcXl         0     0 term
      ttyp4  0   0   0  7680  6720 2052 256       0 OCc        1210  1216 term
    
  • top

    Top displays the top processes on the system and periodically updates this
    information.
    last pid:  1421;  load averages:  0.02,  0.08,  0.08    up 0+01:42:59  11:49:46
    61 processes:  1 running, 60 sleeping
    CPU states:  5.4% user,  0.0% nice,  1.2% system,  0.0% interrupt, 93.4% idle
    Mem: 83M Active, 213M Inact, 62M Wired, 13M Cache, 48M Buf, 824K Free
    Swap: 743M Total, 743M Free
    
      PID USERNAME PRI NICE   SIZE    RES STATE    TIME   WCPU    CPU COMMAND
     1216 ronald    -8    0  6844K  1048K pcmwr    1:25  2.34%  2.34% mpg123
      734 ronald    76    0 51104K 44804K select   2:33  0.00%  0.00% opera
      710 ronald    76  -10 17292K 16096K select   2:29  0.00%  0.00% XFree86
      777 ronald    76    0  4888K  3280K select   0:46  0.00%  0.00% xterm
      723 ronald    76    0  6588K  4236K select   0:14  0.00%  0.00% icewm
     1218 root       5    0  1256K   840K ttyin    0:06  0.00%  0.00% tip
      806 ronald    76    0  4888K  3344K select   0:05  0.00%  0.00% xterm
      753 ronald    76    0  5284K  3712K select   0:03  0.00%  0.00% xterm
      521 root      76    0  1588K  1080K select   0:00  0.00%  0.00% ntpd
      727 ronald    76    0  4904K  3252K select   0:00  0.00%  0.00% xterm
     1410 ronald    76    0  7276K  4652K select   0:00  0.00%  0.00% vim
      724 ronald    76    0  2564K  1580K select   0:00  0.00%  0.00% ssh-agent
      754 ronald     5    0  2192K  1676K ttyin    0:00  0.00%  0.00% bash
      807 ronald     8    0  2196K  1708K wait     0:00  0.00%  0.00% bash
     1209 ronald    76    0  4888K  3648K select   0:00  0.00%  0.00% xterm
      684 root       8    0  1616K  1164K wait     0:00  0.00%  0.00% login
      328 bind      76    0  2760K  2076K select   0:00  0.00%  0.00% named
    

  • systat

    The systat utility displays various system statistics in a screen oriented
    fashion.
        6 users    Load  0.08  0.23  0.26                  Aug 12 10:47
    
    Mem:KB    REAL            VIRTUAL                     VN PAGER  SWAP PAGER
            Tot   Share      Tot    Share    Free         in  out     in  out
    Act   81112    5180   147268     9244   24120 count
    All  376852    6864  2954884    12200         pages
                                                                     Interrupts
    Proc:r  p  d  s  w    Csw  Trp  Sys  Int  Sof  Flt        cow     386 total
               3 56       645   17  721  642   14       57968 wire    250 0: clk
                                                        81664 act         1: atkb
     1.2%Sys   0.8%Intr  0.8%User  0.0%Nice 97.2%Idl   217284 inact       6: fdc0
    |    |    |    |    |    |    |    |    |    |      20720 cache       7: ppc0
    =                                                    3400 free    128 8: rtc
                                                              daefr     7 11: pcm
    Namei         Name-cache    Dir-cache                     prcfr       12: psm
        Calls     hits    %     hits    %                     react       13: npx
                                                              pdwak     1 14: ata
                                              zfod            pdpgs       15: ata
    Disks   ad0   fd0                         ofod            intrn
    KB/t  16.00  0.00                         %slo-z    48784 buf
    tps       1     0                         tfree         1 dirtybuf
    MB/s   0.02  0.00                                   26886 desiredvnodes
    % busy    0     0                                   20241 numvnodes
                                                         3786 freevnodes
    
  • vmstat

    The vmstat utility reports certain kernel statistics kept about process,
    virtual memory, disk, trap and cpu activity.
     procs      memory      page                    disks     faults      cpu
     r b w     avm    fre  flt  re  pi  po  fr  sr ad0 fd0   in   sy  cs us sy id
     1 2 0  138200  20520   48   0   0   0  81  41   0   0  809 1780 1151 10  5 86
     0 2 0  138200  20520    1   0   0   0   1   0   0   0  633  514 590  1  1 98
     0 2 0  138200  20520    0   0   0   0   0   0   0   0  632  469 587  0  1 98
     0 2 0  138200  20520    0   0   0   0   0   0   0   0  687  681 716  1  2 97
     0 2 0  138200  20520    0   0   0   0   1   0   1   0  673  704 686  1  1 98
     2 3 0  139372  20176   79   0   0   0  46   0   3   0  644 1017 654  2  3 95
     0 3 0  139432  18364   12   0   0   0   7   0  67   0  701 14122 2141 56 23 20
     2 2 0  139868  16748   37   0   0   0   0   0  35   0  667 12963 2603 66 20 13
     2 2 0  139920  15648    5   0   0   0  69   0  50   0  682 15063 1930 65 23 12
     0 2 0  138200  14104    6   0   0   0 262   0 124   0  759 10485 1937 30 16 55
    
    

Monday, March 29, 2010

Drupal 6 - How to embed a region in a node

Drupal 6 - How to embed a region in a node
Submitted by tom on Mon, 2008-08-04 03:22
There will come a time when you'll want to add a new region to your Drupal theme, weather you are using a stock theme, a modification of a base theme such as Zen (like me) or creating your own theme from scratch.

Drupal 6 makes the creation of new regions as simple as adding one line of code to your themes template.php file. However, by default new regions created in this manor will only be available to your themes page template (page.tpl.php) and a little extra work will be needed if you want to display it somewhere else.


For the purposes of this article, lets say that we want to add a new region at the top of all story nodes for displaying some google adsense adverts. But, we only want the region to be displaed if we are in the full node view and not in teaser mode.

Add the region to your themes .info file
First thing to do is to define the new region. So, open up your themes .info file (it should be named yourtheme.info) and look for the lines which define the regions. In the Zen theme, these lines look like this:

view sourceprint?

<?php
 regions[left]           = left sidebar  

 regions[right]          = right sidebar  

 regions[navbar]         = navigation bar  

 regions[content_top]    = content top 

 regions[content_bottom] = content bottom  

 regions[header]         = header  

 regions[footer]         = footer  

 regions[closure_region] = closure 
?>

The name in the square brackets is the name of the variable that will be made available to your templates. The text after the equals sign is a just descriptive text that will be used on the admin/build/blocks page. Choose a name which reflects what the region will be used for so you can easily identify it later - I chose the name node_advert_top which will make a variable named $node_top_advert available to my templates. To add the new region, simply add a new line under the existing region declarations.

view sourceprint?
<?php
 regions[footer]         = footer  

 regions[closure_region] = closure  

 regions[node_advert_top]= node advert top 
?>
Expose the region variable to your node template file.
By default, region variables are available for use in your page template file (page.tlp.php

). However, we want to display our advertisements block within the actuall node itself so we need to add the new region variable $node_advert_top to the node.tlp.php file. To do this we can use the preprocess_node() function. Open up your template.php file, create a function named yourtheme_preprocess_node() and add your new region to the $vars variable.

view sourceprint?
<?php
 function kirkdesigns_preprocess_node(&$vars, $hook) {  

   $vars['node_advert_top'] = theme('blocks', 'node_advert_top');  

 } 
?>
Place the region where you want it.
Now you just need to open up your node template file (node.tlp.php) and add the region where you would like it to appear. Remember though, I only want to display this advert block on story nodes, and I only want it to be displayed if we are viewing the full article. The first if statement does exactly that.

view sourceprint?
<?php
 if ($node_advert_top && !$teaser && $node->type == 'story'): ?>


<?php print $node_advert_top;
?>



<?php
endif;
?>

Friday, March 26, 2010

Microsoft PowerToys for Windows XP

PowerToys add fun and functionality to the Windows experience. What are they? PowerToys are additional programs that developers work on after a product has been released.

Note: We take great care to ensure that PowerToys work as they should, but they are not part of Windows and are not supported by Microsoft. For this reason, Microsoft Technical Support is unable to answer questions about PowerToys. PowerToys are for Windows XP only and will not work with Windows Vista.
Important


If you installed PowerToys prior to April 23, 2002, you must uninstall your old PowerToys before installing the versions available here.


PowerToys only work with U.S. English regional settings.

Current PowerToy options:
Color Control Panel Applet

Professional-level photographers and designers know that getting consistent, accurate color from file to screen to print and beyond is a requirement for great results. This new tool helps you manage Windows color settings in one place. Download or learn more.
SyncToy

With new sources of files coming from every direction (such as digital cameras, e-mail, cell phones, portable media players, camcorders, PDAs, and laptops), SyncToy can help you copy, move, and synchronize different directories. Download or learn more.
RAW Image Thumbnailer and Viewer

Are you a serious photographer? Now you can organize and work with digital RAW files in Windows Explorer (much as you can with JPEG images). This tool provides thumbnails, previews, printing, and metadata display for RAW images. Download or learn more.
ClearType Tuner

This PowerToy lets you use ClearType technology to make it easier to read text on your screen, and installs in the Control Panel for easy access.
HTML Slide Show Wizard

This wizard helps you create an HTML slide show of your digital pictures, ready to place on your Web site.
Open Command Window Here

This PowerToy adds an "Open Command Window Here" context menu option on file system folders, giving you a quick way to open a command window (cmd.exe) pointing at the selected folder.
Alt-Tab Replacement

With this PowerToy, in addition to seeing the icon of the application window you are switching to, you will also see a preview of the page. This helps particularly when multiple sessions of an application are open.
Tweak UI

This PowerToy gives you access to system settings that are not exposed in the Windows XP default user interface, including mouse settings, Explorer settings, taskbar settings, and more.

Version 2.10 requires Windows XP Service Pack 1 or Windows Server 2003.
Power Calculator

With this PowerToy you can graph and evaluate functions as well as perform many different types of conversions.
Image Resizer

This PowerToy enables you to resize one or many image files with a right-click.
CD Slide Show Generator

With this PowerToy you can view images burned to a CD as a slide show. The Generator works downlevel on Windows 9x machines as well.
Virtual Desktop Manager

Manage up to four desktops from the Windows taskbar with this PowerToy.
Taskbar Magnifier

Use this PowerToy to magnify part of the screen from the taskbar.
Webcam Timershot

This PowerToy lets you take pictures at specified time intervals from a Webcam connected to your computer and save them to a location that you designate.

Wednesday, March 24, 2010

想嘗試找尋看有沒有 類似 TrueImage 好用的 備份 方式,讓系統 死了 可以 短時間內恢愎

想嘗試找尋看有沒有 類似 TrueImage 好用的 備份 方式,讓系統 死了 可以 短時間內恢愎

有幾種方式 不同效果

- 只備份 /etc /usr/local/etc 設定檔

- rsync 到另一台主機

- snapshot ?

- dump and restore ?

- dd

- RAID

Saturday, March 20, 2010

ambitious 有雄心的;野心勃勃的

ambitious 有雄心的;野心勃勃的

ubiquitous 到處存在的; 普遍存在的

Small tutorial for IT guys to learn the Linux/Unix VI editor which is quite ugly but ubiquitous!

Friday, March 19, 2010

ERROR: Missing kernel configuration file(s) (MYKERNEL)

I had such mistake several days ago. In my case the reson was that I forgot that I am using amd64 arch, and I placed config to /usr/src/sys/i386/conf, but the right place was /usr/src/sys/amd64/conf.

Tuesday, March 16, 2010

誠心為思想之本

1. 誠心為思想之本
2. 忘我以求道
3. 遍習諸藝
4. 廣渉百業之道
5. 了解諸事的利弊得失
6. 培養辨別事物的眼光
7. 洞悉肉眼不可見之事
8. 留心細節小事
9. 不做無功效之事

Six ways to make people like you

Six ways to make people like you

1. Become genuinely interested in other people.
2. Smile.
3. Remember that a person's name is to that person the sweetest and most important sound in any language.
4. Be a good listener. Encourage others to talk about themselves.
5. Talk in terms of the other person's interests.
6. Make the other person feel important - and do it sincerely.

Win people to your way of thinking

Win people to your way of thinking

1. The only way to get the best of an argument is to avoid it.
2. Show respect for the other person's opinions. Never say, "You're wrong."
3. If you are wrong, admit it quickly and emphatically.
4. Begin in a friendly way.
5. Get the other person saying "yes, yes" immediately.
6. Let the other person do a great deal of the talking.
7. Let the other person feel that the idea is his or hers.
8. Try honestly to see things from the other person's point of view.
9. Be sympathetic with the other person's ideas and desires.
10. Appeal to the nobler motives.
11. Dramatize your ideas.
12. Throw down a challenge.

Wednesday, March 3, 2010

vbscript for deleting 2 week old files in 44 separate folders

Option Explicit

Dim fso, dTwoWeeksAgo

dTwoWeeksAgo = Date() - 14
wscript.echo dTwoWeeksAgo
Set fso = CreateObject("Scripting.FileSystemObject")

'DirWalk("C:\")               ' repeat this subroutine call with a different path to process more paths
'DirWalk("F:\users\data\")   ' like this.
'DirWalk("\\phobos\E$\ee\")  ' and/or like this.

DirWalk("C:\tmp\test\hmm")

Sub DirWalk(parmPath)
Dim oSubDir, oSubFolder, oFile, n

   On Error Resume Next         ' We'll handle any errors ourself, thank you very much

   Set oSubFolder = fso.getfolder(parmPath)

   For Each oFile In oSubFolder.Files   ' look in the current dir
      If Err.Number <> 0 Then   ' if we got an error, just skip this entry
         Err.Clear
      ElseIf oFile.DateLastModified < dTwoWeeksAgo Then
         Wscript.Echo "about to delete " & oFile.Path
      '''uncomment the next line when you are satisfied this script works properly
      '''fso.DeleteFile oFile.Path, True
      End If
   Next

   For Each oSubDir In oSubFolder.Subfolders
      DirWalk oSubDir.Path      ' recurse the DirWalk sub with the subdir paths
   Next

   On Error Goto 0              ' Resume letting system handle errors.

   ' Removing a empty folder.
   ' Commenting out following block if you prefer to keep these empty folders.
   If fso.getfolder(parmPath).SubFolders.Count = 0 AND fso.getfolder(parmPath).Files.Count = 0 Then
      fso.DeleteFolder(parmPath)
   End If

End Sub