Tuesday, August 11, 2015

Public access to docker container

Let's say docker container running some application along with ssh daemon is launched on base dockerhost (could be Linux, CoreOS etc VMs).

Now you are inside docker container and you need to know the port of external host to which container's ssh port is mapped.

This query should give you the result:

curl -s http://$(route | grep default | awk '{print $2}'):4243/containers/json | grep $(hostname) | awk -F":" '{$NF=$(NF-1)=""; print $0}'| awk '{print $NF}'| awk -F"," '{print $1}'

Please note that docker host name is not hardcoded in the query. It is derived from network configuration of container itself. 

Tuesday, February 24, 2015

Git Submodule Tutorial


Requirement: Automation run needs code from framework repository which is maintained independently. How do we ensure that we also get framework code whenever we clone/update product automation code.

Solution: Make “framework” a submodule of “automation”

Framework: https://stashserver/stash/scm/abc/framework.git

Automation: https://stashserver/stash/scm/ta/automation.git

Task 1: Add submodule



 git clone -c http.sslVerify=false clone https://stashserver/stash/scm/ta/automation.git

 git submodule add https://stashserver/stash/scm/abc/framework.git

 git commit –m “Add submodule named framework”

 git push origin master

Task 2: Clone automation code repository which includes submodule



 git clone --recursive https://stashserver/stash/scm/ta/automation.git

Task 3: Get latest contents for automation project and framework submodule in an already cloned repository



 cd automation_project_dir

 git pull --recurse-submodules

 git submodule update

Task 4: Update the revision of framework repository which is being referred to by automation repositories



 cd automation_project_dir

 git submodule update --remote framework

 git add framework

 git push origin master

Saturday, February 22, 2014

Bash: How to read file line by line

IFS=$'\n'

for line in $(cat file.txt)
do
       echo $line
done


OR

while read line
do
        echo $line
done < file

[While loop is the easiest method but it obliterates the formatting of lines including spaces and tabs.]


Thursday, February 20, 2014

Revert last submitted changelist from Perforce branch

Let's say Perforce trunk has changes c1,c2,c3. c3 is HOL. How do we revert the changes done through c3??


p4 sync @c2
p4 diff -se ...@c3 | p4 -x - edit
p4 sync @c3
p4 resolve -ay

Monday, January 6, 2014

How to enable warnings for Perl execution

1. Enable warnings from command line: perl -w

2. Through Shebang line: #!/usr/bin/perl -w

However this doesn't work in case of #!/usr/bin/env perl -w because env tries to treat "perl -w" as single argument.

3. use warnings - However this has lexical implications and only applies to current code

4. BEGIN{
$^W = 1
}

BEGIN block is executed during compilation and hence this sets warnings switch to true and applies to all the scripts that get executed/imported during this execution.

Friday, April 29, 2011

Enable wget behind proxy using cntlm on Linux

If your linux box is behind http proxy, command line utilities like wget, curl, yum, zypper etc, which talk to external URLs, fail because proxy does not allow the connection to be established. Authenticating proxy, CNTLM can solve this problem.


Cntlm is an NTLM, NTLM2SR, NTLMv2 authenticating HTTP proxy. It takes the address of your parent proxy (or proxies) and opens a listening socket, forwarding each request to it (moving on in a circular list if the active parent proxy stops working). Along the way, a connection to the parent is created anew and authenticated or, if available, a previously cached connection is reused to achieve higher efficiency and faster responses. When set up, cntlm should be used as the primary proxy in your applications.

Setup Instructions:
1. Download and install cntlm*.rpm
2. Edit /etc/cntlm.conf file to have following information.
----------------------------------------------------------------------------------

Username username
Domain domainname
Password password
Proxy **proxy server IP**:80
Listen 3128
Auth LM

----------------------------------------------------------------------------------
3. To generate hash key for password, run command:

cntlm -M http://**any external IP**:3128

Output of this command will look like this:
Auth ----- NTLMv2
PassNTLMv2 ----- **some-string**


