2011年2月28日 星期一
use ftp and tar in shell script
quote user tester
quote pass tester
cd /download_folder
lcd /upload_folder
put | "tar -cjvf - test.data" test.data.tar.bz2
bye
_EOF
2011年2月22日 星期二
PostgreSQL check DB, Tablespace, Table, Index Size
Postgresql 如何一次清掉所有的view, trigger及function
2011年2月21日 星期一
Windows command for loop
For
Runs a specified command for each file in a set of files.
Syntax
for {%variable|%%variable} in (set) do command [ CommandLineOptions]
Parameters
{%variable|%%variable} : Required. Represents a replaceable parameter. Use %variable to carry out for from the command prompt. Use %%variable to carry out the forcommand within a batch file. Variables are case-sensitive and must be represented with an alpha value, such as %A, %B, or %C.
(set) : Required. Specifies one or more files, directories, range of values, or text strings that you want to process with the specified command. The parentheses are required.
command : Required. Specifies the command that you want to carry out on each file, directory, range of values, or text string included in the specified (set).
CommandLineOptions : Specifies any command-line options that you want to use with the specified command.
/?: Displays help at the command prompt.
Remarks
| • | Using for You can use the for command within a batch file or directly from the command prompt. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| • | Using batch parameters The following attributes apply to the for command:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| • | Specifying a group of files The set parameter can represent a single group of files or several groups of files. You can use wildcards (that is, * and ?) to specify a file set. The following are valid file sets: (*.doc) (*.doc *.txt *.me) (jan*.doc jan*.rpt feb*.doc feb*.rpt) (ar??1991.* ap??1991.*) When you use the for command, the first value in set replaces %variable or %%variable, and then the specified command processes this value. This continues until all of the files (or groups of files) that correspond to the set value are processed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| • | Using the in and do keywords In and do are not parameters, but you must use them with for. If you omit either of these keywords, an error message appears. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| • | Using additional forms of for If command extensions are enabled (that is, the default), the following additional forms of for are supported:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| • | Parsing a string You can use the for /F parsing logic on an immediate string, by wrapping the filenameset between the parentheses in single quotation marks (that is, 'filenameset').Filenameset is treated as a single line of input from a file, and then it is parsed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| • | Parsing output You can use the for /F command to parse the output of a command by making the filenameset between the parenthesis a back quoted string. It is treated as a command line, which is passed to a child Cmd.exe and the output is captured into memory and parsed as if it were a file. |
Examples
To use for in a batch file, use the following syntax:
for %%variable in (set) do command [CommandLineOptions]
To display the contents of all the files in the current directory that have the extension .doc or .txt using the replaceable variable %f, type:
for %f in (*.doc *.txt) do type %f
In the preceding example, each file that has the .doc or .txt extension in the current directory is substituted for the %f variable until the contents of every file are displayed. To use this command in a batch file, replace every occurrence of %f with %%f. Otherwise, the variable is ignored and an error message is displayed.
To parse a file, ignoring commented lines, type:
for /F "eol=; tokens=2,3* delims=," %i in (myfile.txt) do @echo %i %j %k
This command parses each line in Myfile.txt, ignoring lines that begin with a semicolon and passing the second and third token from each line to the FOR body (tokens are delimited by commas or spaces). The body of the FOR statement references %i to get the second token, %j to get the third token, and %k to get all of the remaining tokens. If the file names that you supply contain spaces, use quotation marks around the text (for example, "File Name"). To use quotation marks, you must use usebackq. Otherwise, the quotation marks are interpreted as defining a literal string to parse.
%i is explicitly declared in the FOR statement, and %j and %k are implicitly declared by using tokens=. You can specify up to 26 tokens using tokens=, provided that it does not cause an attempt to declare a variable higher than the letter 'z' or 'Z'.
To parse the output of a command by placing filenameset between the parentheses, type:
for /F "usebackq delims==" %i IN (`set`) DO @echo %i
This example enumerates the environment variable names in the current environment.