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

2
votes
2answers
244 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 ...
0
votes
0answers
61 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 ...
1
vote
1answer
204 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
83 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
1
vote
1answer
120 views

How to count a string occurrence,search in between a pattern for specific string

I am working on a ksh script whose scenario is as follows: I have a text file for students' reports which contains details of students like: Student_1 Name: ABC Class:X Head Teacher:SITA Status: ...
1
vote
1answer
57 views

How to find all the hexadecimal numbers in between 2 numbers

I want to write a little function that would help me determine all the hexadecimal numbers present between 2 numbers. input.txt: 2E25:2E30 Desired output: 2E25 2E26 2E27 2E28 2E29 2E2A 2E2B 2E2C ...
1
vote
1answer
81 views

Catenation of two commands to a file and email output

#!/bin/ksh #HOSTS format: HOSTS="xxxx.xxx.xxx.xx-ACCOUNT" FILE=/home/angela/list.txt #list will be saved on list.txt date > $FILE echo >> $FILE for host in $HOSTS; do ip=$(echo ...
1
vote
2answers
196 views

Compare two times in HH:MM:SS format - ksh

Is it possible to compare two time (24-hour format)? What I need is to just check if the first time is earlier than the second time. Example: $ ./script.ksh 09:30:15 13:00:34 okay $ ./script.ksh ...
0
votes
4answers
2k views

check if date argument is in yyyy-mm-dd format [closed]

Is there a way to check if a date argument is in the correct format (YYYY-MM-DD)? I got this from the web but it doesn't work for me: date "+%Y-%m-%d" -d "2015-10-11" > /dev/null 2>&1 ...
0
votes
4answers
63 views

Use of shift $(($OPTIND -1))

I did see the post Explain shell command shift. As i am unable to comment there i would like to know the use of Shift command. Does it mean that the parameters passed to the script will be empty after ...
2
votes
1answer
168 views

SFTP Dual Factor Authentication

