Archive forOperating Systems

Order of operation… Math operators in Excel

The math operators in Excel have an order of operation, just like in regular math. The order of operation is the order in which they’re processed when multiple operators appear in the same formula. Here are the rules that determine the order:

1. Any operations that are in parentheses, from left to right
2. Exponentiation (^)
3. Multiplication (*) and division (/)
4. Addition (+) and subtraction (-)

Parentheses override everything and go first. So, if you need to execute an operation out of the normal order, you place it in parentheses.

For example, suppose you have this formula:

=5+16/4^2

The order of operation looks like this:

1. The exponentiation (4^2 equals 16)
2. The division (16/16 equals 1)
3. The addition (5+1 equals 6)

The result of the formula is 6.

If you wanted the addition to occur first, you could put parentheses around the addition portion of the equation, like this:

=(5+16)/4^2

This time, the order of operation looks like this:

1. The part in parentheses (5+16 equals 21)
2. The exponentiation (4^2 equals 16)
3. The division (21/16 equals 1.3125)

The result of this formula is 1.3125.

If you wanted to perform the exponentiation last, you could add another set of parentheses, like this:

=((5+16)/4)^2

Now the order is this:

1. The inner parentheses (5+16 equals 21)
2. The outer parentheses (21/4 equals 5.25)
3. The exponentiation (5.25^2 equals 27.5625)

The result of this formula is 27.5625.

If you left off the inner set of parentheses and wrote it like this:

=(5+16/4)^2

The order would be as follows:

1. The division, because it’s the highest-ranking operation inside the parentheses (16/4 equals 4)
2. The rest of the parenthetical operations (5+4 equals 9)
3. The exponent (9^2 equals 81)

The result of this formula is 81.

Comments off

The Types of Commands used for Managing IIS from the Command Line

The types of commands which you can use to manage IIS from the command line are:
Click here to find out more!

* IISReset, Windows Management Instrumentation (WMI) scripts, Active Directory Services Interface (ADSI), and the standard Windows commands and Support Tools utilities.

IISReset Command-line Utility

IISReset is a command-line utility that has been in existence from IIS 5, which you can use to stop IIS, restart IIS, and reboot the IIS server. Typical reasons for restarting IIS are:

* When problematic ASP.NET and ASP application exist, and you need to eliminate resource leaks, or initiate resource recycling.
* When certain IIS configuration changes are made, you would need to restart IIS so that the changes are applied. A few of these types of configuration settings changes are listed below:
o IIS needs to be restarted when the IIS isolation mode is changed.
o When you restore the metabase from a metabase history file manually, you need to restart IIS.
o You have to restart IIS when you change the Direct Metabase Edit feature’s property, EnableEditWhileRunning, directly in the metabase file.
o IIS also has to be restarted whenever changes are made to any global configuration settings located under HKLM\Software\Microsoft\InetMgr\Parameters.

Windows Management Instrumentation (WMI)

You can use WMI scripts for a few typical IIS management tasks:

* Create and delete Web sites and FTP sites
* Create and delete virtual directories
* Enable/disable web service extensions
* Backup and restore IIS configuration, and copy IIS configuration
* Import/export portions of the metabase, as well as other management tasks

A few WMI scripts are provided by Microsoft, and are located in the \Windows\System32 directory. These WMI scripts and their associated functions are listed below:

* iisweb.vbs: Used to perform the following management tasks from the command line:
o List Web sites
o Create/delete Web sites
o Start/stop Web sites
* iisvdir.vbs: Used for performing the following management tasks from the command line:
o Create/delete virtual directories for Web sites
o List virtual directories in a specified root.
* iisapp.vbs: For listing all Web applications which are running on the IIS machine.
* iisback.vbs: For backing up and restoring IIS configuration settings, and for deleting IIS backups.
* iiscnfg.vbs: Used to perform the following management tasks from the command line:
o Import and export IIS configurations as XML files
o Save IIS configuration to disk.
o Copy IIS configuration settings
* iisext.vbs: Used for performing the following management tasks from the command line:
o List applications
o Enable applications
o Add/remove application dependencies
o Enable/disable web service extensions
o List and add/remove web service extension files
o Enable/disable web service extension files
* iisftp.vbs: Used to perform the following management tasks from the command line:
o List FTP sites
o Create/delete FTP sites
o Start/stop FTP sites
o Set Active Directory user isolation for your FTP sites
* iisftpdr.vbs: Used to perform the following management tasks from the command line:
o Create and delete virtual directories in FTP sites
o List virtual directories in a specified root.

