Questions tagged [ksh]

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.

Filter by
Sorted by
Tagged with
0
votes
2answers
38 views

extract day of the month and hour of a given date format shell scripting [duplicate]

I am writing a script where I am looking for help. I am using date format in my script as below (YYYY MM DD HH MM): $ echo $DT 202002252216 Now my requirement is to compare two dates listed in the ...
-3
votes
2answers
44 views

Sending a password protected file to a remote server [closed]

can we share a password protected file to a remote server via SFTP? How do I setup the passowrd, in the source server or at the destination server?
0
votes
0answers
12 views

Using sshpass in ksh script linux

i need help with a KSH script; i have my script in host that runs a second the following command: script in host2 now i'm using sshpass -p *PASSWORD ssh - ID HOST "su - root -c '/andro/test/script2. ...
0
votes
2answers
36 views

What does this part mean in find command with -exec \{\}? [duplicate]

I have this command (KSH) find <path> -regextype posix-extended -type f -regex '.*/txt' -exec ls -l --full-time \{\} \; | sort -bnr So, I'm reading and deciphering the command above so far ...
1
vote
2answers
79 views

How to add subject to sendmail function

I have the below line code in ksh: echo -e "$SUBJECT"|/usr/sbin/sendmail -f XXXXXX@gmail.com -t XXXXXX@gmail.com but I'm still getting the $SUBJECT in the body, and not as the real subject. what's ...
0
votes
1answer
34 views

krb command not working in ksh script

On a RedHat 7, when I run the following command to get a Kerberos ticket: krb my_user It sends back : Ticket for 'my_user' is valid until 08:36 (28/01) Now I need to run this command from a script....
0
votes
0answers
27 views

How to add in if-clause in KSH?

How do I use "AND" conditioning in the if-clause? The below part isn't working....... I refer to some of the posts and some show that it needs double brackets....But I tried with while-loop, one ...
0
votes
0answers
26 views

execute a ksh file from any directory

I have a tom.ksh where it contains #!/bin/ksh . ./tom.ksh print "Check" It ought to print check when executed from any directory ./tom.ksh pop[passing argument] am I right?
0
votes
0answers
25 views

How to pass a folder as argument to the executing script? [duplicate]

I would like to execute a script(h.ksh) with the passing argument kim (which is a folder), so when I run the command h.ksh kim the folder "kim" will be used as a variable in the h.ksh Do I need ...
0
votes
2answers
65 views

how to catch response from server ping and sent alert

I have the below command I'm running: ping ldap.corp.XXXXX.com LDAP Server up: Pinging ldapeu.corp.XXXXX.com [XX.XXX.XXX.XX] with 32 bytes of data: Reply from XX.XXX.XXX.XX: bytes=32 time<1ms ...
0
votes
5answers
46 views

Awk all lines above matched parameter

I have a file called test.out with the below lines in: -rw-rw---- 1 informix informix 9117025 Jan 21 05:22 shop4_0_Log0000331875.Z -rw-rw---- 1 informix informix 8897981 Jan 21 05:24 ...
2
votes
1answer
130 views

How to create sub-directories without HTTP or HTTPS from string parameter

I have ksh script, which is running the below command: mkdir -p down/$JENKINS_URL the thing is that some $JENKINS_URL (string) includes HTTP:// and in some HTTPS://, which is causing the creation of ...
0
votes
2answers
129 views

Which code works (with builtins) both in bash and zsh with the `time` keyword?

It is usual to do time cmd for many types of cmd(s) in bash: $ time true real 0m0.000s user 0m0.000s sys 0m0.000s The output format could be changed (even to a posix format with time -p): ...
0
votes
1answer
35 views

How to set and record alerts for Jenkin server down and up

I have Jenkins pipeline job which goes thought all our Jenkins servers and check the connectivity (runs every few minutes). ksh file: #!/bin/ksh JENKINS_URL=$1 curl --connect-timeout 10 "$...
0
votes
0answers
31 views

ksh not saving history in it's HISTFILE and HISTTIMEFORMAT not working

I have created a custom shell script and put it inside /etc/profile.d/ that declares the HISTFILE. It works on bash and sh however it does not seem to work in ksh. As can be seen below, it gets the ...
0
votes
0answers
82 views

grep command to search 3rd and 4th column

I need to write a script that could grep the 3rd and 4th columns on all files in a directory. So far I have this awk command which is working fine but it is very slow since I am working on a large ...
0
votes
0answers
25 views

Excluding line numbers from sourced in files in KSH93 debug output

