|
Redirecting input in a unix shell script?I have several SCO Unix script that read a parameter from user input or otherwise I put the param within my script, such as ftp scripts and so on. How can I read those parameters from a file instead? Example: I write an ftp script that will connect to a remote location and bring files, right now I write the same script as many times as I have a remote location, but I'd rather substitute the open xxxx from a file. Also if it is an interactive script and the user need to send to more than one location then I need to be able to collect all the location numbers then read then into my script. Look at the "-n" flag to the FTP program if that's what you're working with. On my system, here's what it says:
Why is this useful? Because you can then feed the program a script that has every single command you want, and you can therefore script everything "just so" without any direct interaction. In general, if you are reading from standard input, you can redirect it within some sort of loop or subshell. Here's an example taken from my popular book Wicked Cool Shell Scripts: ftp -n << EOF
open $server user ftp $anonpass get $filename $basefile quit EOF You can see where within a shell script you can gain lots of flexibility by using this technique. The more general question of redirection is one where Unix really shines as an architecture. Consider this simple shell script that I'll call test.sh: #!/bin/sh
read var1 var2 echo var1 = $var1 and var2 = $var2 exit 0 Watch what happens when we run it. Each time here, my typed in input is on bold:
$ sh test.sh
hi mom var1 = hi and var2 = mom $ echo "test two" | sh test.sh var1 = test and var2 = two I hope that all helps you see how to solve your problem!
Categorized:
Shell Script Programming
(Article 4038,
Written by Dave Taylor)
Tagged: Previous: Disable Yahoo Mail alerts in Yahoo Messenger? Next: What display driver do I need for my Dell laptop? Subscribe!
Hi, I want to connet to remote host only when I find a file in a given directory and than ftp code. Pl help Posted by: Pooja at August 18, 2005 9:24 PMwhat is the use of this line below its a scipting code ftp -n << EOF the -n option tells FTP not to ask for user login information immediately. I am working in different host. I want to connect those two host through my Script. When I trying to do them in the command prompt. It is going through fine. But through the script, I am not able to do it. Please let me know the script Posted by: Anantha Ramakrishnan at May 22, 2007 8:13 AMHi, How do I execute a shell script inside FTP commands. Thanks, when calling ftp -n <<EOF inside if loop it is giving me syntax error "<<" Unmatched Posted by: Aditya Khaund at January 19, 2008 4:07 AMHI, Thanks We are using SCO UNIX 5.05 and Informix-4gl 7.20; I would like to write a KORN shell script that will FTP file from Informix Server to Window environment and vise vesa. I have the following script but is is not working: lcd does not seem to be working. How do you write SFTP from one server to another ? Please help
I still can't have PUT my document from SCO UNIX to windows. We are using EWAN terminal emulator. Can any one please help ? Posted by: Felix Mwango Mutale at March 18, 2009 2:19 AMFor what << EOF is used in unix scripting for sql statement. Also, we have bdump area for oracle database alert log....for unix,linux,solaris,aix etc., what is the location. Posted by: NM at May 28, 2009 12:33 AMi want to echco the text on screen and same time want to log the text in log file. kns, you're looking for the "tee" command. Type in "man tee" and you'll be a happy scripter! Posted by: Dave Taylor at July 13, 2010 5:48 PMI am trying to create a function to run in a users .profile in AIX UNIX that will FTP files that the user specifies. From the command line I want the user to only type: The filenames that will be sent via FTP are the same length and all have a common format (usernamexxxxdatexxxx.txt). The problem that I am having is that I want to make the second argument "$2" a requirement and evaluate the second argument to make sure it is a number or all digits. I have looked into using the POSIX [:digit:] character class but I am not sure how to go about using it. Filename format example: My function that I want to modify: exec 4>&1 print -p open $HOST wait HOST=10.65.48.199 exec 4>&1 print -p open $HOST wait I was too busy trying to make sure the above post made sense that I forgot to ask for help. If you can, please post examples of how I can make the second argument a requirement and evaluate if it is a number. Thank you in advance! Posted by: Robert Holland at September 9, 2010 3:11 PMThe fucntion works now! I couldn't figure out how to force the user to input a number for the second argument but I figured out a work-around to force the user to input two arguments. If they don't it will present a message telling them what they need to do. I also had to add a bogus option (xyzpdq) in front of the user names in the "case" section. For some reason the script ignores whatever is in the first position. sendtoftp() { case $1 in exec 4>&1 print -p open $HOST wait HOST=10.65.48.199 exec 4>&1 print -p open $HOST wait write a unix shell script to display time in am/pm format using "if/then","case","for loop" statements? hi am sugandhi I have something to say, now that you mention it, but ...
I do have a comment, now that you mention it!
|
Recommended
Recent Entries
Search
I Need Help!
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and RSS Feeds Building Web Site Traffic Business and Management CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above Facebook Help Google Plus Help HTML and CSS Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Mac OS X Help Pay Per Click (PPC) Advertising Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help WordPress Help |