The Korn shell (ksh) is a shell with advanced scripting features, commonly found on commercial unices and some BSD systems but rarely used on Linux.

learn more… | top users | synonyms

1
vote
3answers
514 views

How to set the command(s) that get run before every single prompt?

I used to know this but I forgot: I want to execute a command or a couple of commands before every single prompt. When I am in our PROD box, I want a big fat reminder above every prompt that says * ...
4
votes
5answers
3k views

Next day of the user entered date - date +1 day

I am new to scripting I needed a script in the AIX environment to get the next days date based on the date entered by the user of the script. After hard time browsing for this I got a piece of code ...
2
votes
3answers
77 views

Run a script on multiple shells?

I have two servers one AIX with default shell ksh, the other RHEL with default shell bash. I have a script that is mounted on both that will run similar commands but for either AIX or Linux. This ...
1
vote
3answers
73 views

How to get a response from any URL?

I have been asked to write a shell script To check if a URL is UP/Working or not for my Project. I tried to find some hints over the internet, but whatever I got is about checking whether the URL ...
3
votes
2answers
50 views

Is there a way to prevent a non-terminal-attached process from executing 'who' inside my .envfile?

I made some modifications to the /home/user/.envfile so the PS1 prompt would show date/time as well as the pwd etc. The modification is: # `who am i` is used to obtain the name of the original user ...
1
vote
1answer
263 views

How do you track memory usage in a ksh93 script