4. Copy the last 2 lines of the output of #3 and paste them in /etc/cntlm.conf in place of the following line:

Auth ------ LM

and remove the password line.

5. Run cntlm in daemon mode by running command 'cntlm'
6. Before executing wget, curl etc, set following variables and that should be it.

http_proxy=127.0.0.1:3128
ftp_proxy=$http_proxy
https_proxy=$http_proxy

Monday, June 21, 2010

How to sign rpm files in a batch mode?

Rpm sign command uses getpass() method to read passphrase and hence there is no direct way to send passphrase by redirection in a shell script.

One alternative to that is to use Expect script (You need to have expect installed. RPMs are available in standard linux distros). Here is a snippet of code that explains how it works:

########BEGIN#############################

function expect_script
{
cat << End-of-text #No white space between << and End-of-text
spawn rpm --resign $RPMFILE
expect -exact "Enter pass phrase: "
send -- "${RPMPWD}\r"
expect eof
exit
End-of-text
}

function sign_rpm
{
echo "Signing RPM..."
expect_script | /usr/bin/expect -f -
}

## Main execution

RPMFILE="$*"
sign_rpm

##############END ##############################

RPMPWD is the passphrase. It should be set in the enviroment before sign_rpm is being called.

Of course, before running this script GPG private/public keys must have been imported in GPG keyring and public key must have been imported in RPM database also.

Monday, February 1, 2010

Good Tech Links

* Sed one liners explained
http://www.catonmat.net/blog/sed-one-liners-explained-part-one/
http://www.catonmat.net/blog/sed-one-liners-explained-part-two/
http://www.catonmat.net/blog/sed-one-liners-explained-part-three/

* Awk one liners explained
http://www.catonmat.net/blog/awk-one-liners-explained-part-one/
http://www.catonmat.net/blog/awk-one-liners-explained-part-two/
http://www.catonmat.net/blog/awk-one-liners-explained-part-three/

* Home Built Wind Turbine
http://www.mdpub.com/Wind_Turbine/index.html

Tuesday, September 1, 2009

Perl Reserved Words and Variables

Perl Reserved Words and Variables

