The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Capturing output from grpck command on AIX pdtak UNIX for Dummies Questions & Answers 2 03-05-2008 10:58 AM
capturing line from script output and appending to a file wally_welder Shell Programming and Scripting 6 08-31-2007 12:03 AM
reading command output from shell script sri b Shell Programming and Scripting 4 11-15-2006 08:52 PM
Need help capturing pipe to a file in shell script heinz Shell Programming and Scripting 6 11-03-2005 04:27 AM
capturing output in script MizzGail Shell Programming and Scripting 6 06-02-2004 04:44 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-01-2006
Registered User
 

Join Date: Dec 2005
Location: Madison, WI
Posts: 6
Angry Capturing shell script command output

I am trying to check to see if a file exists on a ftp server, well, I know that cant be done, atleast directly, So I came up with this small script

Quote:
check_file
Code:
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd public_html/crap
dir $FILE
quit
END_SCRIPT
Where the $ variable have corresponding values, so if I run this on the promt as check_file > check.txt, I can then just check the file size for the check.txt file and know if the file exists or not. Well good deal, But I want to do the above check in the same script, for example, something like

Quote:
check_file_improved
Code:
{
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd public_html/crap
dir $FILE
quit
END_SCRIPT
} > $CHECK_FILE
if $CHECK_FILE = 0 {
  # file does not exist, lets upload the file to the server
  }
else {
  # file exists on the server, rename the file on server before uploading
  }
but somehow, I cannot capture any information into the $CHECK_FILE. Anyone ?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-01-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,334
What language you you trying to use? In the bourne, ksh, bash type shells, you do stuff like this:
FILE=/tmp/output.txt
date > $FILE
This does not change the value of FILE. In your first script you are using a here-document. The last line of your script is the end of the here-document. It does not need to be the end of the script. You can keep on going and do more stuff. Go to our FAQ section and read the article on automating ftp jobs. There are a lot of examples there.
Reply With Quote
  #3 (permalink)  
Old 03-01-2006
Registered User
 

Join Date: Dec 2005
Location: Madison, WI
Posts: 6
I am using bourne shell.

I did go on the FAQ site but I dont see an example in which we are trying to capture output generated by a script commands into a variable. Notice the bold S! . What I mean is, I need to capture output fromt the ftp command dir $FILE as this will tell me if the file exists on the ftp server.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0