Shells
PREVIOUS
NEXT
Enable vi ksh command line editing
The Korn shell has the ability to utilize vi editor commands to edit commands in your history. If you are familiar with the vi editor, you will love this feature.To enable vi editing, type the following command or place it in your .kshrc file:
set -o vi
Then you can use vi commands. Press escape to enter vi command mode then you have access to many vi commands. For example, k will move up through previous commands in the history, /tail will search for the most recent command containing the word tail and pressing n will find the next occurence of that search term.
Once you have found a command that you want to repeat, just press ENTER and it will be run again. You can edit the command with R to replace characters from your current position, x to delete the current character, i to insert characters before the current character, a append characters after the current character, and $ to move to the end of the command.... Read More
Creating a kornshell script with text-based menus in VI
This recipe give a quick run-through on how to create text based menus for ksh scripts in VI. My experience is with IBM AIX 4.x. This a very, very basic recipe.
Create a new file (for example, test.ksh)
by typing: vi test.ksh
the file test.ksh will be created and opened in VI.
in this file, we will add the following lines (i will explain each below)
________
clear
print "TEST Script MENU"
PS3="Test Menu, enter choice:"
select clean_menu in "View script" "Edit script" "Print script" "Exit"
do
case $clean_menu in
"View script")
pg test.ksh;;
"Edit script")
vi test.ksh;;
"Print Report")
lp test.ksh;;
"Exit") break ;;
esac
done
_____
This will look like this when ran!
TEST Script MENU
1) View script
2) Edit script
3) Print script
4) Exit
Test Menu, enter choice:
this a super basic menu driven script.
_____
PS3= : what will show at the bottom, usually i have the name of the script (in my example, Test Menu, enter choice:)
select case_menu ... : can be whatever you choose to be, just be sure... Read More
Some Common AIX/Unix Commands
This is more of an ingredients list than a true recipe.
Here are some common AIX commands that i've come to love and hate. lsps a list paging space
lsattr El mem0 list current physical memory
extendlv hd6 16 doubled paging space from 512MB to 1024MB
(only use with IBM direction)
smit lsmksysb (list files on a tape from a mksysb)
lsdev Cc disk (shows all disk drives)
lscfg vl hdisk1 (shows info on individual disk drives, s/n, p/n, etc)
lspv shows disks installed on system
df k (shows file system size information)
lp filename (prints file to network printer)
lpstat (shows print jobs)
cancel # (cancels print job by #, found with lpstat)
enq U (restarts print que if status shows it is downmust be root)
enq Q prtx -#xxx (redirects a print job to another print que)
ps ef (shows current system processes)
errpt a (shows system error report including power outages)
errclear 0 (completely clears the system errlog viewed with errpt a)
errclear N sysplanar0 0
(clears only... Read More
appending a list of files to one file using xargs command
This recipe explains how to use the xargs command in ksh to work with multiple files. This recipe will show how to combine 10 files together into one file without manually doing a: cat file1 > bigfile, cat file2 >> bigfile, etc. The uses of this command are wide and very helpful; a great way to work with large amounts of files (also avoids the parameter list is too long message when trying to grep more than 1024 files)This is a very basic ksh command recipe.
If you work with AIX/Unix/ksh; most likely there are times when you need to do multiple things with files. This recipe will show how to append a list of files to one big file using two commands versus manually cat file1 > bigfile, then cat file2 >> bigfile, etc.
Files/Directory
ok, in my example; i am going to take the contents of 5 files and combine them into one big file.
so my files are: file1, file2, file3, file4, file5
the combined file will be called: bigfile.dat
also, i have all the files in the same directory (/usr... Read More
Checking if a variable is a number in ksh
Being able to test if a variable is a number in the Korn shell is very useful but not immediately obvious....Due to shell programming not using any kind of type checking you can sometimes end up not knowing if a variable is a number or a string. The script below will return TRUE or FALSE depending on the parameter passed to it.
#!/bin/ksh
#Stuart Brock 24.09.04
#
#Usage is isanum <PossibleNumber>
# e.g. isanum 4 -> TRUE
# isanum Not4 -> FALSE
#Will echo TRUE or FALSE depending on parameter
#
#Name Date Change
#---- ---- ------
#SGB 24.09.04 Created
#
#Notes:
expr $1 + 0 >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "FALSE"
else
echo "TRUE"
fi
The code above works by adding zero to the variable using ... Read More
Reading a list of data into a function using a script.
Well, i've been a ksh geek for only prob 2 years now, but my job requires the managing of HUGE amounts of files and data (usually about 6500 files/items per query,set). Managing and querying such large amounts of data by hand is impossible and just a waste of time when you can have a ksh script do this for you! This recipe is just an example of what you can do with some variables, menus, and functions!Overview: This recipe is more of an appetizer to the meal. I will give a few example scripts and explain how each works and from there one can hopefully use the fundamental concepts in each and apply it to one's own area/field/use. However, there is more going on in each of my examples than just the script. One has to also be sure that the way they are setting up the data to be queried is going to work.. (ie lets say we have 100 customers who are identified in your system by a 5 digit customer number; be sure to keep the data structure for them consistent so when you go back to write a sc... Read More