The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 02:58 PM
capturing line from script output and appending to a file wally_welder Shell Programming and Scripting 6 08-31-2007 04:03 AM
reading command output from shell script sri b Shell Programming and Scripting 4 11-16-2006 12:52 AM
Need help capturing pipe to a file in shell script heinz Shell Programming and Scripting 6 11-03-2005 08:27 AM
capturing output in script MizzGail Shell Programming and Scripting 6 06-02-2004 08:44 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-01-2006
designflaw designflaw is offline
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 ?
  #2 (permalink)  
Old 03-01-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,123
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.
  #3 (permalink)  
Old 03-01-2006
designflaw designflaw is offline
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0