ksh

Why doesn't **find** find anything?

你说的曾经没有我的故事 提交于 2019-12-05 10:46:32
问题 I'm looking for shell scripts files installed on my system, but find doesn't work: $ find /usr -name *.sh But I know there are a ton of scripts out there. For instance: $ ls /usr/local/lib/*.sh /usr/local/lib/tclConfig.sh /usr/local/lib/tkConfig.sh Why doesn't find work? 回答1: Try quoting the wildcard: $ find /usr -name \*.sh or: $ find /usr -name '*.sh' If you happen to have a file that matches *.sh in the current working directory, the wildcard will be expanded before find sees it. If you

Copy stderr and stdout to a file as well as the screen in ksh

一世执手 提交于 2019-12-05 02:53:17
问题 I'm looking for a solution (similar to the bash code below) to copy both stdout and stderr to a file in addition to the screen within ksh on Solaris. The following code works great in the bash shell: #!/usr/bin/bash # Clear the logfile >logfile.txt # Redirect all script output to a logfile as well as their normal locations exec > >(tee -a logfile.txt) exec 2> >(tee -a logfile.txt >&2) date ls -l /non-existent/path For some reason this is throwing a syntax error on Solaris. I assume it's

changing to parent directory in unix

纵饮孤独 提交于 2019-12-05 00:04:55
in general we use cd .. for going to the parent directory cd ../../ to go to the parents parent directory. and cd ../../../../../ for 5th parent directory. is there any simplified way of doing this? shell i am using is ksh. This function is for Bash, but something similar could be done for others (this may work as-is in ksh and zsh): cdn () { pushd .; for ((i=1; i<=$1; i++)); do cd ..; done; pwd; } Example usage: /some/dirs/and/subdirs$ cdn 3 /some/dirs/and/subdirs /some/dirs/and/subdirs /some /some$ popd /some/dirs/and/subdirs$ Here's a function that will cd to a named subdirectory above the

how to send a mail with a message in unix script

大兔子大兔子 提交于 2019-12-04 22:43:40
问题 New to unix and learning the talk and walk of it. I am writing a script in .ksh and have a requirement of sending a mail with a message. Currently using this command in my script: mailx -s"File not found" abc@def.com This command helps me having a subject and the recipient name. My question is how can I write a message along with it. Cause every time i run the script it pauses and asks me to enter the message and then executes, I want to pre-include the message so the script would not pause

How to read just a single character in shell script

╄→гoц情女王★ 提交于 2019-12-04 16:50:27
I want similar option like getche() in C. How can I read just a single character input from command line? Using read command can we do it? In ksh you can basically do: stty raw REPLY=$(dd bs=1 count=1 2> /dev/null) stty -raw SiegeX In bash, read can do it: read -n1 ans fess . read -n1 works for bash The stty raw mode prevents ctrl-c from working and can get you stuck in an input loop with no way out. Also the man page says stty -raw is not guaranteed to return your terminal to the same state. So, building on dtmilano's answer using stty -icanon -echo avoids those issues. #/bin/ksh ## /bin/{ksh

connect to sqlplus only once without writing to a file in a loop

你。 提交于 2019-12-04 15:04:09
I have a requirement for which I need to write a ksh script that reads command line parameters into arrays and creates DML statements to insert records into an oracle database. I've created a script as below to achieve this. However, the user invoking the script doesn't have permission to write into the directory where the script has to run. So, is there a way we can fire multiple inserts on the database without connecting to sqlplus multiple times within the loop and at the same time, NOT create temp sql file as below? Any ideas are highly appreciated. Thanks in advance! i=0 while (( i<$src

Passing Special Characters into telnet Unix

大城市里の小女人 提交于 2019-12-04 13:49:38
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 £ Have you tried encoding the message first? You can do this using base64 in UTF-8 charset:- e.g. Convert: msg="

Create a pipe that writes to multiple files (tee)

耗尽温柔 提交于 2019-12-04 13:27:50
问题 I would like to create a pipe in a ksh script (using exec) that pipe's to a tee, and sends the output to a pipe. Current: #Redirect EVERYTHING exec 3>&1 #Save STDOUT as 3 exec 4>&2 #Save STDERR as 4 exec 1>${Log} #Redirect STDOUT to a log exec 2>&1 #Redirect STDERR to STDOUT What'd I'd like to do (but I don't have the syntax correct): #Redirect EVERYTHING exec 3>&1 #Save STDOUT as 3 exec 4>&2 #Save STDERR as 4 exec 1>tee -a ${Log} >&3 #Redirect STDOUT to a log exec 2>&1 #Redirect STDERR to

How to custom display prompt in KornShell to show hostname and current directory?

余生长醉 提交于 2019-12-04 08:32:47
问题 I am using KornShell (ksh) on Solaris and currently my PS1 env var is: PS1="${HOSTNAME}:\${PWD} \$ " And the prompt displays: hostname:/full/path/to/current/directory $ However, I would like it to display: hostname:directory $ In other words, how can I display just the hostname and the name of the current directory, i.e. tmp or ~ or public_html etc etc? 回答1: From reading the ksh man page you want PS1="${HOSTNAME}:\${PWD##*/} \$ " Tested on default ksh on SunOS 5.8 回答2: Okay, a little old and

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

强颜欢笑 提交于 2019-12-04 08:26: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$ >/dev/null 2>&1; then echo UNIX else echo DOS fi In the above script, ^M should be inserted in vi with