Posts

Showing posts from April, 2011

Decision Making in UNIX Shell Scripts - case Statement

The case statement allows decision making when the decisive value leads to multiple paths. The logic can be implemented using if-elifs also, but case construct makes it less complex. Syntax: case value in pattern1) commands ;; . . . esac Example: The example script reads an input from std input and stores it in the variable MONTHNUM. The case construct processes the month number and outputs corresponding month in words. "The input should be a 2 digit number and less than 13" is printed as output. #!/bin/sh read MONTHNUM?"Enter month in mm format" case $MONTHNUM in    01) print January ;;    02) print February ;;    03) print March ;;    04) print April ;;    05) print May ;;    06) print June ;;    07) print July ;;    08) print August ;;    09) print September ;;    10) print October ;;    11) print November ;;    12) print December ;;    *)  print "The input should be a 2 digit number and less than 13" ;; esac exit 0

Decision Making in UNIX Shell Scripts - if Statement

The if statement allows decision making by executing a block of script when a condition is fulfilled . Syntax: if condition then commands elif condition then commands . . . else commands fi else and elif part of the construct (shown in italics) are optional. You can use multiple elifs if needed. The conditions can be commands. The return code of the command is taken as true or false condition. Example: The example script reads an input from std input and stores it in the variable ANSWER. It checks if the number is less-than-or-equal-to or greater-than 10 and prints an output accordingly. If the input is not a number, it prints 'Could not read the input as number" as output. #!/bin/sh read ANSWER?"Choose a number " if [ $ANSWER -le 10 ]; then print The number is less than or equal to 10 elif [ $ANSWER -gt 10 ]; then print The number is greater than 10 else print Could not read the input as number fi exit 0

Interactive Shell Scripts - Read Command

Image
The read command accepts input from terminal or a file until the input reaches a newline. Examples read reads from the std input and assigns it to variable REPLY read NAME reads from the std input and assigns it to variable NAME read x y reads the first std input till the first space and assignes it to x. the rest of the input (till new line) is assigned to y. read ANSWER?"Choose a number" Displays "Choose a number", reads the input and assigns it to ANSWER. Important option flags -A                    input is stored as an array -d char             uses specified char as delimiter, instead of the default delimiter - newline -t num_sec       waits for num_sec seconds for a response -un                   reads from file descriptor n A known problem is discussed here . For some reason if the read command doesn't work use the following example: read RESPONSE < /dev/tty Further Reading Check out  Wicked Cool Shell Scripts by Dave Tay

Teracopy: Copy your files faster and easier

Image
http://xkcd.com/612/ The default method of copying a large number of files in windows can be a big pain. It stops when there is a problem with a single file; the estimate changes way too often; you can't pause it; multiple copies freeze the system. Teracopy is a free application to make copying easier. Features : Copy files faster . TeraCopy uses dynamically adjusted buffers to reduce seek times. Asynchronous copy speeds up file transfer between two physical hard drives. Pause and resume file transfers . Pause copy process at any time to free up system resources and continue with a single click. Error recovery . In case of copy error, TeraCopy will try several times and in the worse case just skip the file, not terminating the entire transfer. Interactive file list . TeraCopy shows failed file transfers and lets you fix the problem and recopy only problem files. Shell integration . TeraCopy can completely replace Explorer copy and move functions, allowing you work with

SOAP Sender Can Be Optional

Image
Did you know that you can send SOAP messages directly to the Integration Engine instead of using a SOAP sender? Send the SOAP message to  http://<server>:<port>/sap/xi/engine?type=entry&version=3.0&Sender.Service=<YourService>&Interface=<YourNamespace>%5E<YourInterface>   to bypass Adapter Engine. You cannot use this method if you need to use modules or have more than one attachment.

Developer Access Key from SAP Table

Image
Here is a simple trick to get the developer key from SAP system itself. You don't really need to go to marketplace to get a Developer Access Key. You can get it from the table  DEVACCESS using transaction SE16. To request for a new developer key, follow these steps: Log on to the URL http://service.sap.com/sscr with your SAP S-user Click on Register Developer Enter the user name(s) and select the Installation for which the developer key is required Click on Register The key will be displayed in the same screen or you can check from Developer Registered by Me or in DEVACCESS table as described earlier.

Strict Hostname Checking

