FTP Script Help!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP Script Help!!
# 15  
Old 11-04-2014
Quote:
Originally Posted by Chubler_XL
How about:

Code:
find $READDIR -type f -name '*.ready' | while read file
do
  real_file="${file%.ready}"
  echo "put $real_file $FTPDIR" >> tde_batch
  echo "!rm $real_file" >> tde_batch
  cp $real_file $TDE_BACKUP
done

You're awesome thanks a lot!!!
# 16  
Old 11-04-2014
The other advantage of this technique is that if the sftp fails on one of the transfers for any reason while in batchmode all processing of the batchfile stops at that point so there is much less danger of deleting a file that wasn't successfully sent .
# 17  
Old 11-05-2014
Quote:
Originally Posted by Aia
I would like to bring to your attention the following combination of commands in red, which has the potential of spread disaster.

The command cd will silently change directory to your $HOME if it can not use $READDIR to change. Once's in there I don't know the mayhem that it would do, but for sure you can kiss goodbye to your data in $HOME.

Some ways to minimize the risk is to use absolute paths and if you cd check $PWD or pwd, and compare with where you should be.
Aia,
No. No. No!

The only three ways for the command:
Code:
cd $READDIR

to silently change directory to a user's home directory:
  1. READDIR is unset or set to a blank string,
  2. READDIR expands to an absolute pathname naming the user's home directory, or
  3. READDIR expands to a relative pathname that moves up or down within the file hierarchy from the current working directory to the user's home directory.
And, since gkelly1117's code includes:
Code:
export READDIR=/home/foobaruser/TDE

four lines before using $READDIR, we know that none of the above apply. If, however, the invoking user does not have permission to search /home or /home/foobaruser, or one ore more components of /home/foobaruser/TDE does not exist; then the current working directory will not be changed and a diagnostic message will be printed.

If you want to know if and invocation of cd succeeded, the proper thing to do is to check its exit status.

_____________________________________________________________
gkelly1117,
I don't understand what you're trying to do with the following code:
Code:
cd $READDIR
if [ -a  $READDIR ]
   then
     echo " $CURRDATE files found to send in $READDIR!" >>$DAEMONLOG 2>&1
   else
     echo "no files found in $READDIR to send!" >>$DAEMONLOG 2>&1
     exit
fi

Most programmers would check to see if a directory exists before trying to cd to it, or would check the exit status of the cd command. Instead of that, you blindly cd , ignore the exit status, and then check to see if a file of any type exists with that name. And then, if a file exists with the name of the directory you tried to cd to, you decide that there are files to send (without checking to see if there are any files in that directory). Why do you log a message saying files were found when you haven't looked for any files yet???

Why not wait to log a message saying you found files to process until you actually determine that there is at least one file to process? If after searching through the directory you don't find any files to process, why not log a message saying no files were found before attempting to sftp zero files?

Every time you copy a file (locally with cp or remotely with sftp), you should check the exit status. Instead of doing that, you assume that the copy succeeded and blindly remove your oriiginal. And at the end, why copy a file and remove the originals? Why not just move the file to the new name you want it to have? (That way, you don't risk running out of space for the copy, you don't have to worry about losing the original file contents if the copy failed. And, you'll know that you still have the contents of your original file either with the old name or the new name!)

Shouldn't the removal of the list of files to be copied and the files that you tried to copy to the remote system be kept until you have determined that the sftp completed successfully?
# 18  
Old 11-05-2014
Quote:
Originally Posted by Don Cragun
Aia,
No. No. No!

The only three ways for the command:
Code:
cd $READDIR

to silently change directory to a user's home directory:
  1. READDIR is unset or set to a blank string,
  2. READDIR expands to an absolute pathname naming the user's home directory, or
  3. READDIR expands to a relative pathname that moves up or down within the file hierarchy from the current working directory to the user's home
I'm sorry, but yes, yes, and yes. You just explained my point, regardless of what you thought you read on my post.

Last edited by Aia; 11-05-2014 at 01:01 AM.. Reason: Fixing listing quote
# 19  
Old 11-05-2014
Quote:
Originally Posted by Aia
I'm sorry, but yes, yes, and yes. You just explained my point, regardless of what you thought you read on my post.
You said that cd /home/foobaruser/TDE will change the current working directory to the user's home directory if it is unable to change the directory to /home/foobaruser/TDE. That will NOT happen! After running the command:
Code:
cd /home/foobaruser/TDE

the current working directory will either be the directory /home/foobaruser/TDE or the current working directory will be unchanged.
# 20  
Old 11-05-2014
@No Don,
I did not

This is what I said:
Quote:
I would like to bring to your attention the following combination of commands in red, which has the potential of spread disaster.

The command cd will silently change directory to your $HOME if it can not use $READDIR to change. Once's in there I don't know the mayhem that it would do, but for sure you can kiss goodbye to your data in $HOME.
Noticed that I only posted a small portion of the code to just bring attention to the possible harmful practice, tenting fate with rm *. I did not even do reference to the specific code, except for the $READDIR because it was there. I could had said cd $NOTHING_HERE and it would had done the job. That portion of the code was copied to help the OP know what I was talking about.

You described the specific condition I pointed out, in your point 1:
Quote:
READDIR is unset or set to a blank string,
But any of the others, would nicely had created the same disaster.

Last edited by Aia; 11-05-2014 at 02:00 AM.. Reason: puntuation
# 21  
Old 11-05-2014
Quote:
Originally Posted by Aia
@No Don, I did not

This is what I said:
Quote:
I would like to bring to your attention the following combination of commands in red, which has the potential of spread disaster.

The command cd will silently change directory to your $HOME if it can not use $READDIR to change. Once's in there I don't know the mayhem that it would do, but for sure you can kiss goodbye to your data in $HOME.
Noticed that I only posted a small portion of the code to just bring attention to the possible harmful practice, tenting fate with rm *. I did not even do reference to the specific code, except for the $READDIR because it was there. I could had said cd $NOTHING_HERE and it would had done the job. That portion of the code was copied to help the OP know what I was talking about.

You described the specific condition I pointed out in your point 1:

But any of the others, would nicely had created the same disaster.
With the code being discussed in this thread:
Code:
...
export READDIR=/home/foobaruser/TDE
#export TEMP=/opt/foobar/$ENV/tmp
export TDE_BACKUP=/home/foobaruser/TDE/backup

cd $READDIR
...

as I said before, there is absolutely no way that the cd command shown in red above is going to "silently change directory to your $HOME if it can not use $READDIR to change". I said there were three ways that a cd command could move you to $HOME AND NONE of them are possible with this code.

I fully agree that ignoring exit codes from cd, cp, sftp, and other utilities is a recipe for disaster; but there is no way the above code is ever going to silently change directory to $HOME.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

configuration for ftp script in main script

Hi, I am new to shell scripting,and i was planning to write a script that will FTP files to destination folder. I was planning that All configuration should be done through a properties files. and finally the output should be Files are transferred I have developed a properties file named... (4 Replies)
Discussion started by: rahul125
4 Replies

2. Shell Programming and Scripting

Need help in ftp script

hello , I am working on a FTP script which navigates to specific directory and pulls the file Issue which i am facing :: ---------------------------- i) When there is a file it pulls the file , but when there is not file in the directory it fails in the same statement and it is not... (3 Replies)
Discussion started by: ranga27
3 Replies

