New answers tagged

3

You can force interactive session using -tt switch in your script: ssh -tt user@hostB ./scripts/test.ksh Otherwise the TTY on the hostB will not get allocated and you will get such errors.


0

Some errors found: The shebang must be #!/bin/sh. All the # are a syntax error. Lines 15-21 are exactly equal to lines 4-11 (remove them). Line 58 missing $ in Col2 var for Column_list= Line 59, the echo "$Column_list">big_data_file_$$ will erase all information previously written to big_data_file$$. Change to >>. Line 93, 103, 112, 124 the if[ ...


0

An even shorter answer but a little more cryptic (works in bash and ksh): typeset -l ostype; ostype="$(uname)" cmd="alias d='du -sm -- * 2>/dev/null | sort -nr | head -20'" case $ostype in *linux*) a=ba;; *aix*) a=k;; esac a="${a:+~/".${a}shrc"}" ${a:+false} || echo "$cmd" >> "$a"


0

A more compact version (valid in ksh and bash) is: typeset -l ostype ostype="$(uname)"; cmd="alias d='du -sm -- * 2>/dev/null |sort -nr |head -n 20'" case "$ostype" in *aix*) echo "$cmd" >> ~/.kshrc; ;; *linux*) echo "$cmd" >> ~/.bash_profile; ;; esac


1

Use the shell's command expansion $(...) to switch the output file name. This code checks only for aix. The default behavior updates the .bashrc. echo "alias d='du -sm -- * 2>/dev/null | sort -nr | head -20'" >> $( case $(uname) in *[aA][iI][xX]*) echo ~/.kshrc;; *) echo ~/.bashrc;; esac ) Or, split lines for readability: rcfile=$( case ...


1

OSTYPE="`uname`" OSTYPE="${OSTYPE,,}" case "$OSTYPE" in *aix*) target=~/.kshrc ;; *linux*) target=~/.bash_profile ;; esac if [ -n "$target" ]; then echo "alias d='du -sm -- * 2>/dev/null | sort -nr | head -20'" >> "$target" fi


0

One liner: stat -c %Y /path/to/file | echo `expr $(date +%s) - $(cat)`


0

I needed to recently do something similar. I was helping with a field support issue and needed to let a technician see real time plots as they were making changes. The data is in a binary log that grows throughout the day. I have software that can parse and plot the data from logs, but it is currently not real time. What I did was capture the size of the ...


3

GNU tar's --index-file option works well: tar cvf - ./foo 2>foo.err --index-file=foo.out | squish > foo.tar.S


1

You asked for nawk or sed. As you mention ksh, why not do a pure shell version? The following runs in any POSIX compliant shell: p="Apple" while read line ; do case $line in (*$p*) echo $p${line#*$p};; esac done <<! john_Apple01_xyz_1 john_Fruit_Apple01_abc_c1 john_Apple21_trs_1 john_Fruit_Apple21_efg_1 john_Fruit_Apple21_tefg_1 ! This ...


3

@cuonglm's comment illustrates how you can do this with sed: sed -e 's/.*\(Apple\)/\1/' input.txt You might also consider using good old grep: grep -o 'Apple.*' input.txt Caveat 1 - I don't have any solaris handy, so it might be that the solaris grep doesn't have the -o option. YMMV. Caveat 2 - If your input file has lines that don't contain any ...


0

Octal numbers and permissions You can use octal number to represent mode/permission: r: 4 w: 2 x: 1 For example, for file owner you can use octal mode as follows. Read, write and execute (full) permission on a file in octal is 0+r+w+x = 0+4+2+1 = 7 Only Read and write permission on a file in octal is 0+r+w+x = 0+4+2+0 = 6 Only read and execute ...


1

It looks like your script file has DOS/Windows line endings, e.g. Carriage Return (^M, chr(13)) in addition to the Line Feed character. The output tester[2]: ^M: cannot execute [Permission denied] certainly looks like that. This would also explain why the file cannot be executed by the shell directly: It is looking for an executable named /bin/ksh^M ...


3

If your not familiar with "vi" or "emacs" prompt commands the best would be to use the fc shell built-in command look at the "fc" help into the man sh-posix manpage. Use the mouse to copy paste the commands. The HP-UX shell is /usr/bin/sh the "POSIX shell" which command prompt is close to the korn shell, by default it is set to the vi command mode "Esc" ...


2

For HP-UX you need to press Esc+K and pressing again will cycle through the history. To search through the history you can Esc+/ Search string.


0

The .profile is not your shell configuration file, it's your login session settings file. It is only read by the shell started upon login, not other interactive shells started within your login session. ksh has no dedicated customization file per-se, but it treats the $ENV variable as a path to a customization file for interactive shell sessions. So you'd ...


0

I will assume a lot, your descriptions lack much needed information, and mislead otherwise. I would assume that install.sh is the script you expect to run in bash, presented by you as: a="/var/mqm/trace/WMQUNX8000.00/LINUX/MQV8000GA/6/x86_64/install.sh" If that is true, call it as: /path/to/bash "$a" Of course, install.sh should have this code Again, ...


-1

return sets the exit status of the function, and this is a number between 0 and 255. If the number is larger than that, you get its value mod 256, and 20150225 % 256 is 209. To get a string as output from a function, the function should echo it, and then you can capture it in the caller with command substution. function convert_date_to_long { echo ...


-1

rohit, After the source do bash command on script will fix this. bash command will reload the env variables.


0

Put value to the stdout using any command and read it. # somesubscript # do something echo "my value is here" # echo is a method to put something to the stdout Give execute priv. for subscript: chmod a+rx somesubscript And use it val=$(./somesubscript) echo "$val" # will echo my value is here return and exit is used to tell caller was it okay ...


1

The $(cmd) syntax captures the standard output of cmd (stripped of trailing newline characters). So all you have to do is have getweek output the information: #! /bin/sh - date +%V # or %U or %W date outputs the week number on its stdout which it inherits from sh, which in the case of weeknum=$(getweek) is set to a pipe or socketpair by the shell at the ...


0

You can try the below one output=$(sh <scriptname>) And I feel in this case you can also try writing a function with in your script which should help to achieve your goal.


1

You can very well use echo for that purpose. $ cat new echo 1 $ number=$(./new) $ echo $number 1 I think that serves the purpose. Also note that new above is the script that you're gonna write. comment below if I mis-assumed something


2

In ksh, you can only use single digit for explicit file descriptor. With ksh93r and above, you can open more than 10 file descriptor by using the form: {var}>filename (bash and zsh copied this feature later). ksh will pick available file descriptor greater than or equal to 10, store file descriptor number in variable var: $ exec {var1}>/tmp/test1 ...


0

Let's try to work through this interactively first, then in a script. What you have typed in your question would work interactively, if the first line of your kshrc file is NOT #~/usr/bin/env ksh or #!/usr/bin/ksh or something similar. So, I'll assume we want skip the first line of kshrc file and (try to) execute the rest of the file. As an example, ...



Top 50 recent answers are included