Active Directory Services Interface (ADSI)

Active Directory Services Interface (ADSI) was used in IIS 5 to manage IIS from the command line. Through ADSI, you can change IIS configuration settings, and configure websites, applications, and virtual directories from the command line. With IIS 6, it is recommended to use WMI scripts over ADSI. Any custom ADSI scripts previously used in IIS 5 should be tested to verify that they work in IIS 6.
Windows Commands and Support Tools Utilities

A few IIS specific Windows commands, such as the net commands, can be used to manage IIS from the command line:

* net start and net stop: Used to start and stop IIS services. The service name which you should use when utilizing the net command to start, or stop IIS services are listed below:
o FTP service = msftpsvc
o IIS Admin service = iisadmin
o NNTP service = nntpsvc
o SMTP service = smtpsvc
o WWW service = w3svc
* net localgroup: Used to add a user account to the IIS_WPG group. Accounts utilized as application pool identities are members of the IIS_WPG group.
* Cacls: Used to capture NTFS permissions on the IIS server.
* Convlog: Used to convert the IIS log files to the NCSA format.

You can also use the resource kit utilities listed below to manage certain elements of IIS:

* secedit: Used to administer security templates.
* auditpol: Used to change audit policies from the command line
* showmbrs: Used to list the members of security groups which have permissions on directories and files.

How to schedule IISReset.exe through Task Scheduler

IISReset is typically used when you need to recover from faulty application situations. You can use Windows Task Scheduler to schedule IIS to restart according to predefined parameters.

1. Open Control Panel.
2. Select Scheduled Tasks, and then select Add Scheduled Task.
3. Click Next for the Scheduled Task Wizard to start.
4. Click Browse and browse to Windows\System32 folder.
5. Double-click IISReset.exe.
6. Enter a task name, and select when the task should run. Click Next.
7. Enter the Administrator account details that should be utilized to run IISReset. Click Next.
8. If you want to configure advanced task scheduling properties, click the Advanced checkbox; or alternatively click Finish.
9. Open the Properties dialog box of the task you just configured, and click the Task tab.
10. Add any additional switches in the Run box.
11. Click OK.

How to use iisweb.vbs to manage Web sites

The iisweb.vbs utility is used to list Web sites, create and delete Web sites, and start and stop Web sites in IIS.

iisweb.vbs has the following main switches:

* /create, for creating a Web site.
* /delete, for deleting a Web site.
* /start, for starting a Web site.
* /stop, for stopping a Web site
* /pause, for pausing a Web site
* /query, for troubleshooting a Web site – displaying all the Web sites on the IIS machine

To create a Web site, use:

iisweb[.vbs] /create Path SiteName [/b Port] [/i IPAddress] [/d HostHeader] [/dontstart] [/s Computer [/u [Domain\]User [/p Password]]]

* Path, the physical location to the files for the Web site. When the directory does not exist, the script creates it.
* SiteName, the name of the new Web site. This is the name which will be displayed in IIS Manager.
* /b Port, the port on which the new Web site should listen for HTTP requests. The default value is port 80.
* /i IPAddress, the IP address that must be assigned to the Web site.
* /d HostHeader, the host header for the new site.
* /dontstart, used to indicate that IIS should not automatically start the Web site after it is created. IIS by default starts a newly created Web site.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to create the Web site on the remote computer.
* /p Password, the password of the account credentials (above).

To start, stop, delete, or pause a Web site, use:

iisweb[.vbs] {/delete | /start | /stop | /pause} WebSite [WebSite...] [/s Computer [/u [Domain\]User [/p Password]]]

* WebSite, the name of the Web site which should be deleted, started, stopped, or paused.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to delete, start, stop, or pause the Web site on the remote computer.
* /p Password, the password of the account credentials (above).

To query Web sites on your IIS servers, use

iisweb[.vbs] /query [WebSite [WebSite...]] [/s Computer [/u [Domain\]User [/p Password]]]
How to use iisvdir.vbs to manage virtual directories

