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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing a variables value from the called script to calling script using ksh rajarkumar Shell Programming and Scripting 10 12-23-2008 02:51 AM
Include PERL script with in the unix shell script ganapati UNIX for Dummies Questions & Answers 1 04-29-2008 01:18 PM
help me in sending parameters from sqlplus script to unix shell script Hara Shell Programming and Scripting 2 01-29-2008 03:31 PM
Shell Script: want to insert values in database when update script runs ring Shell Programming and Scripting 1 10-25-2007 04:06 AM
here document to automate perl script that call script hogger84 Shell Programming and Scripting 3 10-22-2007 11:15 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 06-19-2008
Puntino Puntino is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 30
A ftp script

Hi guys

I'm writing my first shell script and I can't get rid of some errors.
First of all my shell is ash.
I've written the following script with the goal to log in on FTP server and calculate the throughput like number bytes transmitted (returned by get) /time for transmitting them.
The error tha I get when I execute my shell are:
Unresolved host -n
ftp>quote USER di leo
memory fault core dumped
Thank you in advance.



Code:
#!/bin/sh
HOST='10.0.0.201'
USER= 'dragon'
PASSWD= 'dragon'
FILE='/home/dragon/minix_modified/lance.c'
START=$(date+%s)
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
get $FILE >> NUMBYTES
END=$(date+%s)
DIFF=$(($END-$START))
THROUGHPUT= NUMBYTES/DIFF
quit
END_SCRIPT
exit 0

  #2 (permalink)  
Old 06-19-2008
p_s_shah p_s_shah is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
Check the value of $HOST

Firstly, I don't think your calculation should be done inside ftp.
Secondly, I am not sure about "get $FILE >> NUMBYTES", whether it will work or not.
Finally and most importantly, Please enable debugging using set -x and copy/paste its output for better troubleshooting.


Code:
#!/bin/sh
set -x
HOST='10.0.0.201'
USER= 'dragon'
PASSWD= 'dragon'
FILE='/home/dragon/minix_modified/lance.c'
START=$(date+%s)
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
get $FILE >> NUMBYTES
quit
END_SCRIPT
END=$(date+%s)
DIFF=$(($END-$START))
THROUGHPUT= NUMBYTES/DIFF
exit 0
set +x

Note: I hope you understand what the meaning of first line "#!/bin/sh
".
  #3 (permalink)  
Old 06-20-2008
Puntino Puntino is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 30
First of all thank you for your help.
Second I think I know the meaning of first line "#!/bin/sh, it should point out which interpreter use for your script.
To be more precise "#!" is a magic number of two bytes to identify a file or script like in this case. I'm learning script programming so I could have made some mistakes in this definition.

Any way I applied your corrections and this is the output
(Note: to log in I don't need a password so I set PASSWORD='' and the ftp server is a windows workstation


Code:

+HOST=192.168.1.6
+USER=domenik
domenik: No such file or directory
+PASSWD=
:Permission denied
+FILE=/minix/minix_modified/lance.c
+date%s
date+%s: No such file or directory
+START
+ftp -n 192.168.1.6
Memory fault - core dumped
+date%s
date+%s: no such file or directory
+END=
+-
-:No such file or directory
+DIFF=
+THROUGHPUT=NUMBYTES/DIFF
./ftp.sh:NUMBYTES/DIFF No such file or directory
+exit 0

  #4 (permalink)  
Old 06-20-2008
psiva_arul's Avatar
psiva_arul psiva_arul is offline
Registered User
  
 

Join Date: Jul 2007
Location: Bangalore, India
Posts: 97
Hi Sha,

You can try this script and let me know if you get any error

Code:
------

#!/bin/sh
set -x
HOST='10.0.0.201'
USER= 'dragon'
PASSWD= 'dragon'
DIR='/home/dragon/minix_modified/'
FILE='/home/dragon/minix_modified/lance.c'
LCL_PTH='C\Sample'
START=$(date+%s)
ftp -n $HOST <<END_SCRIPT
user $USER $PASSWD
binary
cd $DIR
lcd $LCL_PTH
get $FILE >> NUMBYTES
quit
END_SCRIPT
END=$(date+%s)
DIFF=$(($END-$START))
THROUGHPUT= NUMBYTES/DIFF
exit 0
set +x

Regards,
MPS
  #5 (permalink)  
Old 06-20-2008
Puntino Puntino is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 30
Thanks psiva_arul

Unfortunately I keep on receiving errors messages:
Before I continue bore you, i think it's better how I access to the FTP server without script.
The FTP server is mozzila on win xp
1 I type: ftp 192.168.1.6
and I'm in the directory "minix"
2 I type my username: domenik
3 I type: "the bottom return" because I don't need to write any password
4 I type: cd minix_modified
5 I type: get lance.txt
6 I type: quit

After the "get" is displayed the bytes transferred that I'm interest to pick because I want to calculate the throughput
Thank for your help
The errors with your script are:

Code:
+date%s
date+%s: No such file or directory
+START
+ftp -n 192.168.1.6
Unresolved host -n
ftp>user root
You must "open" a connection first
ftp>cd
You must "open" a connection first
ftp>lcd C\sample
Couldnt not change local directory. No such file or directory 
ftp>get lance.c>>NUMBYTES
You must "open" a connection first 
ftp>quit
FTP done
+date+%s
date+%s: No such file or directory
+END=
+-
-: No such file or directory
+DIFF= 
+THROUGHPUT= NUMBYTES/DIFF
./ftp.sh: NUMBYTES/DIFF No such file or directory
+exit 0

  #6 (permalink)  
Old 06-20-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,960
Quote:
USER= 'dragon'
PASSWD= 'dragon'
no space after '=' and quote
  #7 (permalink)  
Old 06-21-2008
itsviju itsviju is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 4
FTP Script

Hi all,
In the below script to download file names with todays date from ftp, how can i delete the file downloaded from the ftp site after sucessfully downloading the same. I am using the below script however, its not deleting after download of the file.

#!/bin/bash -vx
now_date=`date +%d%m20%y`
ftp -in 192.168.77.7<<END_SCRIPT
quote USER abc
quote PASS XXXX
bin
prompt off
cd /PC65021001 --folder on ftp
lcd /report/common/scripttesting/FTP_down --folder on local drive
mget PC65021001-${now_date}-*
mdel PC65021001-${now_date}-*
bye
END_SCRIPT
Closed Thread

Bookmarks

Tags
automated login, ftp

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 07:11 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