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
1answer
21 views

Issue with resize and stty on remote ssh script?

Scenario: Source host (Solaris 5.10, KSH), im trying to run the following script named sample.ksh on source #!/bin/ksh set -x Rediscover () { ssh user@hostB ./scripts/test.ksh } Rediscover exit 0 ...
-2
votes
1answer
44 views

KSH for generating 'n' of rows for a table dynamically : Issue with if else statement

I need to generate billion of records in a text file for table loading purpose. My destination table defination is: CREATE TABLE txnrecords12( txnno int, txndate string, custno int, ...
0
votes
4answers
32 views

Alias for listing top file and directory consumption - shortest way?

function isaix { echo "alias d='du -sm -- * 2>/dev/null | sort -nr | head -20'" >> ~/.kshrc; } function islinux { echo "alias d='du -sm -- * 2>/dev/null | sort -nr | head -20'" >> ...
3
votes
4answers
413 views

Calculate date difference between Last modified date of a file and NOW using shell script

I am trying to calculate the time elapsed since the log file was last updated. I guess following commands will be used lastUpdate=$(date -r myLogFile.log) now=$(date) How can I subtract them and ...
4
votes
3answers
4k views

Skip first 3 byte of a file

I am using AIX 6.1 ksh shell I want to use one liner to do something like this cat A_FILE | skip-first-3-bytes-of-the-file I want to skip the first 3 bytes of the first line, is there a way to ...
10
votes
3answers
1k views

tar to pipe but keep -v verbose output separate from STDERR

A normal tar command tar cvf foo.tar ./foo >foo.out 2>foo.err has three output IO streams archive data to foo.tar list of filenames to STDOUT (redirected into foo.out) error messages to ...
0
votes
2answers
67 views

How to cut every line from a particular string?

input.txt: john_Apple01_xyz_1 john_Fruit_Apple01_abc_c1 john_Apple21_trs_1 john_Fruit_Apple21_efg_1 john_Fruit_Apple21_tefg_1 Desired output: Apple01_xyz_1 Apple01_abc_c1 Apple21_trs_1 ...
0
votes
2answers
39 views

command not found error after giving permission to access file using chmod

I've been trying to run a script using chmod. Here's how I tried to execute the script: $ chmod u+x tester $ ./tester ./tester: Command not found. I always get the Command not found error and I'm ...
1
vote
2answers
23 views

How to get the previously used command in HP-UX reverse search

I'm using HP-UX OS and want to use previously typed command, as how I'm using in Linux Ctrl+r for ease access in the HP-UX command line.
13
votes
7answers
3k views

determine shell in script during runtime

As per my knowledge, to determine the current shell we use echo $0 in the shell. Rather I want my script to check in which shell it is running. So, I tried to print $0 in the script and it returns the ...
1
vote
3answers
3k views

Why doesn't alias work in AIX (Korn shell, .profile)?

I have these files in my home directory: drwxr-xr-x 3 meuser staff 256 Oct 12 13:11 . drwxr-xr-x 102 bin bin 4096 Sep 30 12:28 .. -rw------- 1 meuser staff ...
35
votes
4answers
4k views

Is the shell ksh93 dead?

On 10/1/2013 Glenn Fowler posted this to the ast-users mailing list: As has been pointed out several times on the AST and UWIN lists, AT&T gives very little support to OpenSouce software, ...
1
vote
1answer
44 views

Bash - Running a bash script from within a ksh script

I am on RHEL 6.7 and have a korn shell script that does check pre-reqs, prepares the system for rpm install's (creating directories if they are not already that are required by the product), stops ...
1
vote
1answer
21 views

Return long integer value from a function in ksh

I use the below function in ksh to return the long value of date parts function convert_date_to_long { long_date="${1}${2}${3}" return $long_date; } but the result i get is 209 when i ...
0
votes
1answer
22 views

cannot reload .profile from script

I am trying to reload .profile from the below script, but that doesn't work at all. #!/bin/ksh sed -i '/export rel=Rel1510_Linux/c\export rel=Rel1602_MX' ~/.profile source ~/.profile When I run ...
0
votes
4answers
42 views

Return value from a subscript in ksh

I want to call a script from inside a script like below weeknum=$(getweek ) Here getweek is a script file. How to write the sub script file so that it returns the value to weeknum. Should i use ...
3
votes
1answer
32 views

Opening more than 10 file descriptors with ksh

The shell syntax for opening a file for writing and using its file descriptor is: exec 3>output.log With bash and zsh you also can write: exec 13>output.log Thus, later in your script you ...
4
votes
1answer
769 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 ...
-1
votes
1answer
49 views

How to change shell from script

I want to change shell from ksh to bash and source the .kshrc file. I want to execute following lines of command sequentially: bash . ~/.kshrc clear Can anybody help me?
1
vote
1answer
35 views

alias su='su -' in .kshrc

I'm on OpenBSD 5.8, new to ksh and I put the string alias su='su -' in my .kshrc file as the only line. After logging in via ssh alias su gives me su alias not found and $(cat .kshrc) ...
1
vote
0answers
22 views

Background processes in ksh script are disappearing after they are kicked off

I'm having an issue with a KSH script that is supposed to kick off four processes in parallel in the background and then poll their status. Put simply, running the four processes sequentially would ...
9
votes
5answers
14k views

Is there a way to sum up the size of files listed?

This is the command I am using to list some files: find . -name \*.extract.sys -size +1000000c -exec ls -lrt {} \; -rw-r--r-- 1 qa1wrk15 test 1265190 Sep 29 01:14 ...
3
votes
3answers
2k views

forward function and variables into sudo su - <user> <<EOF

I have declared functions and variables in bash/ksh and I need to forward them into sudo su - {user} << EOF: #!/bin/bash log_f() { echo "LOG line: $@" } extVAR="yourName" sudo su - ...
1
vote
0answers
49 views

Siemens NX 10 installation: Could not determine filesystem containing /usr/ugs100

I debug script to install Siemens NX 10 applications for Debian 8.2, and get the warning: Could not determine filesystem containing /usr/ugs100 space calculations may be incorrect. The source ...
2
votes
5answers
8k views

Sum the values in a column except the header

I have a file as given below -------------------------------------------------------------- Name_Customer Item_Purchased Item_Amount Credit ...
40
votes
3answers
13k views

using single or double bracket - bash

I'm confused with using single or double bracket. look at code: dir="/home/mazimi/VirtualBox VMs" if [[ -d ${dir} ]]; then echo "yep" fi It works perfectly although the string contains space. ...
1
vote
2answers
154 views

cat command is not working inside shell script

I have the following line which is not working in ksh but works fine in sh cat `find /home/peter/databases -name "cells.txt"` This is working if this line is inside /usr/bin/sh script. But not when ...
2
votes
1answer
23 views

how to differentiate error returned while reading and for EOF in shell script

I have this task of uploading a delimited file and processing it. Once the processing is done, i either say its successful and if parsing fails, i need to throw the error. I'm reading this file line ...
2
votes
1answer
15 views

Script to see /mysqlshare is present in all list servers, doing only first iteration

I need to get /mysqlsharedetails from all the MySQL servers. I have written a script using a while read loop, but it's getting the details of only the first server, #!/bin/ksh ...
11
votes
2answers
3k views

Using sed to color the output from a command on solaris

I have a ksh script that must work on both linux and solaris. I'm trying to color the output of specific commands. It works on linux (specifically RHEL6), but not on solaris (SunOS 5.10). Command ...
2
votes
1answer
83 views

ksh: for loop to loop through files in a particular directory

schema_dir=schema_app for SCHEMA_CHANGE in $schema_dir/* do so my pwd is /A/B/C/scripts within which I have subdirectories (schema_app, schema_data, etc). I want a for loop to run through the files ...
22
votes
4answers
15k views

Getting size with du of files only

How can I get the size of all files and all files in its subdirectories using the du command. I am trying the following command to get the size of all files (and files in subdirectories) find . ...
9
votes
6answers
3k views

How can I safely get the version of ksh?

How can I safely get the version of ksh from within a ksh script? I have seen the following solutions: ksh --version echo ${.sh.version} echo $KSH_VERSION And if the circumstances are perfect, ...
2
votes
1answer
38 views

How to know log the full script name executed by user?

I want to log the full name of the script executed by the user including the options/arguments he provided to that script. I was able to achieve some success using basename and whoami but it does not ...
9
votes
7answers
289 views

Check variable is an array in Bourne like shell?

In Bourne like shell which support array variable, we can use some parsing to check if variable is an array. All commands below were run after running a=(1 2 3). zsh: $ declare -p a typeset -a a ...
6
votes
3answers
3k views

KSH - if/then/else vs. double amps (&&) and double pipes (||)

I am wondering what are the best practices regarding if/then/else ; I tend to use the following form (because I find it easier to read) #!/usr/bin/ksh # [[ -f /path/to/target/file ]] && { ...
5
votes
4answers
9k views

Subtracting dates in unix

Is there a way in unix to subtract a month or at least 30 days from a specific date? The date is to be inputted by the user. Example: 2012-11-19 - 1 month = 2013-10-19 This one doesn't work: date ...
5
votes
3answers
104 views

Is “Arithmetic Expansion” the expected action on vars inside `[[` tests?

This script: a=2 [[ "$a" -eq 2 ]] && echo yes1 [[ $a -eq 2 ]] && echo yes2 [[ a -eq 2 ]] && echo yes3 [[ "a" -eq 2 ]] && echo yes4 Does not work in dash (and ...
2
votes
1answer
8k 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 ...
0
votes
1answer
46 views

Color encoding for shell script

I using KSH shell as my linux environment. I am writing shell script for one of my project. Currently shell script does not shows color encoding for variable ,etc. It comes in black and white mode. ...
4
votes
2answers
524 views

Is there anything equivalent to getch() in ksh?

I am writing a script in Korn Shell, where at one statement I want something like getch() used in C. I want my while loop to be exited, if it sees that I have pressed ESC in Keyboard. For eg. while ...
1
vote
1answer
45 views

set -A command not running in Linux

if [ $UNITS = day ]; then while ((OFFSET > 0)); do if (( OFFSET >= day )) ;then month=$((month - 1)) if (( month == 0 )) ;then year=$((year - 1)) ...
1
vote
1answer
101 views

Find files older than a given file - a few hours

I'm using the following to find all files that are older than a reference file... find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt ... which works as expected. However, I want to ...
0
votes
2answers
862 views

Color diff output

I am new to unix I wanted to format the Unix files conditionally, I am currently working on diff command and wanted to know if it is possible to format the text of the diff command output. Example: ...
0
votes
1answer
31 views

removing all tabs in sqlplus

I can resolve this problem, but I don't understand, why happen this... My task is: (in ksh) 1st step: Query a number from a DB with sqlplus, 2nd step: Format some text for a mail, 3rd step: send a ...
2
votes
2answers
143 views

exit trap in dash vs ksh and bash

Here's a simple script that sets up a temp dir in the current dir and a trap to delete it on exit. #filename: script set -x trap 'rm -rf "$d"' exit d=`TMPDIR=$PWD mktemp -d` "$@" If I do ksh ...
2
votes
1answer
52 views

Script to mail PDF files [closed]

It's a wrong question..please delete itn
3
votes
3answers
6k views

case + how to implement equal or less or greater in case syntax

My target is to verify a range of number with (only with case + esac), and print the range. So for example: If the number is between 0 and 80, print >=0<=80 If the number is between 81 and 100 ...
0
votes
0answers
43 views

ksh script to ftp file to remote directory script

hello I have this script, basically I need to ftp to remote server only the new files for example that will be generated today or by date, so it does not import the old files, just the new ones I have ...
0
votes
2answers
66 views

mv files older than 8 days in ksh script [closed]

need help to create script in KSH to mv files to other directory in same server older than 8 days they all .CSV