The iisvdir.vbs command can be used to list virtual directories in a specified root, to create and delete virtual directories for websites, and to query virtual directories of an IIS server.

To create a virtual directory for a Web site, use:

iisvdir /create WebSite[/VirtualPath] Name PhysicalPath [/s Computer [/u [Domain\]User /p Password]]

* WebSite, the name of the Web site which you want to create the virtual directory for.
* VirtualPath, the virtual path under which this virtual directory should be created (optional)
* Name, the name of the new virtual directory.
* PhysicalPath, the name of physical directory where the virtual directory points.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to create the virtual directory for the remote computer.
* /p Password, the password of the account credentials (above).

To delete a virtual directory associated with a Web site, use:

iisvdir /delete WebSite[/VirtualPath] Name [/s Computer [/u [Domain\]User/p Password]]

* WebSite, the name of the Web site which is associated with the virtual directory that you want to delete.
* VirtualPath, the virtual path which holds the virtual directory (optional).
* Name, the name of the virtual directory that you want to delete.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to delete the virtual directory.
* /p Password, the password of the account credentials (above).

To query Web site specific virtual directories on your IIS servers, use

iisvdir /query WebSite[/VirtualPath][/s Computer [/u [Domain\] User/p Password]]

* WebSite, the name of the Web site which is associated with the virtual directory that you want to query.
* VirtualPath, the virtual path which holds the virtual directory (optional).
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to query for virtual directories.
* /p Password, the password of the account credentials (above).

How to use iisftp.vbs to manage FTP sites

The iisftp.vbs utility is used to perform management tasks from the command line that are specific to managing FTP sites on the IIS servers.

iisftp.vbs has the following main switches:

* /create, for creating a FTP site.
* /delete, for deleting a FTP site.
* /start, for starting a FTP site.
* /stop, for stopping a FTP site
* /query, for troubleshooting a FTP site – displaying all the FTP sites on the IIS machine
* /setadprop, for indicating that Active Directory properties should be used for a particular user accessing the FTP site.
* /getadprop, for obtaining Active Directory properties for the particular user.

To create a FTP site, use:

iisftp /create Path SiteName [/b Port] [/i IPAddress] [/dontstart] [/isolation {AD|Local} [/domain DomainName /Admin [Domain\]User /AdminPwd Password]] [/s Computer [/u [Domain\]User/p Password]]

* Path, the physical location to the files for the FTP site.
* SiteName, the name of the new FTP site. This is the name which will be displayed in IIS Manager.
* /b Port, the port on which the new FTP site should listen for FTP requests. The default value is port 21.
* /i IPAddress, the IP address that must be assigned to the FTP site.
* /dontstart, used to indicate that IIS should not automatically start the FTP site after it is created. IIS by default starts all newly created sites.
* /isolation, used to indicate the isolation mode that should be used.
* domain, when Active Directory is selected as the isolation mode, this is the domain for Active Directory.
* admin, when Active Directory is selected as the isolation mode, this is the admin account credentials for Active Directory.
* AdminPwd, when Active Directory is selected as the isolation mode, this is the password of the admin account for Active Directory (above).
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to create the FTP site on the remote computer.
* /p Password, the password of the account credentials (above).

To start, stop, delete, or pause a FTP site, use:

iisftp[.vbs] {/delete | /start | /stop | /pause} FTPSite [FTPSite...] [/s Computer [/u [Domain\]User [/p Password]]]

* FTPSite, the name of the FTP site which should be deleted, started, stopped, or paused.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to delete, start, stop, or pause the FTP site on the remote computer.
* /p Password, the password of the account credentials (above).

To query FTP sites on your IIS servers, use

iisftp[.vbs] /query [FTPSite [FTPSite...]] [/s Computer [/u [Domain\]User [/p Password]]]

To use /setadprop, and /getadprop use,

iisftp /SetADProp UserID {FTPDir|FTPRoot} PropertyValue [/s Computer [/u [Domain\]User/p Password]]

iisftp /GetADProp UserID [/s Computer [/u [Domain\]User /p Password]]

* UserID, the Active Directory user login ID
* FTPDir, indicates whether the modification is applicable at the directory level or at the root level.
* PropertyValue, indicates the home directory and relative path.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used for remote administration.
* /p Password, the password of the account credentials (above).

How to use iisftpdr.vbsto manage virtual directories

