ksh

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

隐身守侯 提交于 2019-12-06 09:42:40
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 The original command was not interpreting the ; before myps properly. Using sh -c fixes that, but... ( please see Charles Duffy comments below ). Using a combination of single/double quotes sometimes makes the syntax easier to read and

How to reverse a string in ksh

只谈情不闲聊 提交于 2019-12-06 09:31:43
please help me with this problem, i have an array witch includes 1000 lines with number which are treated as strings and i want for all of them to reverse them one by one, my problem is how to reverse them because i have to use ksh or else with bash or something it would be so easy..... what i have now is this, but rev="$rev${copy:$y:1}" doesnt work in ksh. i=0 while [[ $i -lt 999 ]] do rev="" var=${xnumbers[$i]} copy=${var} len=${#copy} y=$(expr $len - 1) while [[ $y -ge 0 ]] do rev="$rev${copy:$y:1}" echo "y = " $y y=$(expr $y - 1) done echo "i = " $i echo "rev = " $rev #xnumbers[$i]=$(expr

Passing Special Characters into telnet Unix

瘦欲@ 提交于 2019-12-06 08:27:39
问题 I use the following command to send SMS messages through SMS Adapters: telnet localhost 0000 <<-EOF helo x MAIL FROM: Test RCPT TO: 447999999999 DATA Test £1234 . logout quit EOF However when ever I get the Message through it will be in the format: Test ?£1234 Appending the ? to the front of the £ symbol, I have tried investigating a few methods including MIME however not quite sure how they can be implemented. Any ideas on how I can stop and allow the successful passthroughs of £ 回答1: Have

Could an existing fd always be duplicated both as input and output?

*爱你&永不变心* 提交于 2019-12-06 08:23:59
问题 In bash, once a fd is in use (either as input or output): exec 7>AFile It seems that that fd number could be duplicated, both as input or output: true <&7; echo $? true >&7; echo $? The tests could be repeated for a variable as: fd=7 rco="$(true >&${fd} 2>/dev/null; echo $?)" rci="$(true <&${fd} 2>/dev/null; echo $?)" And both exit values joined in one word as: [[ "$rco$rci" = "11" ]] && echo "The fd number $fd is free" The question is: Under which conditions will the exit value of "$rco$rci"

how to check end-of-line of a text file to see if it is unix or dos format?

风格不统一 提交于 2019-12-06 03:37:44
问题 I need to convert the text file to dos format (ending each line with 0x0d0x0a , rather than 0x0a only), if the file is in unix format ( 0x0a only at the end of each line). I know how to convert it ( sed 's/$/^M/' ), but don't how how to detect the end-of-line character(s) of a file. I am using ksh. Any help would be appreciated. [Update]: Kind of figured it out, and here is my ksh script to do the check. [qiangxu@host:/my/folder]# cat eol_check.ksh #!/usr/bin/ksh if ! head -1 $1 |grep ^M$ >

suppress the output to screen in shell script

萝らか妹 提交于 2019-12-06 02:56:50
问题 Hi i have written a small script: #!/usr/bin/ksh for i in *.DAT do awk 'BEGIN{OFS=FS=","}$3~/^353/{$3="353861958962"}{print}' $i >> $i_changed awk '$3~/^353/' $i_changed >> $i_353 rm -rf $i_changed done exit i tested it and its wrking fine. But it is giving the output to screen i dont need the output to screen. i simply need the final file that is made $i_353 how is it possible? 回答1: Wrap the body of the script in braces and redirect to /dev/null: #!/usr/bin/ksh { for i in *.DAT do awk 'BEGIN

How to move files from X sub_dir to Y sub_dir

北城余情 提交于 2019-12-06 02:52:33
I have main DIR X and inside this I have many sub directories like A,B,C,D. I have main DIR Y and inside this i have many sub directories with same name as X main directory sub directories like A,B,C,D. Now I need to MOVE only files from X main dir sub directories to Y main directory sub directory. Eg: Inside main directory X ,sub directory A has 100 files and B has 1 file and C has 5 files and D has 50 files... my cursor should be at main DIR X , from there I need to MOVE all the sub directory files to same named sub directories(A,B,C,D) which is there inside Y main directory. how can I do

ksh scripting, For loop

依然范特西╮ 提交于 2019-12-06 01:54:27
问题 #!/bin/ksh ######################### for i in {1..30} ;do echo $i done output is: {1..30} What is wrong in my code? 回答1: {1..30} belongs to bash . Use this: for((i=1;i<=30;i++)); do echo $i done 回答2: Alternatively you can switch to a while construction: i=1 while (( i <= 30 )) do echo $i (( i+=1 )) done 回答3: for {set x 0} {$x<10} {incr x} { puts "x is $x" } 来源: https://stackoverflow.com/questions/9977485/ksh-scripting-for-loop

redirect plsql error message to a log file when executing it in sqlplus

喜欢而已 提交于 2019-12-05 21:37:55
Need a way to redirect PL/SQL program error message to a log file when executing it in sqlplus. Say the PL/SQL program is named send_2012.sql and it has the following exception block EXCEPTION WHEN NO_DATA_FOUND THEN var_err := 'Data not found. '; WHEN OTHERS THEN var_err := 'Error in ' || $$plsql_unit || ' | ' || SQLERRM || ' | ' || 'Details: ' || DBMS_UTILITY.format_error_backtrace; END; To run the PL/SQL program in a KornShell (ksh) script, I have: sqlplus some_username/'some_password' @some_database \ @/some/directory/send_2012.sql \ $parameter1 $paramenter2 Suppose error occurs when

Difference between ksh and bash script

风格不统一 提交于 2019-12-05 19:55:08
问题 Consider the following script (arithmetic syntax that is used for local_var2 is irrelevant for this case): #!/bin/ksh function my_func1 { typeset local_var1=one typeset local_var2 (( local_var2 = 1 )) echo my_func1: local_var1 = $local_var1, local_var2 = $local_var2 } my_func2() { typeset local_var1=two typeset local_var2 (( local_var2 = 2 )) echo my_func2: local_var1 = $local_var1, local_var2 = $local_var2 } local_var1=0 local_var2=0 echo before functions: local_var1 = $local_var1, local