I have a number of ksh93 scripts on AIX 7.1 which print debug information using the following command to print the script/function name, time and line number when used with 'set-x': PS4='$0 @ `...
2
votes
2answers
67 views

increment a variable date by a month

Is there way on how to increment an input date by one month without using the date -d option? My machine do not have that functionality. Sample: $yearmonth=201912 Expected Output: 201912 202001
0
votes
0answers
155 views

execute perl script from a shell script, assign output to shell variable or print to a temporary file

Is it possible to call a script from a inside a shells script, and assign the result of that script to a shell variable? Or print the result of that perl script to a file? sample: #!/usr/bin/sh /...
0
votes
1answer
19 views

display time per minute using start and end date time

I want to write a script that will display the time per minute between two date and time. The Start and End time gap can be anything, could be 5minutes, 3hours, 30days, etc. Example: Start time: ...
0
votes
0answers
26 views

not able to use unzip command in ksh script

I am not able to use the below command unzip file_name.zip for script in #!/bin/ksh this language. I am assuming this to be incorrect because the unzip command does not turns bold and blue in ...
1
vote
1answer
23 views

Script that Show which hdisks each of the filesystems reside on for IBM AIX [closed]

i have the folowing script that Show which hdisks each of the filesystems reside on for IBM AIX. #!/bin/ksh for vg in `lsvg -o`; do for fs in `lsvgfs $vg`; do printf "%-22s" $fs; ...
0
votes
0answers
35 views

Using named pipes within ksh-script for write and read

I'm porting some ksh scripts from Solaris 10 (ksh-Version M-11/16/88i) to RedHat 7.x Linux (ksh-Version AJM 93u+ 2012-08-01) and have some difficulties with inter-process communication. Normally there ...
0
votes
2answers
129 views

getopts for parsing both long and short options

I already have a script that accepts only SHORT OPTIONS, and I want to extend the same script so as to pass the respective LONG OPTIONS. The existing code is given below. while getopts :t:c: name; do ...
-2
votes
1answer
53 views

Create and use custom .profile file

Our current Linux distribution doesn't show .proflle file in the user home folder, but as we are using ksh shell, we have the .kshrc file available. However, without playing with the kshrc file, can I ...
0
votes
0answers
26 views

How to separate & re-arrange the values of file in shell script [duplicate]

I have 2 files ex- abc.txt & xyz.txt. I've generated one shell script where I want to content of these two files. Content of the files are below- abc.txt file content- abc ---- 1 2 3 4 ...
0
votes
2answers
57 views

Error while using array in AIX : syntax error error at line 81 : '(' unexpected

I am trying to execute one .sh script in AIX environment, but it's giving an error at below line tableList = ( Value1 Value2 Value3 ) I have tried executing the script like below: sh file1.ksh I ...
0
votes
4answers
92 views

Awk in shell script

# # Script Name : extract_filename.ksh # #!/bin/ksh FILE_TO_SPLIT="CR_WKLY_Sales_SC_ON.TXT" FILE_TO_SPLIT_NEW=$(awk FILE_TO_SPLIT_AWK="$FILE_TO_SPLIT" -F'[_.]' '{print $1"_"$3"_"$4"_"$5}') echo "$...
0
votes
0answers
18 views

su <user> -c "sudo -l > some_file adding line breaks

Getting a really strange problem that I cant really get my head around at all. I am running a script as root to check a number of sudo rules are present as user X. When I run: su $USER -c "sudo -l &...
0
votes
1answer
22 views

Round 2nd decimal place when performing calculation within awk