3. Linux

Need SCP script equivalent to FTP script .

Hi, Currently i'm using the folllowing FTP acript and its working. echo "open $server" > ftp_file echo "user $user $password" >> ftp_file echo "cd $remote_dir" >> ftp_file echo "lcd $local_dir" >> ftp_file echo "put $file">> ftp_file echo "bye" >> ftp_file ftp -nv < ftp_file I've... (1 Reply)
Discussion started by: vickramshetty
1 Replies

4. Shell Programming and Scripting

Automated FTP script using .netrc to multiple FTP servers

Hi all, I'm using the following script to automated ftp files to 1 ftp servers host=192.168.0.1 /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine 192.168.0.1 login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

5. Shell Programming and Scripting

passing parameter to ftp script from output of another ftp

Hi, I have a ftp script which first gets all the file names and echo's the latest file. I'm using another ftp command sets to get the file name given by first ftp. The problem is the parameter is not accepted by second ftp. The error message i'm getting is > Rename Temp File calloc:ICMP... (5 Replies)
Discussion started by: ammu
5 Replies

6. Shell Programming and Scripting

ftp script not able to connect to ftp server.

I have the following ftp script to get files from a remote location. However, on running the script I find that I am not even able to connect to ftp server. I am able to connect to ftp server using other GUI ftp tools like WS_FTP using the same IP. IP used here is a dummy IP. What can go... (3 Replies)
Discussion started by: gram77
3 Replies

7. Shell Programming and Scripting

FTP script to FTP file to UNIX - Solaris

Hello, A couple of times per week, i receive emails notifications when files are available for processing. Currently i read these eamails with a java program and store the attachement on my C: drive and would now like to generate a PC script to send this file name up to UNIX-Solaris and... (3 Replies)
Discussion started by: bobk544
3 Replies

8. Shell Programming and Scripting

Need help - script for ftp..

I have my ftp script as below.. This is logging the messages into ftp.log file , But I want the same output(what ever messages are going into ftp.log) to be printed on the console too for the user to show the status.. Tried with "tee" .. unable to get the solution.. Can some one help me... (3 Replies)
Discussion started by: Srini75
3 Replies

9. UNIX for Dummies Questions & Answers

excuting a shell script within ftp script

Novice here... I need help with excuting a shell script on a flat file that I've transfered over from a Windows XP machine for manipulation through an auto FTP script... so that after it is transfers it excutes the shell script and then returns it back to XP machine... Any ideas... (2 Replies)
Discussion started by: Gerry405
2 Replies

10. Shell Programming and Scripting

FTP script in Unix shell script

Hello , I am trying to make a shell script (Unix) for a ftp connection to another server and to get a file. So I have no knowledge about ftp and my script must do automaticly the connection with the user and passwd. Can you help us about that... Christian... (2 Replies)
Discussion started by: steiner
2 Replies
Login or Register to Ask a Question