Fairly new to scripting


 
Thread Tools Search this Thread
# 1  
Fairly new to scripting

Hi, my team has existing ftp scripts that basically ftp files from one server to the other. Can anyone show me how to add some lines where if the ftp fails, an email could be sent out to myself and others on my team so that we are alerted? Thanks in advance.
# 2  
Quote:
Originally Posted by ocanyc
Hi, my team has existing ftp scripts that basically ftp files from one server to the other. Can anyone show me how to add some lines where if the ftp fails, an email could be sent out to myself and others on my team so that we are alerted? Thanks in advance.

Should look something like this

Code:
ftp -n ${HOST} << SCRIPT
user <username> <password>
binary
lcd ${WHERE_TO_SAVE}
cd ${WHERE_DOWNLOAD_FROM}
get ${WHICH_FILE_TO_GET}
quit
SCRIPT

if [ -f ${WHICH_FILE_TO_GET} ]
then
    echo "successful"
else
    echo "Failed: could not FTP"
    echo "Failed" | mailx -s "FTP failed for ${WHICH_FILE_TO_GET}" abc@xyz.com

fi

# 3  
It is tough to get return codes from ftp put / get operations. There are ways, but I am not aware of them.

I would replace ftp with an scp ( Create the keys for an auto logon ). scp does give a good return code for you.

Regards,

KapilRaj
# 4  
Quote:
Originally Posted by rakeshou
Should look something like this

Code:
ftp -n ${HOST} << SCRIPT
user <username> <password>
binary
lcd ${WHERE_TO_SAVE}
cd ${WHERE_DOWNLOAD_FROM}
get ${WHICH_FILE_TO_GET}
quit
SCRIPT

if [ -f ${WHICH_FILE_TO_GET} ]
then
    echo "successful"
else
    echo "Failed: could not FTP"
    echo "Failed" | mailx -s "FTP failed for ${WHICH_FILE_TO_GET}" abc@xyz.com

fi

Thank you for the idea. From what I can tell basically this script would just check if the file in the location but not necessarily know if the file is complete, correct?
# 5  
Quote:
Originally Posted by ocanyc
Thank you for the idea. From what I can tell basically this script would just check if the file in the location but not necessarily know if the file is complete, correct?
An astutue observation, and a condition known as partial failure. Alas FTP isn't really upto the job. SCP or SFTP would be better.

Unless you do an ftp "ls -l" of the file and decode it's length then compare that with the downloaded file.
# 6  
Quote:
Originally Posted by porter
An astutue observation, and a condition known as partial failure. Alas FTP isn't really upto the job. SCP or SFTP would be better.

Unless you do an ftp "ls -l" of the file and decode it's length then compare that with the downloaded file.
Thanks, I have a feeling I'm going to like this place and rest assured I'll have more questions Smilie.

How does SCP work? And how can I apply it to my situation? Does 'mailx' work with this as well? Yes, I guess I'm asking for sample code to understand better.
# 7  
Quote:
Originally Posted by ocanyc
How does SCP work? And how can I apply it to my situation? Does 'mailx' work with this as well?
1. scp - secure copy - man scp - basically -

Code:
scp [options] from to

2. mailx has nothing to do with scp, sftp or ftp.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #893
Difficulty: Easy
sed uses regular expressions, such as .* (zero or more of any character).
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help on a fairly complicated shell script

Hello, also with the help of some great users of this forum, I have created following shell script. MM=120 GG=5000 # get size of directory szm=$(du -s --block-size M ./192.168.1.xxx | awk '{print int($0)}') data=$(date --rfc-3339=seconds) if ; then # too big delete older files ... (10 Replies)
Discussion started by: dcaccount
10 Replies

2. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

3. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

4. Android

Android Scripting Environment: Shell Scripting and Android

I just upgraded to Android 2.2 from 2.1. The GPS issue that was troublesome in 2.1 seems to have been fixed. Some of web browsing seems faster, but it could just be my connection is better today ;) Flash works in some browsers but not very good and it is too slow for Flash apps designed for... (0 Replies)
Discussion started by: Neo
0 Replies

5. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

6. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

7. Programming

Read/Write a fairly large amount of data to a file as fast as possible

Hi, I'm trying to figure out the best solution to the following problem, and I'm not yet that much experienced like you. :-) Basically I have to read a fairly large file, composed of "messages" , in order to display all of them through an user interface (made with QT). The messages that... (3 Replies)
Discussion started by: emitrax
3 Replies

8. Programming

Does realloc free fairly?

Hello, my program works properly but valgrind tells me I am not freeing allocated memory. I think the problem is in realloc. I am pretty sure I do something wrong with realloc, because I changed it a bit and valgrind noticed less errors (that the program wasn't working properly with less errors... (3 Replies)
Discussion started by: samciz
3 Replies

9. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

10. Shell Programming and Scripting

scripting guru's pls help me with scripting on AIX

can someone pls help me with the script for a files coming from one system to a particular directory and i want to write a script to move those files to another directory on different system by renaming the files... pls someone help me on this... thanking in anticipation.... (1 Reply)
Discussion started by: thatiprashant
1 Replies

Featured Tech Videos