My Issue I am trying to automate a file fetch from an external [SFTP] server. The server is using 2-factor authentication. First, it needs a public-private key pairing established [This has already ...
1
vote
1answer
183 views

How can I see history of the “at” command in AIX?

I'm experiencing a strange problem where occasionally the at command appears to not be running the command I've configured it to run. For example: at -t 201510071042 runsomescript <Ctrl-D> ...
2
votes
1answer
53 views

Shell Script - Redirected output to a file and results are not as expected in first run

I have redirected the output of the command which returns some times 2 rows, 5 rows.. 100 rows etc in the file.. and i will use this file in if condition later to check some other conditions.. ...
1
vote
4answers
53 views

Symlinks according to directory depth

I have the following directory structure that I need to create, and while doing so, I need to also create the zip files which are symlinks. /a/2015-08-17/a.zip /a/2015-08-17/a_b/a_b.zip ...
-1
votes
4answers
486 views

Script to convert a directory of ksh scripts to bash scripts?

Since both ksh and bash are based upon sh many Korn Shell scripts (ksh) will simply run as Bourne-again Shell scripts (bash) once the shebang and file extension are changed, and you call $ bash ...
2
votes
2answers
56 views

ksh if statement syntax

I have this if statement and everytime I change sth another thing seems to be wrong.. Can you see the problem? Thanks! if [[ $(ps -ef | grep "Process" | grep -v "grep" | awk '{print $2}') = '' ]]; ...
2
votes
1answer
193 views

How to get the current date and time in YYYYMMDDHHMMSS format in ksh88?

I am new to Unix and in need of some urgent help. I looked around a lot first to find how to get date difference (in a 1 or 2 liner code). But none worked for me. My requirement is to get difference ...
1
vote
1answer
80 views

Replace or modify file contents at one shot

I have file where I need to modify some lines for every account. The line which I need to modify looks like as below: PstlInfo <some content> NNYYYN (Every account will have this line) the ...
2
votes
1answer
59 views

Script to mail PDF files [closed]

It's a wrong question..please delete itn
2
votes
2answers
295 views

Copying latest modified file from multiple directories

I have directory structure adc/asd/abc.20150918_150635.gz, adc/asd/abc.20150921_140748.gz .... (where .gz file names contain time stamps of its creation). Many other directories similar to asd are ...
4
votes
3answers
60 views

Open a file with line numbers in more (AIX)

How do I open a file in more mode with line numbers. I am using ksh on AIX for less I use -N but for more it is not working. less -N filename
0
votes
2answers
550 views

Database: 0403-009 The specified number is not valid for this command

getting the error as Database: 0403-009 The specified number is not valid for this command. Code:: #!/usr/bin/ksh #set -x WORKFILE="/tmp/oatest.out" DDLFILE="/tmp/oatest.ddl" ...
0
votes
0answers
66 views

Is the pipe overloaded?

I am using a coprocess to run commands in siebel server manager. I am reading commands from a text file (around 2000 commands) and executing them one by one in siebel server manager. After executing ...
0
votes
1answer
75 views

Remote execution of a file is not working

I'm trying to execute a local file (here /tmp/cmd) on a remote machine (slc05bkt) using SSH. Here's the command I'm trying from a script file: cmd="ssh -v ssuthari@slc05bkt \"bash -l -s\" < ...
0
votes
1answer
86 views

How to spawn new processes for new instances of the same shell script?

I'm trying to lock a file using the command lock. It's syntax is ./lock </path/to/file/name> I need to lock a bunch of files in a given directory and in order to achieve this I'm using two ...
1
vote
1answer
81 views

How to print a concatenation of strings in Korn Shell

This is my script [root@localhost scripts]# cat nested.sh #!/bin/ksh echo Enter the level of nesting read lev echo Enter the directory \( Enter the Absolute Path\) read path echo Enter the directory ...
1
vote
2answers
326 views

Script that only counts Established, TIME_WAIT, and Closed Wait connections using Netstat

I'm trying to make a script (using Perl, but it isn't necessary) that will only count the number of Established, Time_Wait, and Closed_Wait connections on a system and print them in terminal. So far ...
0
votes
0answers
625 views

telnet command with custom timeout duration

I'm trying to execute telnet command and getting the out put on shell script. But when the port not open or the ip not exist. The command take too much time to give the response. Will it be possible ...
2
votes
1answer
56 views

Can a process bring itself back to the foreground on completion? (AIX/ksh)

I have a while loop to count to 5 and echo "Done" when finished. I want to be able to execute the script in the background with "&" and continuing issuing commands while it runs. But when it's ...
-2
votes
1answer
125 views

Shell script curl limit the try time for page not found

I found following code to check web url. if curl --output /dev/null --silent --head --fail "$url"; then echo "URL exists: $url" else echo "URL does not exist: $url" fi Here if the page not ...
3
votes
2answers
462 views

Subtract floating numbers in shell script

I'm trying to do some calculation in shell script with CPU usage. Which return floating point number. But when I subtract this number I'm getting error. See the following code and error. Code ...
2
votes
1answer
47 views

make sure all lines in a textfiles don't have the same value

I have a text file that contain multiple lines. Some of the lines have contain same value. What I want is to make sure that all of the lines do not have duplicates or "triplicates". Sample: ...
2
votes
1answer
133 views

Dynamic Variable in KornShell Script

This KornShell Script (ksh): envir=Dev eval "${envir}foo=bar" echo "$Devfoo" Output: bar But I will not know what value is assigned to envir variable. So I want to do something like this where ...
0
votes
1answer
102 views

Storage allocator out of space error on unix shell script