[ Source : http://www.sarand.com/td/ref_perl_reserve.html ]

Reserved Literals
__END__ indicates the logical end of the script (^D and ^Z are synonyms)
__FILE__ current filename
__LINE__ current line number
Reserved Filehandles
<> Null filehanedle - input from either stdin, or files specified on the command line. Psuedonym for internal filehandle .
DATA read data only from the main script, but not from any required file or evaluated string.
STDERR Output to stderr
STDIN Input from stdin
STDOUT Output to stdout
Reserved Variables
$_ The default input and pattern-searching space. The following pairs are equivalent:
while (<>) {...} while ($_ = <>) {...} # only equivalent in while!
/^Subject:/ $_ =~ /^Subject:/
tr/a-z/A-Z/ $_ =~ tr/a-z/A-Z/
chop chop($_)
Also: $ARG
@_ The parameters passed to a subroutine. The array itself is local to the subroutine, but its values are references to the variables that are passed so updates to the members of the array will update the corresponding parameter value.
"><digit> Contains the subpattern from the corresponding set of parentheses in the last pattern matched, not counting patterns matched in nested blocks that have been exited already. These variables are all read-only.
$& The string matched by the last successful pattern match (not counting any matches hidden within a BLOCK or eval() enclosed by the current BLOCK). This variable is read-only.
Also: $MATCH
$` The string preceding whatever was matched by the last successful pattern match, not counting any matches hidden within a BLOCK or eval enclosed by the current BLOCK. This variable is read-only.
Also: $PREMATCH
$' The string following whatever was matched by the last successful pattern match (not counting any matches hidden within a BLOCK or eval() enclosed by the current BLOCK). Example:
$_ = 'abcdefghi';
/def/;
print "$`:$&:$'\n"; # prints abc:def:ghi
This variable is read-only.
Also: $POSTMATCH
$+ The last bracket matched by the last search pattern. This is useful if you don't know which of a set of alternative patterns matched. For example:
/Version: (.*)|Revision: (.*)/ && ($rev = $+);
This variable is read-only.
Also: $LAST_PAREN_MATCH
$* Set to 1 to do multiline matching within a string, 0 to tell Perl that it can assume that strings contain a single line, for the purpose of optimizing pattern matches. Pattern matches on strings containing multiple newlines can produce confusing results when " $* " is 0. Default is 0. Note that this variable only influences the interpretation of " ^ " and " $ ". A literal newline can be searched for even when $* == 0 . The '/m' modifier should be used instead when pattern matching.
Also: $MULTILINE_MATCHING
$. The current input line number of the last filehandle that was read. This variable should be considered read-only. Remember that only an explicit close on the filehandle resets the line number. Since " <> " never does an explicit close, line numbers increase across ARGV files.
Also: $NR, $INPUT_LINE_NUMBER, input_line_number HANDLE EXPR
$/ The input record separator, newline by default. Works like awk 's RS variable, including treating blank lines as delimiters if set to the null string. You may set it to a multicharacter string to match a multi-character delimiter. Note that setting it to "\n\n" means something slightly different than setting it to "" , if the file contains consecutive blank lines. Setting it to "" will treat two or more consecutive blank lines as a single blank line. Setting it to "\n\n" will blindly assume that the next input character belongs to the next paragraph, even if it's a newline.
undef $/;
$_ = ; # whole file now here
s/\n[ \t]+/ /g;
Also: $RS, $INPUT_RECORD_SEPARATOR, input_record_separator HANDLE EXPR
$| If set to nonzero, forces a flush after every write or print on the currently selected output channel. Default is 0. Note that STDOUT will typically be line buffered if output is to the terminal and block buffered otherwise. Setting this variable is useful primarily when you are outputting to a pipe, such as when you are running a Perl script under rsh and want to see the output as it's happening.
Also: $OUTPUT_AUTOFLUSH, autoflush HANDLE EXPR
$, The output field separator for the print operator. Ordinarily the print operator simply prints out the comma separated fields you specify. In order to get behavior more like awk, set this variable as you would set awk 's OFS variable to specify what is printed between fields.
Also: $OFS, $OUTPUT_FIELD_SEPARATOR, output_field_separator HANDLE EXPR
$\ The output record separator for the print operator. Ordinarily the print operator simply prints out the comma separated fields you specify, with no trailing newline or record separator assumed.
Also: $ORS, $OUTPUT_RECORD_SEPARATOR, output_record_separator HANDLE EXPR
$" Delimiter used when interpreting an array as a scalar. This value separates each element of the array in the resulting string - default a space.
Also: $LIST_SEPARATOR
$; The subscript separator for multi-dimensional array emulation, which can be declared directly in v.5. If you refer to a hash element as
$foo{$a,$b,$c}
it really means
$foo{join($;, $a, $b, $c)}
But don't put
@foo{$a,$b,$c} # a slice--note the @
which means
($foo{$a},$foo{$b},$foo{$c})
Default is "\034", the same as SUBSEP in awk . Note that if your keys contain binary data there might not be any safe value for " $; ".
Also: $SUBSEP, $SUBSCRIPT_SEPARATOR
$# The output format for printed numbers. The initial value is '%. 20g'. Deprecated in Perl 5.
Also: $OFMT
$% The current page number of the currently selected output channel.
Also: $FORMAT_PAGE_NUMBER, format_page_number HANDLE EXPR
$= The current page length (printable lines) of the currently selected output channel. Default is 60.
Also: $FORMAT_LINES_PER_PAGE, format_lines_per_page HANDLE EXPR
$- The number of lines left on the page of the currently selected output channel.
Also: $FORMAT_LINES_LEFT, format_lines_left HANDLE EXPR
$~ The name of the current report format for the currently selected output channel. Default is name of the filehandle.
Also: $FORMAT_NAME, format_name HANDLE EXPR
$^ The name of the current top-of-page format for the currently selected output channel. Default is name of the filehandle with _TOP appended.
Also: $FORMAT_TOP_NAME, format_top_name HANDLE EXPR
$: The current set of characters after which a string may be broken to fill continuation fields (starting with ^) in a format. Default is S<" \n-">, to break on whitespace or hyphens.
Also: $FORMAT_LINE_BREAK_CHARACTERS, format_line_break_characters HANDLE EXPR
$^ L What formats output to perform a formfeed. Default is \f.
Also: $FORMAT_FORMFEED, format_formfeed HANDLE EXPR
$^ A The current value of the write() accumulator for format() lines. A format contains formline() commands that put their result into $^ A . After calling its format, write() prints out the contents of $^ A and empties. So you never actually see the contents of $^ A unless you call formline() yourself and then look at it.
Also: $ACCUMULATOR
$? The status returned by the last pipe close, backtick ( `` ) command, or system() operator. Note that this is the status word returned by the wait() system call, so the exit value of the subprocess is actually ( $? >> 8 ). Thus on many systems, $? & 255 gives which signal, if any, the process died from, and whether there was a core dump.
Also: $CHILD_ERROR
$! If used in a numeric context, yields the current value of errno, with all the usual caveats. (This means that you shouldn't depend on the value of " $! " to be anything in particular unless you've gotten a specific error return indicating a system error.) If used in a string context, yields the corresponding system error string. You can assign to " $! " in order to set errno if, for instance, you want " $! " to return the string for error n , or you want to set the exit value for the die() operator.
Also: $ERRNO, $OS_ERROR
$@ The Perl syntax error message from the last eval() command. If null, the last eval() parsed and executed correctly (although the operations you invoked may have failed in the normal fashion).
Also: $EVAL_ERROR
$$ The process number of the Perl running this script.
Also: $PID, $PROCESS_ID
$< The real uid of this process.
Also: $UID, $REAL_USER_ID
">$> The effective uid of this process. Example:
$< = $>; # set real to effective uid
($<,$>) = ($>,$<); # swap real and effective uid
Also: $EUID, $EFFECTIVE_USER_ID
$( The real gid of this process. If you are on a machine that supports membership in multiple groups simultaneously, gives a space separated list of groups you are in. The first number is the one returned by getgid() , and the subsequent ones by getgroups() , one of which may be the same as the first number.
Also: $GID, $REAL_GROUP_ID
$) The effective gid of this process. If you are on a machine that supports membership in multiple groups simultaneously, gives a space separated list of groups you are in. The first number is the one returned by getegid() , and the subsequent ones by getgroups() , one of which may be the same as the first number.
Note: " $& lt; ", " $& gt; ", " $( " and " $) " can only be set on machines that support the corresponding set[re][ug] id() routine. " $( " and " $) " can only be swapped on machines supporting setregid() .
Also: $EGID, $EFFECTIVE_GROUP_ID
$0 Contains the name of the file containing the Perl script being executed. Assigning to " $0 " modifies the argument area that the ps(1) program sees. This is more useful as a way of indicating the current program state than it is for hiding the program you're running.
Also: $PROGRAM_NAME
$[ The index of the first element in an array, and of the first character in a substring. Default is 0, but you could set it to 1 to make Perl behave more like awk (or Fortran) when subscripting and when evaluating the index() and substr() functions.
As of Perl 5, assignment to " $[ " is treated as a compiler directive, and cannot influence the behavior of any other file. Its use is discouraged.
$] The string printed out when you say perl -v . It can be used to determine at the beginning of a script whether the perl interpreter executing the script is in the right range of versions. If used in a numeric context, returns the version + patchlevel / 1000. Example:
# see if getc is available
($version,$patchlevel) =
$] =~ /(\d+\.\d+).*\nPatch level: (\d+)/;
print STDERR "(No filename completion available.)\n"
if $version * 1000 + $patchlevel <>
or, used numerically,
warn "No checksumming!\n" if $] <>
Also: $PERL_VERSION
$^ D The current value of the debugging flags.
Also: $DEBUGGING
$^ F The maximum system file descriptor, ordinarily 2. System file descriptors are passed to exec() ed processes, while higher file descriptors are not. Also, during an open() , system file descriptors are preserved even if the open() fails. (Ordinary file descriptors are closed before the open() is attempted.) Note that the close-on-exec status of a file descriptor will be decided according to the value of $^ F at the time of the open, not the time of the exec.
Also: $SYSTEM_FD_MAX
$^ I The current value of the inplace-edit extension. Use undef to disable inplace editing.
Also: $INPLACE_EDIT
$^ P The internal flag that the debugger clears so that it doesn't debug itself. You could conceivable disable debugging yourself by clearing it.
Also: $PERLDB
$^ T The time at which the script began running, in seconds since the epoch (beginning of 1970). The values returned by the -M , -A and -C filetests are based on this value.
Also: $BASETIME
$^ W The current value of the warning switch, either TRUE or FALSE.
Also: $WARNING
$^ X The name that the Perl binary itself was executed as, from C's argv[0] .
Also: $EXECUTABLE_NAME
$ARGV The name of the current file when reading from <>.
@ARGV The array @ARGV contains the command line arguments intended for the script. Note that $# ARGV is the generally number of arguments minus one, since $ARGV [0] is the first argument, NOT the command name. See " $0 " for the command name.
@INC The array @INC contains the list of places to look for Perl scripts to be evaluated by the do EXPR , require , or use constructs. It initially consists of the arguments to any -I command line switches, followed by the default Perl library, probably "/usr/local/lib/perl", followed by ".", to represent the current directory.
%INC The hash %INC contains entries for each filename that has been included via do or require . The key is the filename you specified, and the value is the location of the file actually found. The require command uses this array to determine whether a given file has already been included.
$ENV {expr} The hash %ENV contains your current environment. Setting a value in ENV changes the environment for child processes.
$SIG {expr} The hash %SIG is used to set signal handlers for various signals.
Environment Variables
These are available as the '%ENV' hash, and retrieved as follows:
$variable = $ENV{'variable'};
The following are commonly used:
CONTENT_LENGTH The number of bytes of data passed through standard input via the POST method.
DOCUMENT_ROOT Path on the server to the web site (root URL) being accessed.
GATEWAY_INTERFACE Protocol used to communicate with the server.
HTTP_COOKIE The contents of all cookies that are visible to the script - each cookie delimited by a semicolon (';').
HTTP_USER_AGENT The name (eg. 'Mozilla') and version (eg. '4.03') of the browser used to access the server and the type of platform used by the browser (eg. 'Macintosh;I;PPC').
HTTP_REFERER The URL of the page that was being viewed when the script was accessed, either via a link or by direct entering o fthe URL. Can be used to check that the user has come from a recognised source, to help with security.
QUERY_STRING Holds the data input via the GET method.
REQUEST_METHOD Either "POST" or "GET", depending on what is set on the method attributes of the form tag. NB This value will be "POST" if method="POST", even if some data is passed via GET (eg. data appended directly to the action URL).
The following will cause both methods to be used, even though $REQUEST_METHOD="POST":
SERVER_SOFTWARE Name and version of the web server.