We have a number of ksh scripts that run forever (inside a while loop), or at least until a shutdown event is delivered to them. We had a project where these scripts where converted to ksh93 (and ...
1
vote
3answers
25 views

Using a command's output in printf in ksh

I am trying to perform the following : printf "Are you sure you want to copy %s (y/n) ? (file bigger than 10 MB) " "$0" It works fine, nevertheless, I would like to display the actual size of my ...
1
vote
1answer
36 views

why is EXPORT PS1 in my .profile getting clobbered?

In this question How can I get KornShell to display the date and time in the prompt? all the variables are visible in ksh except PS1 which appears to be getting replaced somehow. How can I determine ...
0
votes
1answer
51 views

Copy a file from a remote server to windows home using scp

Is there a way to copy a file from a server to a local folder (i.e. My Documents)? can it be done by scp? I have this script that generate some list. I want this script to automatically copy the ...
2
votes
1answer
40 views

How can I get KornShell to display the date and time in the prompt?

On my AIX box, which is using ksh as the default shell, I'd like the prompt to show both the date and time followed by a newline \n, along with the name of the machine, and the working directory. ...
0
votes
1answer
388 views

Using alias in another script (ksh)

I'm writing a ksh script, and I'd like to use a command define by an alias in my .profile file, in my script. I tried this command in the folder containing my script, and it works. However, in my ...
0
votes
0answers
19 views

How to capture INFORMIX DB errors in shell script?

I need to capture the informix DB errors like Update failed, Insert failed using the shell script. I am using ksh shell.
0
votes
1answer
47 views

Why does this command not work on AIX?

I want to remove UTF-8 BOM from a file using this command: sed '1 s/\xEF\xBB\xBF//' old.java > tmp.java But it did not work. I am running with ksh on AIX 7.1
5
votes
1answer
252 views

What is #@(#) in Kornshell syntax

I'm looking at a script on an AIX box where several lines begin with #@(#) What does that indicate? Clearly doing a Google search is totally fruitless for symbols. Here are the lines from the ...
2
votes
1answer
401 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
0
votes
1answer
50 views

Error unzipping file through ksh, unzip works through bash

I have an auto-generated zipfile foo.zip on a Red Hat server that needs to be extracted to a particular location /bar. This is done through an install script using ksh. When the script executes unzip ...
0
votes
1answer
48 views

how do I recursivley grep (or otherwise search for) hex strings

Long and short I'm trying to track down some files left by evil scum on a server. fgrep -r "STRING" /path/here has been working well for finding general stuff. However, how do I search for hex ...
3
votes
1answer
52 views

How do I use sudo to run multiple commands as another user within a portion of a script?

I'm trying to run the following: if [! -f .owner ]; then creator=$(whoami) sudo -u appuser ksh echo "$creator" >> .owner mkdir test1 test2 test3 exit fi However, the ...
1
vote
2answers
41 views

How to check a ksh script for syntax errors?

$ cat foo.sh #!/bin/ksh echo foo ehco foo2 It doesn't warns for errors: $ /bin/ksh -n foo.sh $ echo $? 0 Question: How can I get the "ksh -n" to warn me about syntax errors?
5
votes
2answers
189 views

how to return to underlying script from tail -f

I have a ksh script, in which I use tail -f to view a log file. How can I terminate the tail process, and continue executing the underlying script? I am running it on AIX 7.1. ...
0
votes
1answer
64 views

aix ksh start weblogic server without nohup.out and return to underlying script

I am writing a ksh script, in which I want to start weblogic server in background and return to underlying script immediately(continue to execute the script) like this: nohup ...
2
votes
3answers
203 views

Shell script not executing

Not sure what is happening. Lets call script a.sh with the following /users/guru$ cat a.sh #! /usr/bin/ksh echo "Hello" date Execute with ksh. It gets done. /users/guru$ ksh a.sh Hello Tue Jul ...
1
vote
2answers
36 views

what's the right pattern to match my command

OS: AIX 7.1 I am working on a shell script which let user input some command and execute it, one of the commands is in this form: compile appname the appname only can be one of [ccms|asws], what's ...
1
vote
3answers
86 views

Problem when splitting command with backslash in unix prompt

I often use the space-backslash combination ( ) to split a command and its parameters into various lines and make it more readable: /home/user> ls -ltra \ > file1.txt \ > file2.txt ...
1
vote
3answers
54 views

Sed + how to set parameters in sed command in order to display lines from text file

I find the following way to print line from file In this example we want to print the first line from the hosts file sed -n '1,1p' /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 ...
0
votes
2answers
519 views

Comparison of shells? [closed]

Do shells have any actual advantages or disadvantages? They can all run any binary, they all support pipes and > (output to file). Why would one choose bash over sh, or sh over ksh, etc? Why does ...
3
votes
1answer
76 views

how to get exit status from command in expect script

Below is an shell script I have written to automate entering the password for the vpnc command. The expect works fine and vpnc activated automatically after password entered, but I need to get the ...
1
vote
1answer
357 views

0403-053 Expression is not complete; more tokens expected

I have this piece of code given below as a part of my main script if [ -e /tmp/rsm/Logs/filename_$$.txt ]; then { total=0 for files in $(<filename_$$.txt); do #cd /tmp/rsm/Logs docs=`grep -i ...
0
votes
1answer
54 views

ksh, perform action when reaching loop maximal value

I am looking to write a small korn shell script doing 5 tests (by waiting some time before each one) and then, if they all fail, performing an action. I was looking at doing something like : for ...
3
votes
1answer
1k views

Installing ksh as the standard shell in Redhat: Foolhardy?

I'm not a system administrator, but my organization is considering replacing /bin/sh in Red Hat Enterprise Linux 6+ with a hard link to /bin/ksh. How foolhardy would this be? The background to this ...
3
votes
5answers
127 views

Get values block by block in same file

I have a file say "SAMPLE.txt" with following content, P1 10,9:6/123456 P2 blah blah P1 10,9:5/98765 P2 blah blah P1 blah blah P2 I want a output file say "RESULT.txt" as, Value1:123456 ...
1
vote
2answers
1k views

How to print dates between two different dates [duplicate]

I want to print dates between 2 different dates (i.e. start date and two dates) If start date is 2013-09-05 and end date is 2013-09-10, then I want result as 2013-09-05 2013-09-06 2013-09-07 ...
1
vote
2answers
146 views

Aix grep wildcard not working

I have a file called message that has the line CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/NONE/ORDRSP/758 I am doing a grep (Platform is AIX 6.1) grep ...
1
vote
2answers
55 views

How to convert text or character to hex in korn shell

Does the unix korn shell provide a function to convert text or character to hex eg. hex 31 32 37 33 34 35 35 36 36 37 value of characters 1273455667 Here i have written the code to display but i don't ...
1
vote
1answer
603 views

-ksh: revenue_ext.ksh: not found [No such file or directory]

I am getting the same not found [No such file or directory] error when trying to execute a ksh script. Read tips about the PATH and running the script with a ./ in the posts here and here and tried ...
1
vote
1answer
62 views

Using kornshell or Perl to circumvent permissions needed by root

I have a problem where I need to change the ownership and permissions of one file that exists on more than 200 servers. I belong to 2 different groups and need to change the ownership from one group ...
1
vote
0answers
34 views

Learning to use ksh88 in HP-UX [closed]

I am just a plain Linux user who played some distros since 2-3 years. Now, in the company I work there's an HP-UX server. And when I get connected to it I really felt myself like a grandma seeing ...
0
votes
1answer
31 views

KSH script missinterpreting alias stored in SQL oracle DB

I have stored the path of my file in a table with as an alias (as the complete path was too long for the table's field). However, in my KSH script, when I am doing : nomtmp=`sqlplus -S bla/bla ...
4
votes
2answers
3k views

How do I capture the return status and use tee at the same time in korn shell? [duplicate]

Consider Source code: 1. Parent.sh #!/usr/bin/ksh # No tee ksh Child.sh; exit_status=$?; echo "Exit status: ${exit_status}" # Using tee ksh Child.sh | tee -a log.txt; exit_status=$?; echo "Exit ...
11
votes
7answers
676 views

What is the difference between $* and $@?

Consider the following code: foo () { echo $* } bar () { echo $@ } foo 1 2 3 4 bar 1 2 3 4 It outputs: 1 2 3 4 1 2 3 4 I am using Ksh88, but I am interested in other common ...
2
votes
1answer
49 views

Trying to compare a variable that is multiline in a if comparison

Here is the current file I am running: #!/bin/ksh -x export BIN_DIR="../../env" . $BIN_DIR/vdenv.ksh success="DROP CREATE TABLE GRANT" $worker_dir/runsql.ksh ddl X X > chnl_avt_v1.log ...
1
vote
2answers
2k views

How can i run a part of a script as a different user?

#!/bin/ksh (some code) Log=~/my.log chown USER1 filename su - USER1 -c " date | tee -a ${Log} 2>&1; cd /blah/blah if [ SOMECONDITION ] then sh ./somescript.ksh > logfile fi exit" | tee -a ...
5
votes
1answer
187 views

Where is $_ defined by POSIX?

In the comments to the accepted answer to this Unix & Linux StackExchange question, it is stated that $_ is "one of only some 7 special parameters defined by POSIX". I can't find that definition ...
4
votes
2answers
5k views

Remove all files created before a certain date

I have a directory containing a high number of files (like logs for every day of the year). I would like to remove all files created before let's say 22/11. How can I achieve that ? Must I use find ...
0
votes
3answers
1k views

Convert Month Number to Month Name

is there a way to convert month number to name? example: 2013-10-22 will become Oct 22 I don't have the GNU date and my OS is AIX.
3
votes
5answers
2k views

Formatting the output: Underlining

I wrote the following function in ksh that prints its first argument to the screen and underlines it with the appropriate ammount of - character: print_underlined () { word=$1 echo $word ...
4
votes
4answers
2k views

Convert Unix timestamp into human-readable format on AIX

I need to convert unix timestamp (number of seconds since 1970, e.g. 1381260225 is Tue Oct 8 19:23:45 GMT 2013) into a standard human-readable format. I could get some answers by googling but those ...
1
vote
1answer
65 views

Is there an advantage in using ksh over zsh? [closed]

Or are there any advantages for using ksh over zsh? Would any specific commands not execute successfully across the shells or are the major differences not command related, but something else?
1
vote
2answers
954 views

Find all directories, in which user has access to search and echo this directories in shell

I need to find all directories, in which user has access to search(command find) and echo this directories in shell. USER is read from ksh. for example: read user I know, if user want to use find ...
1
vote
2answers
143 views

get arguments passed and put it in an array

is there a way to make the arguments passed become the element of an array? I want to access those arguments individually through array. like this: ./script.ksh arg1 arg2 arg3 then it will become ...