ksh

Executing a local shell function on a remote host over ssh using Python

自作多情 提交于 2020-01-13 19:36:12
问题 My .profile defines a function myps () { ps -aef|egrep "a|b"|egrep -v "c\-" } I'd like to execute it from my python script import subprocess subprocess.call("ssh user@box \"$(typeset -f); myps\"", shell=True) Getting an error back bash: -c: line 0: syntax error near unexpected token `;' bash: -c: line 0: `; myps' Escaping ; results in bash: ;: command not found 回答1: The original command was not interpreting the ; before myps properly. Using sh -c fixes that, but... ( please see Charles Duffy

Unix shell script run SQL scripts in parallel

橙三吉。 提交于 2020-01-13 04:47:58
问题 How do I setup this KornShell (ksh) script to run SQL scripts 2,3 in parallel after tst1.sql is done then run tst4.sql after 2,3 are complete? Is this possible? #/usr/bin/ksh #SET ENVIRONMENT ORACLE sqlplus user1/pw @/home/scripts/tst1.sql sqlplus user1/pw @/home/scripts/tst2.sql sqlplus user1/pw @/home/scripts/tst3.sql sqlplus user1/pw @/home/scripts/tst4.sql exit 0 回答1: The first command should run synchronously... If you start the two last commands as background processes (add & at the end

Regex in KornShell

不问归期 提交于 2020-01-10 14:16:22
问题 I am trying to check whether a variable is exactly two numbers but I can not seem to figure it out. How do you do check regular expressions (regex) in KornShell (ksh)? I have tried: if [[ $month =~ "[0-9]{2}" ]] if [[ $month = _[0-9]{2}_ ]] I have not been able to find any docs on it. Any insight? 回答1: case $month in [0-9][0-9]) echo "ok";; *) echo "no";; esac should work. If you need full regexp search, you can use egrep like this: if echo $month | egrep -q '^[0-9]{2}$' then echo "ok" else

How to copy a ksh associative array?

夙愿已清 提交于 2020-01-07 04:22:27
问题 Is there a way to copy an associative array? I realize that regular arrays can be copied easily with a one liner as such: set -A NEW_ARRAY $(echo ${OTHER_ARRAY[*]}) but doing so with associative arrays just gives you the values in that manner. I know about nameref but I'm interested in knowing if there's a way of copying the array such that the original array isn't affected. 回答1: untested: typeset -A NEW_ARRAY for key in "${!OTHER_ARRAY[@]}"; do NEW_ARRAY["$key"]="${OTHER_ARRAY[$key]}" done

KornShell: Variable assigned “000010” converted to 8 instead of 10.

删除回忆录丶 提交于 2020-01-06 04:51:14
问题 I have a fixed length string which is a number. When I assign the string to a variable it is getting assigned 8 instead of 10. Why? How do I stop it? $ i=10 $ ((i=i+1)) $ echo $i 11 # Right answer $ i=000010 $ ((i=i+1)) $ echo $i 9 # Wrong answer Update: The answers confirm that the number is being converted to octal and that the leading zeros need to be removed. Here is the sed command for that. echo "000010" | sed 's/0*//' 回答1: That's because a leading 0 means that the constant is octal

Setting variables in a KSH spawned process

泄露秘密 提交于 2020-01-04 16:57:50
问题 I have a lengthy menu script that relies on a few command outputs for it's variables. These commands take several seconds to run each and I would like to spawn new processes to set these variables. It would look something like this: VAR1=`somecommand` & VAR2=`somecommand` & ... wait echo $VAR1 $VAR2 The problem is that the processes are spawned and die with those variables they set. I realize that I can do this by sending these to a file and then reading that but I would like to do it without

ksh: how to probe stdin?

非 Y 不嫁゛ 提交于 2020-01-01 06:15:31
问题 I want my ksh script to have different behaviors depending on whether there is something incoming through stdin or not: (1) cat file.txt | ./script.ksh (then do "cat <&0 >./tmp.dat" and process tmp.dat) vs. (2) ./script.ksh (then process $1 which must be a readable regular file) Checking for stdin to see if it is a terminal[ -t 0 ] is not helpful, because my script is called from an other script. Doing "cat <&0 >./tmp.dat" to check tmp.dat's size hangs up waiting for an EOF from stdin if

How to overcome an incompatibility between the ksh on Linux vs. that installed on AIX/Solaris/HPUX?

久未见 提交于 2019-12-30 04:58:08
问题 I am involved in the process of porting a system containing several hundreds of ksh scripts from AIX, Solaris and HPUX to Linux. I have come across the following difference in the way ksh behaves on the two systems: #!/bin/ksh flag=false echo "a\nb" | while read x do flag=true done echo "flag = ${flag}" exit 0 On AIX, Solaris and HPUX the output is "flag = true" on Linux the output is "flag = false". My questions are: Is there an environment variable that I can set to get Linux's ksh to

Make Arrow and delete keys work in KornShell command line

泪湿孤枕 提交于 2019-12-29 03:10:08
问题 I am new to Unix and am using sun solaris (v10 I think). I have my shell set as KornShell (ksh). I am wondering how to make the arrow keys and delete key work in the command line. I have done set -o emacs and the backspace works, but not the arrow keys and the delete keys. Also is it possible to set the up and down arrow key to cycle through the command line history? 回答1: For the arrow keys, you can put this into your the .kshrc file in your home directory: set -o emacs alias __A=`echo "\020"

How can I extract a substring after a certain string in ksh?

非 Y 不嫁゛ 提交于 2019-12-25 13:47:08
问题 If I have a string like this: The important variable=123 the rest is not important. I want to extract the "123" part in ksh. So far I have tried: print awk ' {substr($line, 20) }' | read TEMP_VALUE (This 20 part is just temporary, until I work out how to extract the start position of a string.) But this just prints awk ' {substr($line, 20) }' | read TEMP_VALUE (though this format does work with code like this: print ${line} | awk '{print $1}' | read SINGLE_FILE ). Am I missing a simple