Saturday, March 14, 2009

Read command line arguments in perl script

Somehow, I never got it right in first attempt and hence keeping a note here.

use strict;
use Getopt::Std;
use vars qw ($opt_d $opt_p $opt_r $opt_m $opt_t $opt_a);
getopts('d:p:r:m:t:a:') ;
$Depot = $opt_d;
$Product = $opt_p;
$Release = $opt_r;
$Branch = $opt_m;
$BuildTimeStamp = $opt_t;
$Action = $opt_a;
print ("Depot == $Depot");

The most important code to note is "use vars qw" declaration for opt_? kind of variables.

Returning multiple arrays from a perl function

I wrote a perl function where I was trying to return 2 arrays from a perl function with statement,
return (@array1, @array2);
Return values were being collected as
my (@a1, @a2) = array_function ();
Even though there were no errors, my script was not working as expected. Only when I digged deeper I realized that returned arrays were not getting collected properly in @a1 & @2. Perl, was returning both of those arrays in concatenated manner and all the contents were getting assigned to single array @a1.

The fix:
To fix this issue, I changed the function to return references to array instead of arrays themselves. References are scalars and hence can be returned from functions just like any other scalar variables. Now my code inside a function changed to

return (\@array1, \@array2);

and calling statement changed to

my ($ref_a1, $ref_a2)= array_function ();
The way these references are used to retrieve the contents of array is to use a formation,
@{ref_a1} and @{ref_a2}

