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.