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.
1
vote
2answers
37 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 ...
2
votes
1answer
247 views
Del key in AIX ksh over PuTTY telnet
At the place where I work we're developing under AIX with ksh and connecting to it via telnet. Most people use ArcTel to connect, while I prefer PuTTY. The only problem I have with PuTTY is that the ...
5
votes
2answers
869 views
Adding Ctrl-L as “clear” hotkey in OpenBSD's ksh
I've been looking for a way to use Ctrl-L to clear the monitor instead of typing clear in each time. I found nothing except a patch which didn't work for me. How do I add hotkeys/shortcuts to my ...
4
votes
4answers
66 views
linux + how to ignore (filter) file with space
Sometimes a file name is created from a couple of names and space between each name as the following:
$ touch "A B C"
$ ls
A B C <-- one file but has three words ! ...
1
vote
2answers
50 views
linux + match IP ADDRESS with 3 octets or with 4 octets
how to match IP address with 4 octets or with 3 octets in one command?
target - match xxx.xxx.xxx or xxx.xxx.xxx.xxx ( syntax should fit for Linux and Solaris )
how to merge the following commands ...
5
votes
4answers
2k views
How to have separate command history for different sessions for the same user?
I face this issue on some of Unix servers. When I open different session for same user, command history is shared by all the session. This creates issues if by mistake I press Ctrl-P or up arrow and ...
2
votes
4answers
99 views
Find directories that do not contain subdirectories
I'm writing script is ksh. Need to find all directory names directly under the current directory which contain only files, not subdirectories.
I know that I could use ls -alR and recursively parse ...
4
votes
5answers
300 views
Last command in ksh
In bash I can use !! to indicate the last command. In ksh I think you can use r to do something similar, but it seems to fail in one of my common patterns: typing sudo [last command].
> cp foo ...
3
votes
1answer
70 views
Why is uname -M returning an empty string?
On the exact same machine (AIX 6.1), in 2 different login shells (both ksh), with different user IDs, I can do uname -M; in one shell I get the system model. In the other shell I get BLANK! The only ...
8
votes
7answers
485 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 ...
3
votes
1answer
85 views
Trapping dot (.) file not found errors in KSH
In ksh88, I can source a file using the "dot" command, like
. /my/file/source.ksh
However, if source.ksh doesn't exist, I want to trap the error.
So I tried this:
#!/bin/ksh
trap "echo 'Source ...
3
votes
1answer
90 views
Output of `java -version` not matched by grep or awk
On my Linux machine, it isn't clear to me why if I do the following then I don't get only the version string ("1.5.0_32").
# java -version | grep version | awk '{print $NF}'
java version "1.5.0_32"
...
-1
votes
3answers
62 views
Sorting IP address according to the second field in file
in my ksh script I need to add the following task ( OS - linux/solaris )
I have the following file
more test.txt
/etc/backup/app 172.1.120 172.110.120
/etc/backup/app 172.1.120.12 ...
3
votes
3answers
2k views
Using nohup on Solaris 10
I need to transfer a large number of files over SFTP (only between Solaris servers) which takes a very long time. I cannot keep my PC on for this duration. I tried:
nohup sftp server1
While the ...
3
votes
1answer
126 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 ...
0
votes
2answers
75 views
How to call a KSH script from another KSH script
I want to call a KSH script a KSH script.
Script 1 performs the following:
Loops thru a list of database server
Perfroms a query
Appends output from query from each database server to a txtfile
...
7
votes
3answers
2k 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 . ...
0
votes
3answers
81 views
output only file names(with spaces) in ls -Al
I should echo only names of files or directories with this construction:
ls -Al | while read string
do
...
done
ls -Al output :
drwxr-xr-x 12 s162103 studs 12 march 28 12:49 personal ...
0
votes
1answer
81 views
Must parse ls -Al output and get file or directory name [duplicate]
I must parse ls -Al output and get file or directory name
ls -Al output :
drwxr-xr-x 12 s162103 studs 12 march 28 2012 personal domain
drwxr-xr-x 2 s162103 studs 3 march 28 ...
0
votes
1answer
69 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 ...
2
votes
2answers
80 views
How do I escape a sub-directory name with an ampersand in it?
Running a kornshell and trying to traverse a directory tree.
Want to cd to a sub-directory named as follows:
-3ab_&_-3dc.img
My question is HOW do I need to escape the ampersand in this name?
...
1
vote
1answer
75 views
How to create an alias that takes an argument in KornShell
I am trying to create an alias which when given some argument will look for the folder with contains the argument as pattern. Let the alias name be gohf.
Now, I will be using this alias like gohf ...
18
votes
3answers
2k 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
1answer
61 views
What rules govern the parent-child relationship of processes launched by shell across a pipe?
#!/bin/ksh
# start_service: start the service
my_server_executable 2>&1 | my_pipe_following_shell_script &
exit 0
After I run the above start_service script from command line, it is ...
5
votes
1answer
110 views
Find all users who have more than N processes and echo them in shell
I'm writing a script in ksh. I need to find all users who have more than N processes and echo them in the shell. N is read from ksh.
I know that I should use ps -elf, but how do I parse it, find ...
0
votes
2answers
67 views
perl one liner + print VALUE in the end of the line
The following perl one liner checks if $CURRENT_VERSION matches $NEW_VERSION exactly, and prints it if it does.
Example:
CURRENT_VERSION=223.3.12.4.5.3
NEW_VERSION=223.3.12.4.5.3
DATE=17.3.2013
...
3
votes
4answers
167 views
Piping output to text file within a for loop
I'm trying to do the following within a for loop:
Find files that satisfy a condition
Echo the name of the files to a log file.
Gzip the file.
I can get the script to find the files and echo their ...
0
votes
1answer
193 views
Rename files and directories with a special characters on solaris machines
The target of the following code ( commands ) is to rename files/directories and also support files/directories with a special characters as "@" or "." etc
those commands are run fine on Linux ...
3
votes
1answer
291 views
Delete key doesn't work on command line
*Note: I asked this same question on SuperUser, but didn't get any response. I now realize this is a more appropriate forum for this particular question.
In a ksh shell, the Delete key doesn't work ...
1
vote
3answers
225 views
How to scp with regular expressions
I'm trying to copy all files that do not begin with the letter "a", in ksh.
Copying from the source machine to destination machine is working fine:
scp -p !(a*) user@machine:/path/directory/.
But, ...
0
votes
1answer
127 views
Solaris 10, Shell Script, Cursor movement [closed]
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
void prtime() {
time_t rawtime;
struct tm * ...
1
vote
2answers
69 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 ...
2
votes
1answer
339 views
Bash vs ksh pipes
I am stuck with some problems with my scripts in ksh. FWIW the problem which I am unable to overcome is that when I use a structure such as this
command | while read VAR1
do
many.commands using ...
0
votes
1answer
222 views
ksh - map Ctrl-D to exit shell
I would like to know how we can map the keys Ctrl-D in ksh to exit the shell as it does in bash shell.
Not much familiar with key binding in ksh.
Edit
My comments are after the <!-- string ...
-2
votes
2answers
132 views
History command in ksh not able to use [closed]
I am using the ksh shell. I am not getting any impact of these following commands. It is executing without any error but it is not giving the proper results.
export HISTTIMEFORMAT='%F %T '
Use the ...
1
vote
3answers
313 views
How to iterate through a comma-separated list and execute a command for each entry
I have been give a command which outputs a comma-separated list for autosys jobs in the variable $all_jobs:
box=box-of-jobs;all_jobs=$(jobscout -box $box | egrep "^\w+" | tr '\n' ',' | sed s/.$//);
...
1
vote
1answer
342 views
Reading the contents of the file and splitting using ksh
We're using a ksh script for installing one product.
I've another config file, I'd need to read this configuration file from my main script
Content of the Configuration file:
...
2
votes
1answer
601 views
Ksh Script to ftp multiple directories simultaneously
I'm new to this site and i have this problem:
I have a directory in unix with multiple directories in it. Each directory have around 5k files in it. So we are talking about 40k to 50k files. I need ...
0
votes
2answers
101 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 ...
1
vote
2answers
143 views
Pattern matching from the input arguments
we're trying to enhance the scripts.
Users will pass some arguments and part of the arguments will have 5.0.3 For an example the input argument would be like Jboss5.0.3GA. Since it ( Jboss5.0.3GA ) ...
2
votes
1answer
130 views
How to find old directories in local directory using find in AIX?
I need to find all old directories in current directory.
find in AIX does not provide -maxdepth parameter.
There is only -depth and -prune parameters.
It is possible to write something like following: ...
3
votes
1answer
181 views
Why does sendmail work differently in different shells?
The following code works when I directly run it in bash shell:
SUBJECT="SUBJECT-"`date`;
MAIL_FROM="abc@site.com";
MAIL_TO="abc@site.com";
MAIL_CC="abc@site.com";
MAIL_FILE="/path/of/html/body.html";
...
4
votes
3answers
1k views
How to get subshell's PID in Korn Shell (equivalent of $BASHPID)
In bash you have this handy variable: $BASHPID wich always returns the currently running subshell's PID. How can I get a subshell's PID in ksh? For example see the code below:
#!/usr/bin/ksh93
echo ...
2
votes
2answers
641 views
What are the dangers of setting a high limit to max File Descriptors per process?
I'm working on an old legacy application, and I commonly come across certain settings that no one around cam explain.
Apparently at some point, some processes in the application were hitting the max ...
1
vote
1answer
43 views
Unsure about the behaviour of my script when writing to log file
I have a very simple ksh script and at certain points I want to write to a log file. I use the following commands in two places...
print "Directory listing 1:\n" > ${LogFile}
ll >> ...
7
votes
4answers
967 views
Executing user defined function in a find -exec call
I'm on Solaris 10 and I have tested the following with ksh (88), bash (3.00) and zsh (4.2.1).
The following code doesn't yield any result:
function foo {
echo "Hello World"
}
find somedir -exec ...
1
vote
1answer
110 views
How do I ensure that only one instance of my ksh script runs on Solaris using NFS? [duplicate]
Possible Duplicate:
What Unix commands can be used as a semaphore/lock?
I have read many similar post and the solution seems to be to use flock. flock does not exist on my system and I ...
3
votes
3answers
605 views
Solaris: find the day of last Monday,Tuesday,…Sunday by means of shell script
I'm trying desperatly to find a bash or ksh routine that allows me to find for example the previous Monday,Tuesday,Wednesday,... preceding today's date. Additonal it has to work on plain vanilla ...
3
votes
3answers
1k views
How to use cut command to get the first and last elements of a row?
I've asked almost the same question already, but this time, I want to retrieve the X latest elements of a row of a CSV file. For example, with an input file as this one:
1;foo;bar;baz;x;y;z
...
3
votes
2answers
666 views
Creating a variable with sed in ksh
I'm using Ksh88 on a Solaris 10 machine.
If I do the following:
foo="one two three"
for i in $foo; do
echo $i;
done
The script executes as expected:
$ ./script.ksh
one
two
three
However if ...






