ksh

expr non-numeric argument shell script

The below check is not working: if [ $LEN = `expr $CNPROC + $CTotal` ]) and returns expr non-numeric argument shell script. Always it is going to else. Please tell me what is the mistake. Earlier I was not using while so the same thing was working fine now suddenly when I did put it in the while loop it is no working. #!/usr/bin/ks...

bash/ksh/scripting eval subshell quotes

I'm using ksh and having some trouble. Why does this code not run? [root]$ CMD="ls -ltr" [root]$ eval "W=$( $CMD )" [root]$ ksh: ls -ltr: not found. [root]$ echo $W But this works fine: [root]$ CMD="ls -ltr" [root]$ eval 'W=$('$CMD')' [root]$ echo $W ...

bash ksh single quotes vs double quotes

Hi guys, I'm learning ksh, I'm trying to run a command using a subshell, but I got different results, I'm guessing the reason. root@setPrompt[/home/za] X=$("ls -ltr") ksh: ls -ltr: not found. root@setPrompt[/home/za] X=$('ls -ltr') ksh: ls -ltr: not found. root@setPrompt[/home/za] X="$(ls -ltr)" root@setPrompt[/home/za] echo $X total...

Connecting to remote server by ssh using ksh

I am trying to connect to a remote server through ssh. $ssh "username"@host "command" which prompts for password which can be done in interactive systems.But I want to automate this by passing the password as argument instead of typing interactively. I am using ksh shell and I can't use expect is there any ksh specific solution to con...

ksh : Need to delete multiple directories quickly and reliably

Hi , I have many directories and need to delete them periodically with minimum time. Additionally for each directories delete status need to know i.e whether deleted successfully or not. I need to write on the ksh . Could you please help me out. The sample code which I am using, in which I tried launching rm-rf in the background, is no...

How can I return a value from a Perl program to a Korn-shell script?

I want to do this in a shell script: #!/usr/bin/ksh PERL_PATH=/usr/local/bin/perl RET1=$(${PERL_PATH} missing_months_wrap.pl) echo $RET1 How do i do it? calling the perl script as above is giving me an error: > shell.sh Can't return outside a subroutine at missing_months_wrap.pl line 269. EDIT: inside the perl script the state...

shell scripting: nested subshell ++

Hi guys, more than a problem, this is a request for "another way to do this" actually, if a want to use the result from a previous command I into another one, I use: R1=$("cat somefile | awk '{ print $1 }'" ) myScript -c $R1 -h123 then, a "better way"is: myScript -c $("cat somefile | awk '{ print $1 }'" ) -h123 but, what if I h...

An agenda in Korn Shell: New / Edit / Delete / View appointment

As stated in the title, I have to write a simple script which should perform some typical agenda's functions. The script must use crontab. The functions are: Creating a new appointment Edit an existent appointment Delete an appointment List the appointment I really don't have a clue how to do this, can you help me with some hint? May...

Mysql,issues with into outfile, an easy solution or a better way to do it?

Hello everyone, at the moment I'm writing a simple script in ksh who should take some strings from a DB and list them on the shell. This is how it should work: Query the DB for all the datas Export them to a text file Using awk to show the different columns The problem is that two fields of the table I'm querying contain sentences. S...

Find duplicates lines based on some delimited fileds on line

Hello, I have a file with lines having some fields delimited by "|". I have to extract the lines that are identical based on some of the fileds (i.e. find lines which contain the same values for fields 1,2,3 12,and 13) Other fields contents have no importance for searching but the whole extracted lines have to be complete. Can anyone ...

Running pl/sql in Korn Shell(AIX)

I have a file to execute in Ksh written by someone. It has a set of commands to execute in sqlplus. It starts with, sqlplus -s $UP <<- END followed by a set of ddl commands such as create,drop,etc., When I execute the file in the shell, I get the error in the starting line quoted above. I understand "-s" starts the sqlplus in silent...

ksh + prinf , print the line with stat gap

I need to print the follwoing: * need smart way by printf to print this example param1 ............... value1 param2 ............... value2 param3 ............... value1 param4 ............... value2 THX ...

appending text to all files that starts with a string

How do I append a string to all the files in a directory that starts with a particular string? I tried, cat mysig >> F* But instead of appending contents of mysig to all files starting with F, it creates a file named "F*". Obviously wildcard doesn't seem to work. Any alternatives? Thanks in advance. Edit: Also how do I delete this n...

Is there an explanation of the difference between export and typeset in combination with nested function calls in a korn shell program?

I have encountered an issue with ksh programs running differently on ksh88 & ksh93 wherein functions which call functions handle differently, variables declared with typeset and export. Here is an example program that highlights the difference: #!/bin/ksh # example.ksh: highlights differences between typeset and export on ksh93 functio...

for loop range not working ksh

I tried this, #!/bin/ksh for i in {1..10} do echo "Welcome $i times" done in Ksh of an AIX box. I am getting the output as, Welcome {1..10} times What's wrong here? Isn't it supposed to print from 1 to 10?. Edit: According to perkolator's post, from http://stackoverflow.com/questions/1591109/ksh-iterate-through-a-range It wor...

echo value inside a variable ?

x=102 y=x means when i echo $y it gives x echo $y x --and not 102 and when i echo $x it give 102 lets say I dnt know what is inside y and i want the value of x to be echoed with using y someting like this a=`echo $(echo $y)` echo $a Ans 102 ...

shell scripting arithmetic operations

in general i will use expr inside shell scripts for doing arithmetic operations. is there a way where we can come up with arithmetic operation in a shell script without using expr? ...

Unknown error sourcing a script containing 'typeset -r' wrapped in command substitution

I wish to source a script, print the value of a variable this script defines, and then have this value be assigned to a variable on the command line with command substitution wrapping the source/print commands. This works on ksh88 but not on ksh93 and I am wondering why. $ cat typeset_err.ksh #!/bin/ksh unset _typeset_var typeset -i -r...

kill -9 + disable messages (standard output) from kill command

I wrote the following script which enables timeout of 20 seconds if grep can not find the relevant string in the file. The script works well, but the output from the script is like this: ./test: line 11: 30039: Killed how to disable this message from the kill command? how to tell kill command to ignore if process not exist? THX Ya...

while read loop + create aproccess in the while loop

Hi all dear friends The following test script has a problem. When I add the line (sleep 5 ) & in the script then the "while read" loop does not read all lines from the file, but only prints the first line. But when I remove the ( sleep 5 ) & from the script, then the script prints all lines as defined in the file. Why the ( sleep 5 ) ...