The iisftpdr.vbs command can be used to list virtual directories in a specified root, and to create and delete virtual directories in FTP sites from the command line.

To create a virtual directory for a FTP site, use:

iisftpdr /create FTPSite[VirtualPath] Name PhysicalPath [/s Computer [/u [Domain\]User /p Password]]

* FTPSite, the name of the FTP site which you want to create the virtual directory for.
* VirtualPath, the virtual path under which this virtual directory should be created (optional)
* Name, the name of the new virtual directory.
* PhysicalPath, the name of physical directory where the virtual directory points.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to create the virtual directory on the remote computer.
* /p Password, the password of the account credentials (above).

To delete a virtual directory associated with a FTP site, use:

iisftpdr /delete FTPSite[VirtualPath]/Name [/s Computer [/u [Domain\]User /p Password]]

* FTPSite, the name of the FTP site which is associated with the virtual directory that you want to delete.
* VirtualPath, the virtual path which holds the virtual directory (optional).
* Name, the name of the virtual directory that you want to delete.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to delete the virtual directory.
* /p Password, the password of the account credentials (above).

To query FTP specific virtual directories on your IIS servers, use

iisftpdr /query FTPSite[/VirtualPath][/s Computer [/u [Domain\]User/p Password]]

* FTPSite, the name of the FTP site which is associated with the virtual directory that you want to query.
* VirtualPath, the virtual path which holds the virtual directory (optional).
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to query for virtual directories remotely.
* /p Password, the password of the user account (above).

How to use iiscnfg.vbs to manage IIS from the command line

You can use iiscnfg.vbs to import and export IIS configurations settings of the metabase as XML files.

To export IIS configuration settings, use:

iiscnfg /export /f [Path\]FileName.xml /sp SourcePath [/d EncryptingPassword] [/inherited] [/children] [/s Computer [/u [Domain\]User [/p Password]]]

* /f [Path\]FileName.xml, the name of the XML file that the configuration settings should be exported to.
* /sp SourcePath, the node of the metabase configuration settings.
* /d EncryptingPassword, the password of the XML file.
* /inherited, indicates that all inherited information should be exported.
* /children, indicates that subkeys of the node should be exported.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to run the script.
* /p Password, the password of the account credentials (above).

To import IIS configuration settings, use:

iiscnfg /import /f [Path\]FileName.xml /sp SourcePath /dp DestinationPath [/d EncryptingPassword] [/inherited] [/children] [/merge][/s Computer [/u [Domain\]User [/p Password]]]

* /f [Path\]FileName.xml, the name of the XML file that should be used to import IIS configuration settings to the server.
* /sp SourcePath, the node of the XML file.
* /dp DestinationPath, the destination node path in the metabase.
* /d EncryptingPassword, the password of the XML file.
* /inherited, indicates that all inherited information should be imported. This can only occur when the source node has properties that can be inherited.
* /children, indicates that subkeys of the node should be imported.
* /merge, merges different source keys to one metabase key through this value.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to run the script.
* /p Password, the password of the user account (above).

To copy the metabase.xml file and metabase XML file to a different IIS server, use:

iiscnfg /copy /ts TargetComputer /tu TargetUser /tp TargetPassword [/s Computer [/u [Domain\]User [/p Password]]]

* /ts TargetComputer, the name or IP address of the IIS computer to which these configuration settings should be copied.
* tu TargetUser, the user account for logging on the target computer.
* tp TargetPassword, the password of the account provided above.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to run the script remotely.
* /p Password, the password of the account (above).

To immediately save configuration changes to the metabase, use:

iiscnfg /save [/s Computer [/u [Domain\]User /p Password]]

* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to run the script.
* /p Password, the password of the account (above).

How to use iisback.vbs to back up IIS configuration settings and restore IIS configurations

You can use iisback.vbs to back up, and restore IIS configuration settings from the command line

To back up IIS configuration settings, use:

iisback /backup [/b BackupName] [/v {Integer | HIGHEST_VERSION | NEXT_VERSION}] [/overwrite] [/e EncryptingPassword] [/s Computer [/u [Domain\]User/p Password]]