Image
The default setting in SAP doesn't make a strict hostname check when executing an SSL handshake. Depending on your security audit requirements you may have to change this behaviour. You can set messaging.ssl.serverNameCheck to true in SAP XI AF Messaging service to ensure that SSL handshake succeeds only in the hostname of the server matches the CN of the public certificate.

Find Big Junk Folders to Free Up Disk Space

Image
Did you ever had to find out which folder is taking up most disk space in order to free up space? Space Sniffer is an amazing tool that helps you find the folder/file taking up most of the disk space. Very useful in locating forgotten junk files. Here is a screen shot of result from a scan. It is a 187 GB log file created by HandBrake in C:\Users******\AppData\Roaming\HandBrake\logs. Zeroing in on this file would not have been this easy otherwise. HandBrake is an excellent application. Don't judge it by this scan result.

UNIX Shell Scripting - Command Line Arguments

You can pass variables while executing the script. The command line arguments are numbered from $0 to $9, where $0 is the name of the script itself and $1 to $9 are first to ninth argument respectively. You can use more arguments by refering them as ${nn}. You can use shift command to shift the arguments to left. This is useful when you want to scan through the arguments. The following additional variables are defined apart from the command line arguments: $# refers to the number of arguments passed $@ refers to all the argumets as a string $- refers to flags called $$ refers to the PID of shell

How to Timestamp the History of Commands Used in AIX

Until AIX 5.3, one could only store what commands were run by a user. Having information on what command was run by a user ID is useful, but it is not always sufficient to conclude if that command caused a certain effect at a certain time. One needs to know WHEN a command was run as well. The command history can be time stamped from AIX 5.3 onward , by setting the following to a user's environment: EXTENDED_HISTORY=ON HISTSIZE=5000 You have to make sure that a HISTSIZE (5000 shown above is an example, you can set it to a value based on you needs) is also defined when EXTENDED_HISTORY is set. Now you could set these environment variable on each user's logon script or you can push it to all the users by adding "EXTENDED_HISTORY=ON" (without quotes) to /etc/environment and "export HISTSIZE=5000" to /etc/profile. Remember that you won't be able to see the time stamps using history command. You can see them in .sh_history file in home directory of

Finding Out ABAP Program Called by a Transaction

From Transaction Code SE93 call transaction SE93 and enter the transaction code as input. From Table TSTC Call transaction SE16 and enter table name TSTC Enter the transaction code as input.

Converting SAPscript (OTF) or Spool Request to PDF

You can do this using the report  RSTXPDFT4 . Run this report from SE38, give the spool request number as input and the pdf file names as output. The following restrictions apply: The PDF conversion only supports true bar codes for Smart Forms, which were generated with the new bar code technology with SAP NetWeaver 2004. In all other cases, the bar code is only simulated. PDF conversion, especially of ABAP lists, is slower and is therefore not suitable for mass printing. However, you can speed up the conversion to PDF using the FASTLISTCONV option in report RSTXPDF3. The font selection for ABAP lists is predefined in the PDF converter and cannot be changed.

Dealing with Interrupted Transport

If your SAP instance crashed during a tranport and you are trying to retransport the request and failing to do so, you can fix it from STMS --> Extras --> Activate Inactive Requests. If that doesn't work, try deleting all entries from the tables TRBAT and TRJOB and retry. If that also fails, check the tables TMSTLOCKR and TMSTLOCKP . These are TMS lock tables. Delete entries specific to the ones you are importing. Check for .lob file in /usr/sap/trans/tmp directory and delete it (or move it somewhere else).

Useful Oracle DBA Commands

This post will be updated with a list of useful commands for database administration . 1 To see your Oracle user id show user 2. Version of Oracle is running  select * from v$version; 3. Check which Oracle components are enabled/installed select * from v$option; 4. Check if instance is running select * from v$instance; 5. Check if database is in READ-WRITE mode select open_mode from v$database; 6. Check if any data files need recovery select * from v$recover_file; If some datafiles are listed here, they would need recovery. When a database is in backup mode, the tablespaces in backup mode will also be in recovery mode and will show up in this view. select * from v$backup; 7. Preparing a sorted list of wait events for wait analysis select EVENT, TIME_WAITED, AVERAGE_WAIT from V$SYSTEM_EVENT order by TIME_WAITED desc; 8. List all DB users SELECT USERNAME FROM DBA_USERS; 9. Change a DB user's password ALTER USER <username> IDENTIFI