here is a simple example: echo "36974820" | awk '{print "("$1 " KB)" " (" $1/1024 " MB)" " (" $1/1024/1024 " GB)\n"}' Output: (36974820 KB) (36108.2 MB) (35.2619 GB) What I want is below: (...
-2
votes
1answer
48 views

Arrange the value of file in UNIX shell script to come in proper output format or Transpose the file content [duplicate]

I have 3 files ex- abc.txt, def.txt & xyz.txt. I've generate one shell script where I want to content of these 3 files. Content of the files are below- abc.txt file content- abc ---- 1 2 3 ...
1
vote
2answers
220 views

How to cut date and time in Unix Scripting

I'd like to ask how to use cut or other similar command to get date and time... So basically, $line was retrieved from a for loop: for line in $(cat $file); do getdatetime=$(echo $line | cut -f4 -...
2
votes
2answers
220 views

Iterate through array of strings applying a Regex to each element in Korn Shell

I have an array of strings called names containing names with some subsequent garbage data. Like this Jill Shortz, City Contractor, America Bill Torts, Family Doctor, Canada Will Courtz, Folk DJ, ...
0
votes
1answer
41 views

ksh prompt defined as function with newlines

I wrote myself a pretty, git aware ksh prompt function. Here I only include a minimal working example so that you can see my problem without all the bloat: #!/bin/ksh function _test_prompt { ...
0
votes
1answer
33 views

ksh: appending date-time in history

Does anyone have a solution to append date and time to this as another column? It seems like it would be very useful with sorting, etc... $ history 3 history Thank you!
0
votes
2answers
92 views

Korn shell and Bash substitute variable with space over SSH

I have been trying to collect the LPAR id details in by executing a remote command from AIX server (Korn Shell) to IBM HMC (restricted Bash Shell) over SSH. Im having trouble in substituting the ...
2
votes
2answers
55 views

Better method to get a side-value from awk

I have a script whose main purpose is to gather some information and output it in a table. The primary part is an awk script: awk ' { # do some stuff, including calculating dwt ...
-1
votes
1answer
50 views

Parsing a CSV file with comma in one of its field [duplicate]

Is there a way that I can parse a CSV file which has comma as a valid character in one of its fields (which can a free form text like DESCRIPTION)? The only alternative (easy way) I have tried to ...
1
vote
2answers
72 views

Find files with user specified extensions

I am writing a script that takes multiple file extensions as a comma separated string and use it to list files within a specific directory structure, but the number of extensions provided may vary. ...
-1
votes
3answers
63 views

Mapping readings with labels [closed]

Given a list of readings in the following format: 1 1 0 0 2 3 23101 23101 0 0 2 0 5 2 0 0 1 1 0 0 2 2 23104 23104 0 0 1 0 5 1 0 0 What would be an approriate (and clean !) way to map them to their ...
0
votes
3answers
78 views

Unable to assign values to array within -exec command of find result

I have the following command written to assign find results into an array, to delete files older than 7 days later. F_ARR[0]='' unset F_ARR find "$CDIR" ! -type d -mtime +7 -exec sh -c ' for ...
0
votes
2answers
41 views

mtime changes when trying to delete files followed by directories. Best way to delete files and directories.?

I have written the following code to delete files older than 7 days, followed by deleting empty directories older than 7 days. deleting files find "$CDIR" ! -type d -mtime +7 -exec sh -c ' ...
0
votes
1answer
39 views

How to list all function names only, one per line

In ksh93 typeset -f lists all functions and its definition. $ f(){ :; } $ typeset -f f(){ :; } With the added quirk that functions that have been defined without a trailing newline are listed the ...
1
vote
1answer
2k views

/bin/ksh: bad interpreter: No such file or directory [duplicate]

I have script with #!/bin/ksh in the first line. When I try to execute this script (run ./myscript.sh) the error occurred: -bash: ./myscript.sh: /bin/ksh: bad interpreter: No such file or directory ...
5
votes
2answers
167 views

Is there a way to make the local command work portably to dash ksh bash and zsh?

In dash (and in bash zsh and some other shells) the command local works to make a variable scope limited to that function (and descendants in some cases). That enable the possibility of making a ...
21
votes
1answer
1k views

Is for(( … )){ … ;} a valid shell syntax? In which shells?

The expresion: $ ksh -c 'for ((i=0;i<10;i++)){ echo $i;}' 0 1 2 3 4 works correctly. I fail to find the description of this syntax in which the {...;} is replacing the ; do ...; done in the ...
1
vote
1answer
46 views

How to expand array elements containing variable?

I have an array in which every element may contain another variable. The array assignment is from a file as follows: FILE_CLEANUP_DIR_ARR=($(cat cleanup.list | sed '/^[[:blank:]]*$/d' | sed '/^[#]/d')...
4
votes
4answers
399 views

Just one file echoed from an array of files

I try to copy 2 or more files from one directory to another with cp using an array. I executed: files=( LocalSettings.php robots.txt .htaccess ${domain}.png googlec69e044fede13fdc....
0
votes
1answer
37 views

Naming conflict with File extension and Shebang in Linux? [duplicate]

I have seen some Linux scripts having Shebang different from the file extension. Ex: somefile.sh has #!/bin/bash inside it somefile.ksh has #!/bin/sh inside it somefile.bash has #!/bin/sh inside it ...
1
vote
1answer
31 views

How to capture no of errors in deleting multiple files in Linux?

I am deleting a no of directories/files using the following command. Per my knowledge, if any of the directory/files has access or any other issues, it will be skipped and rest of the files will be ...

1
2 3 4 5
15