This one was a good learning!

Thursday, December 11, 2008

Parallel Program Execution using Windows Batch File

The requirement is to initiate 4 program executions parallely. The main calling program should not exit until all 4 executions are complete. This is how I did my POC:

a.bat : (Main Calling Script)

start cmd /T:A0 /k "call D:\scratch\sanbox\a1.bat"
start cmd /T:B0 /k "call D:\scratch\sanbox\a2.bat"
start cmd /T:C0 /k "call D:\scratch\sanbox\a3.bat"
start cmd /T:D0 /k "call D:\scratch\sanbox\a4.bat"

:TimePlease

ping 1.1.1.1 -n 3 -w 120000
echo Checking if everything is done
findstr /N ^$ a.out | findstr 4

if NOT %ERRORLEVEL% == 0 goto TimePlease



The 4 programs that were to be executed parallely:

a1.bat :

@echo "In A1 Execution"
ping 1.1.1.1 -n 10 -w 7000
@echo "A Done" >> a.out

a2.bat :

@echo "In A2 Execution"
ping 1.1.1.1 -n 30 -w 1000
@echo "AA Done" >> a.out

a3.bat :

@echo "In A3 Execution"
ping 1.1.1.1 -n 70 -w 3000
@echo "AAA Done" >> a.out

a4.bat :