* /b BackupName, the name of the back up.
* /v {Integer}, possible values are HIGHEST_VERSION or NEXT_VERSION. HIGHEST_VERSION creates a backup of the highest version number. The HIGHEST_VERSION value has to be utilized with /overwrite. NEXT_VERSION increments the existing version number by one.
* /overwrite, used to overwrite a current backup
* /e EncryptingPassword, used to enable password encryption for the backup.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to create backups for the remote computer.
* /p Password, the password of the account credentials (above).

To restore IIS configuration settings, use:

iisback /restore /b BackupName [/v {Integer | HIGHEST_VERSION}] [/e EncryptionPassword] [/s Computer [/u [Domain\]User/p Password]]

* /b BackupName, the name of the backup file that you want to restore.
* /v {Integer}, possible values are HIGHEST_VERSION or NEXT_VERSION.
* /e EncryptingPassword, the password for the backup.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to restore the backup file for the remote computer.
* /p Password, the password of the account (above).

To list all IIS backups for an IIS server, use:

iisback /list [/s Computer [/u [Domain\]User/p Password]]

* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to list all backups for the remote computer.
* /p Password, the password of the account credentials (above).

To delete an IIS backup, use:

iisback /delete [/bBackupName] [/v {Integer | HIGHEST_VERSION}] [/s Computer [/u [Domain\]User /p Password]]

* /bBackupName, the name of the backup file that you want to delete.
* /v {Integer}, possible values are HIGHEST_VERSION or NEXT_VERSION.
* /s Computer, used to indicate that the script should run on this remote computer. The local computer is used by default.
* /u [Domain\]User, the account credentials that must be used to delete the backup file for the remote computer.
* /p Password, the password of the account credentials (above).

Comments off

What happened to HyperTerminal?

What happened to HyperTerminal?

Applies to all editions of Windows Vista.
Which edition of Windows Vista am I using?

HyperTerminal is no longer part of Windows. There are several options you can use to replace its functionality.

If you only need remote shell access, you can use WinRS (Windows Remote Shell), new in Windows Vista. To get help with WinRS, type winrs /? at the command prompt, and then press ENTER.

Telnet is a simple, text-based program that you can use to connect to another computer over the Internet.

If you previously used HyperTerminal to troubleshoot modem problems, use Phone and Modem Options instead:

Open Phone and Modem Options by clicking the Start button Picture of the Start button, clicking Control Panel, clicking Hardware and Sound, and then clicking Phone and Modem Options.
NoteYou might need to provide information, such as your country or region and any special phone dialing rules, in the Location Information dialog box before you can access the Phone and Modem Options dialog box.

If you previously used HyperTerminal to control serial devices, you can usually find a downloadable version of HyperTerminal on the Internet that is free for personal use.

Comments off

How can I recover a bad superblock from a corrupted ext3 partition?

I’m getting following error:

/dev/sda2: Input/output error
mount: /dev/sda2: can’t read superblock

How do I fix this error?

A. Linux ext2/3 filesystem stores superblock at different backup location so it is possible to get back data from corrupted partition.
[Warning examples may crash your computer] WARNING! Make sure file system is UNMOUNTED.

If your system will give you a terminal type the following command, else boot Linux system from rescue disk (boot from 1st CD/DVD. At boot: prompt type command linux rescue).
Mount partition using alternate superblock

Find out superblock location for /dev/sda2:
# dumpe2fs /dev/sda2 | grep superblock
Sample output:

Primary superblock at 0, Group descriptors at 1-6
Backup superblock at 32768, Group descriptors at 32769-32774
Backup superblock at 98304, Group descriptors at 98305-98310
Backup superblock at 163840, Group descriptors at 163841-163846
Backup superblock at 229376, Group descriptors at 229377-229382
Backup superblock at 294912, Group descriptors at 294913-294918
Backup superblock at 819200, Group descriptors at 819201-819206
Backup superblock at 884736, Group descriptors at 884737-884742
Backup superblock at 1605632, Group descriptors at 1605633-1605638
Backup superblock at 2654208, Group descriptors at 2654209-2654214
Backup superblock at 4096000, Group descriptors at 4096001-4096006
Backup superblock at 7962624, Group descriptors at 7962625-7962630
Backup superblock at 11239424, Group descriptors at 11239425-11239430
Backup superblock at 20480000, Group descriptors at 20480001-20480006
Backup superblock at 23887872, Group descriptors at 23887873-23887878