While running the script called abc.sh, following errors are thrown. abc.sh: line 226: storage allocator out of space on 64946176 byte request ( region 64329285632 segments 1981 busy ...
1
vote
1answer
76 views

How to make awk work in a while loop

input.txt: /usr/dir1/file1 /usr/dir1/file2 /usr/dir2/file4 /usr/dir3/file5 Script: cat input.txt |while read FILENAME do nawk '{print $1}' ${FILENAME} >> output.txt done Expected output: all ...
3
votes
1answer
86 views

Setting the title for Xterm with long paths

I have the following code in my .profile: case $TERM in xterm*) HOST=`hostname` PS1='^[]0;${USER}@${HOST}: ${PWD}^Gksh$ ' ;; *) PS1='ksh$ ' ;; esac ...
-1
votes
1answer
45 views

Whats wrong with the 2nd script?

I am new to linux and scripting. I have some concerns regarding the script below which creates folder per line from file. Folder.list is located in /scripts/ . 1st script works smoothly but the 2nd ...
2
votes
1answer
91 views

Using directive and namespace aliasing with Ksh

Can I create an alias for a korn shell namespace? Is there anything like the using directive in C++ (bring several namespaces together and throw a (compiler) error if a symbol designation is ...
3
votes
2answers
199 views

bash + how to hold shell scripts

Is it possible to hold/stop the bash script progress without to kill the process? ( by kill command ) or other command For example this script - install_linux_pkgs.bash , will install Linux pkgs ...
0
votes
2answers
39 views

How to open compressed file in less mode [duplicate]

How do I open a compressed file in less mode. I am able to grep using zgrep and using zcatI can open, but the file is big I want to open in less mode.
1
vote
1answer
124 views

How to convert a generic xml format block to properties format String from an xml file using ksh script [closed]

With the conditions: I cannot use any XML parser tool as I don't have permission , read only My xmllint version does not support xpath, and I cannot update it , read only I dont have xmlstarlet and ...
1
vote
2answers
129 views

Unable to store ascii value in a variable

I am trying to convert hex to decimal to ascii and store it in a variable. I am using the following code. HEX=30 DEC=`printf "%d\n" 0x${HEX}` echo "$DEC" ASC=`printf \\$(printf '%03o' $DEC)` echo ...
1
vote
1answer
241 views

Passing multiple varibles to a script for SQL query

I have this script called info_code: #!/bin/ksh if [ $# -eq 0 ] ;then echo "Enter code : \c" read code echo "" else code=$1 fi code=`echo ${code} | tr '[a-z]' '[A-Z]'` echo "select * from ...
2
votes
4answers
468 views

How to use and/or conditional in shell script

I have an if statement in a script. It looks like this: if [ "$a" != "0" -a "$b" != "100" ]; then #some commands here If I'm not mistaken, the line above will work if both conditions are true. ...
0
votes
1answer
297 views

Convert particular lines in a text file to bold [closed]

I have a text file with 100 lines in it. I want to convert particular lines, lets say line1, line6 , line27, line 48, line 86, line99 to bold. I am using solaris 5.10, with KSH. Is there a way I can ...
1
vote
2answers
130 views

concatenating file names in a variable

I am attempting concatenate file names to use in a ftp mdelete command. Each file name needs to be separated by a space in order for the mdelete command to work. The $i variable is in a loop and I ...
1
vote
1answer
160 views

How to respond in a prompt using exec channel of JSch

I need to respond to a prompt generated by a command, for example ssh hostname then a password prompt appears and the script must automatically enter the password after the prompt. I tried ...
0
votes
2answers
49 views

Unable to perform a simple multiplication in script

I am havingf trouble performing a simple multiplication in my script. while read A B C do tmp=$A\*$C/100 echo $tmp >> out1.txt done < foo.txt foo.txt: 13721725 99 100 ...
0
votes
4answers
88 views

tabs in variable not working

I have this lines that i will insert in a mail called "header". header=" ------------------------------------- Name\tAge\tGender\tAddress ------------------------------------- " Unfortunately, the ...
5
votes
5answers
1k views

How to delete files from a folder which have more than 60 files in unix?

I want to put a script in cronjob which will run in a particular time and if the file count is more than 60, it will delete oldest files from that folder. Last In First Out. I have tried, ...