@echo "In A4 Execution"
ping 1.1.1.1 -n 50 -w 5000
@echo "AAAA Done" >> a.out


The way it works is, when I invoke master script a.bat, it invokes 4 programs, named a1,a2,a3,a4. All these programs at the end of their execution, create an entry into common file a.out. Master script keeps polling a.out until it finds 4 lines in it.


Monday, September 29, 2008

Rcp issue

TERM: Undefined Variable error

This was because user was getting C shell by default. When one does an rsh/rcp the shell that gets assigned in that case is also C shell. While logging into Csh, it was trying to source .tcsh file (which had some errors) which was actually checking for TERM value and since it was not defined, the execution could not complete. Hence the error.

Remedy : Just removed .csh file and it started working.

Thursday, June 19, 2008

Windows Autologon

You want your windows machine to be in logged on state after every reboot instead of it waiting for you to enter login credentials? Here is how you do that:

Make sure that you have these 4 entries in the registy at path:

HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon

autoadminlogon REG_SZ 1
DefaultDomainName REG_SZ *Domain Name*
DefaultPassword REG_SZ *password*
DefaultUserName REG_SZ *username*

Thursday, May 29, 2008

AIX & LIBPATH

The AIX operating system assumes /usr/lib:/lib if LIBPATH is notset, if LIBPATH is set then AIX operating system only uses the pathin theLIBPATH var.

By using changing the assignment statement to
LIBPATH=${LIBPATH:-"/usr/lib:/lib"}:/home/abc/lib
we can make sure the /usr/lib:/lib is always included on theLIBPATH.

Thursday, April 17, 2008

External editing of files in Unix - II

While playing around with ex, I found one another script which is using "ed" to edit the files without actually opening them. Lets say in a text file, you want to insert particular string "Sunday is a Holiday" before every line on which the word Monday is found. Here is how you can write .ed script.