Now check and repair a Linux file system using alternate superblock # 32768:
# fsck -b 32768 /dev/sda2
Sample output:

fsck 1.40.2 (12-Jul-2007)
e2fsck 1.40.2 (12-Jul-2007)
/dev/sda2 was not cleanly unmounted, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong for group #241 (32254, counted=32253).
Fix? yes

Free blocks count wrong for group #362 (32254, counted=32248).
Fix? yes

Free blocks count wrong for group #368 (32254, counted=27774).
Fix? yes
……….
/dev/sda2: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sda2: 59586/30539776 files (0.6% non-contiguous), 3604682/61059048 blocks

Now try to mount file system using mount command:
# mount /dev/sda2 /mnt
You can also use superblock stored at 32768 to mount partition, enter:
# mount sb={alternative-superblock} /dev/device /mnt
# mount sb=32768 /dev/sda2 /mnt
Try to browse and access file system:
# cd /mnt
# mkdir test
# ls -l
# cp file /path/to/safe/location

You should always keep backup of all important data including configuration files.

Comments off

netstat: commands to find attackers…

This is useful to find out if your server is under attack or not. You can also list abusive IP address using this method.

netstat -nat | awk ‘{print $6}’ | sort | uniq -c | sort -n

Dig out more information about a specific ip address:

netstat -nat |grep {IP-address} | awk ‘{print $6}’ | sort | uniq -c | sort -n

Busy server can give out more information:

netstat -nat |grep 202.54.1.10 | awk ‘{print $6}’ | sort | uniq -c | sort -n

To print list of all unique IP address connected to server, enter:

netstat -nat | awk ‘{ print $5}’ | cut -d: -f1 | sed -e ‘/^$/d’ | uniq

To print total of all unique IP address, enter:

netstat -nat | awk ‘{ print $5}’ | cut -d: -f1 | sed -e ‘/^$/d’ | uniq | wc -l

If you think your Linux box is under attack, print out a list of open connections on your box and sorts them by according to IP address, enter:

netstat -atun | awk ‘{print $5}’ | cut -d: -f1 | sed -e ‘/^$/d’ |sort | uniq -c | sort -n

Display Summary Statistics for Each Protocol

Simply use netstat -s:

netstat -s | less

netstat -t -s | less

netstat -u -s | less

netstat -w -s | less

netstat -s

You can easily display dropped and total transmitted packets with netstat for eth0:

netstat –interfaces=eth0

Comments off

SVC Program…

The svc program
svc controls services monitored by supervise.
Interface
svc opts services

opts is a series of getopt-style options. services consists of any number of arguments, each argument naming a directory used by supervise.

svc applies all the options to each service in turn. Here are the options:

-u: Up. If the service is not running, start it. If the service stops, restart it.
-d: Down. If the service is running, send it a TERM signal and then a CONT signal. After it stops, do not restart it.
-o: Once. If the service is not running, start it. Do not restart it if it stops.
-p: Pause. Send the service a STOP signal.
-c: Continue. Send the service a CONT signal.
-h: Hangup. Send the service a HUP signal.
-a: Alarm. Send the service an ALRM signal.
-i: Interrupt. Send the service an INT signal.
-t: Terminate. Send the service a TERM signal.
-k: Kill. Send the service a KILL signal.
-x: Exit. supervise will exit as soon as the service is down. If you use this option on a stable system, you’re doing something wrong; supervise is designed to run forever.

Comments off

Status of dd command…

setup your dd as normal:

dd if=whatever.dd of=/dev/sda &

pkill -USR1 ^dd$

or watch it

watch -n5 — pkill -USR1 ^dd$

Comments off

svc .. svstat .. /service .. huh?!?!?!?

The svc program
svc controls services monitored by supervise.
Interface

svc opts services

opts is a series of getopt-style options. services consists of any number of arguments, each argument naming a directory used by supervise.

svc applies all the options to each service in turn. Here are the options:

* -u: Up. If the service is not running, start it. If the service stops, restart it.
* -d: Down. If the service is running, send it a TERM signal and then a CONT signal. After it stops, do not restart it.
* -o: Once. If the service is not running, start it. Do not restart it if it stops.
* -p: Pause. Send the service a STOP signal.
* -c: Continue. Send the service a CONT signal.
* -h: Hangup. Send the service a HUP signal.
* -a: Alarm. Send the service an ALRM signal.
* -i: Interrupt. Send the service an INT signal.
* -t: Terminate. Send the service a TERM signal.
* -k: Kill. Send the service a KILL signal.
* -x: Exit. supervise will exit as soon as the service is down. If you use this option on a stable system, you’re doing something wrong; supervise is designed to run forever.

The svscan program
svscan starts and monitors a collection of services.
Interface
svscan starts one supervise process for each subdirectory of the current directory, up to a limit of 1000 subdirectories. svscan skips subdirectory names starting with dots. supervise must be in svscan’s path.

svscan optionally starts a pair of supervise processes, one for a subdirectory s, one for s/log, with a pipe between them. It does this if the name s is at most 255 bytes long and s/log exists. (In versions 0.70 and below, it does this if s is sticky.) svscan needs two free descriptors for each pipe.

Every five seconds, svscan checks for subdirectories again. If it sees a new subdirectory, it starts a new supervise process. If it sees an old subdirectory where a supervise process has exited, it restarts the supervise process. In the log case it reuses the same pipe so that no data is lost.

svscan is designed to run forever. If it has trouble creating a pipe or running supervise, it prints a message to stderr; it will try again five seconds later.

If svscan is given a command-line argument, it switches to that directory when it starts.

The svstat program
svstat prints the status of services monitored by supervise.
Interface

svstat services

services consists of any number of arguments, each argument naming a directory. svstat prints one human-readable line for each directory, saying whether supervise is successfully running in that directory, and reporting the status information maintained by supervise.

The supervise program
supervise starts and monitors a service.
Interface

supervise s

supervise switches to the directory named s and starts ./run. It restarts ./run if ./run exits. It pauses for a second after starting ./run, so that it does not loop too quickly if ./run exits immediately.

If the file s/down exists, supervise does not start ./run immediately. You can use svc to start ./run and to give other commands to supervise.

supervise maintains status information in a binary format inside the directory s/supervise, which must be writable to supervise. The status information can be read by svstat.

supervise may exit immediately after startup if it cannot find the files it needs in s or if another copy of supervise is already running in s. Once supervise is successfully running, it will not exit unless it is killed or specifically asked to exit. You can use svok to check whether supervise is successfully running. You can use svscan to reliably start a collection of supervise processes.

Comments off

Linux auto reboot after kernel panic

By default after a kernel panic Linux just sits there and waits for a user to hit the restart button.

That can be a bad thing if it’s a remote server.

To check if its enabled try this:
Code: cat /proc/sys/kernel/panic

0

The returned 0 is the time the kernel will wait before it reboots. If it is 0 or lower, it won’t reboot by itself.

To set the kernel to reboot do this command:

# echo “5″ > /proc/sys/kernel/panic

Where 5 is replaced with the number of seconds to wait till reboot after a kernel panic.

To check the time was set right do this:
Code: cat /proc/sys/kernel/panic

5

To make it more permanent do this:

# echo “kernel.panic=5″ >> /etc/sysctl.conf

Adding the following to your kernel parameters in your bootloaders configuration might also help:

panic=5

NOTE: Substitute 5 with the number of seconds to wait till reboot after a kernel panic.

Retrieved from “http://gentoo-wiki.com/TIP_Kernel_Panic_Reboot”

Comments off

Useful EXIM Commands

Here are some useful exim commands. They’re useful if you have an overloaded queue and need to clear it out, or find out why the messagse are being piled up.

exim -M id #Try to send the message with id id

exim -qf #Tell exim to process the entire queue again
exim -qff #same as qf, but it will flush the frozen messages

exim -Mvl id #view the message log for message id
exim -Mvh id #view message id’s headers
exim -Mvb id #view message id’s body
exim -Mrm id #remove message id from the queue
exim -Mg id #fail and send a bounce to the sender
exim -bp | exiqsumm #Print summary of the messages in the queue
exiwhat #show what exim is doing right now
exim -bpc #show number of messages in the queue
exim -bp #print list of messages in the queue

The manual way to remove the entire queue is as follows

cd /var/spool
mv exim exim.old
mkdir -p exim/input
mkdir -p exim/msglog
mkdir -p exim/db
chown -R mail:mail exim

Then restart exim.

Comments off

« Previous entries