#####SCRIPT BEGINS#####
#!/bin/sh
TERM=vt100
export TERM
ed -s $1 "<<"MYEOF >/dev/null
1
/Monday/
i
Sunday is a holiday
.
w
q
MYEOF
#
exit 0
#####SCRIPT ENDS#####

Run the script as
bash-2.05$./test.ed abc.txt

So many hidden gems there!

External editing of the files in Unix

While debugging a build break, I came across some scripts which were strangely named with extension .ed. Just out of curiosity I opened one of them and I was taken aback by the contents. I just wondered to myself how the hell did I never knew this?

It was using ex (actually just a command line interface to vi), which I now realize is such a powerful tool to edit files without actually opening them in editor window one by one. Let me give you a small example of how to use it. That ease of use will demonstrate its awesome powers.

Lets say you have a file named, abc.txt. The contents of the file are

Solaris
Linux
Hpux
Aix
Windows

Now lets say you want to replace string Windows with Apple. You can write one script named replace.ed which will look something like this:

#####SCRIPT BEGINS#####
#!/bin/sh
TERM=vt100
export TERM
ex -s $1 "<<" MYEOF >/dev/null
set noignorecase
%s/Windows/Apple/g
.
w
q
MYEOF
#
exit 0
##### SCRIPT ENDS#####
Now, all you have to do is to run the script by providing the file to be edited as an input.
bash-2.05$./replace.ed abc.txt

The utility example that I have displayed here is pretty simple, but surely good enough to emphasize the power of this tool. Just imagine how quickly and automatically you can do search and replace text for n number of files by calling this script from some iterative loop.

Happy Editing!

Thursday, January 10, 2008

Memory usage report for Unix system

Following simple script will generate the report of memory usage on unix system. It will store user memory, system memory and total memory consumption numbers in the report file, mem_stat.txt

##### SCRIPT BEGIN ########
#!/bin/sh

rm -rf /tmp/mem_stat.txt
top -f /tmp/mem.txt

while [ 1 ]
do
top -f /tmp/mem.txt;
grep Memory /tmp/mem.txt awk -F" " '{print $2,$5,$8}' sed -e 's/K//g' >> /tmp/mem_stat.txt;
rm -f /tmp/mem.txt;
sleep 30;
done>> /tmp/mem_stat.txt;
rm -f /tmp/mem.txt

########SCRIPT END#########

Thursday, December 27, 2007

Command Completion Character

(Snippet from Microsoft Site)

To Activate Automatic Completion Permanently loadTOCNode(3, 'summary');
WARNING: If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.

1. Click Start, click Run, type regedit, and then click OK.
2. To enable automatic completion for the computer, locate and click the HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor key.
3. To enable automatic completion for the current user, locate and click the HKEY_CURRENT_USER\Software\Microsoft\Command Processor key.
4. For folder name completion, double-click the CompletionChar value. Type in hexadecimal the control character that you want to use. For example, if you want to use the TAB key as the control character, the control character is 0x9 (type 9 as the value; Windows converts it to hexadecimal). If you want to use the same control characters that you use for a single command session, type 0x4 for CTRL+D and 0x6 for CTRL+F. You can use the same control character for both folder and file name completion.
5. For file name completion, double-click the PathCompletionChar value. Type in hexadecimal the control character that you want to use.For example, if you want to use the TAB key as the control character, the control character is 0x9 (type 9 as the value; Windows converts it to hexadecimal). If you want to use the same control characters that you use for a single command session, type 0x4 for CTRL+D and 0x6 for CTRL+F. You can use the same control character for both folder and file name completion.
6. Quit Registry Editor.If you enable this feature for the computer, the feature is available to all users. However, you can deactivate the feature for any individual user, or you can use different control characters for that user than you applied to the computer. The user settings take precedence over the computer settings.

Thursday, December 20, 2007

Add tasks to the folder

1. Open CM Synergy command line section

2. If you have a list of CMSynergy task ids in a file D:\tasks.txt, run command



D:> for /f %a in (D:\tasks.txt) do @ccm folder -modify -at %a "-Folder ID-"