I am a DBA, worked on Windows platforms for past 6 years, and now shifted in environment where HP UX is OS environment.
I have task to complete which involves Unix script to be prepared. This script should FTP the file to the destination server and if this FTP fails, then it should write in syslog file. For the same purpose, I have prepared following script.
#!/usr/bin/sh # testftp : Script to transfer file from SAP to wowftp server #-------------------------------------------------------------------
# Timestamp echo ------------------------------------ >> /interface/logs/alhftplog.txt echo `date` Start of FTP to WOW FTP >> /interface/logs/alhftplog.txt echo ----------------------------------- >> /interface/logs/alhftplog.txt
# FTP
ftp -vn HOST NAME 2> /interface/logs/ftpfailedlog.log <<END_SCRIPT >> /interface/logs/ftplog.txt quote USER USER NAME quote PASS USER PASSWORD ascii prompt off lcd /interface/outbound cd /test mput FILE PATTERN* bye END_SCRIPT
# End of FTP
EXITSTATUS=$? if [ $EXITSTATUS != "0" ] then logger -p local6.info -t XXTIV9999E9 "FTP to Host Failed" else echo `date` "FTP Successful" >> /interface/logs/ftplog.txt fi
I am able execute above-mentioned screen and not experiencing any error. However, when I check in the system log file, no error message is being recorded.
To test this problem, I have executed “logger” command from OS prompt and I have found that error is being written in the syslog file.
Please use the code environment around your script for readability
Quote:
Originally Posted by Nishchal_Nagre
I am able execute above-mentioned screen and not experiencing any error. However, when I check in the system log file, no error message is being recorded.
ftp will not throw an error if it connects and runs commands then exits ok. You will need to capture the error from ftp itself. So you need to look at the stderr from you ftp command and see if the error on file transfer failed.Do you get anything in /interface/logs/ftpfailedlog.log?
I want to accomplish the same thing as Nischal, if anybody can shed light as to what's wrong with my script, I would appreciate it
Here is what i want to do, ftp a file to a server then if there are any errors, an email shall be sent to my account stating that the ftp process failed. However as BubbaJoe mentioned, eventhough I get an ftp error, the return code is still zero (upon checking with $?). I need to be able to capture the error code since this will be the basis for my if statement and for the script that will run after the ftp. Initially I tried this (which didn't work):
I was able to search something in the net which seemed like a good idea, since in his code, he checked the return code, the bytes transferred and transfer complete as the basis for whether there was an error:
However in that code block above, i get the error that the -c and -e commands are not valid (I am using ksh). Please help me dissect the code or if you have a suggestion on how I could check the success or not of an ftp, as well as use that error code for the email to be sent and as the basis for whether my next script will be kicked off, i would highly appreciate it.
Hello experts,
we have input files with 700K lines each (one generated for every hour). and we need to convert them as below and move them to another directory once.
Sample INPUT:-
# cat test1
1559205600000,8474,NormalizedPortInfo,PctDiscards,0.0,Interface,BG-CTA-AX1.test.com,Vl111... (7 Replies)
Hi i have write the one scripts and the scripts is error. The scripts purpose select one directory to check the file is there or not. i will give the two format of file to search the mention the path one file is there to select the file one copy the another location.please check the my script give... (1 Reply)
Hi All,
I am trying to calculate the total_amount based on two key fields. Here is the script. I am new to unix. So please help me to find out the error in this script.
I'm getting error like "command not found" and ]; is missing..
PRE_LBNO=0
PRE_DATE=0
TOT_PAY=0
for line in `cat... (4 Replies)
Shell Scipt: temp.sh
su - <$username>
expect pass.exp
Expect script: pass.exp
#!/usr/bin/expect -f
# Login
#######################
expect "Password: " send "<$password>\r"
it comes up with Password: but doesnt take password passed throguh file. (2 Replies)
Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered.
The script is as follow:
#!/bin/sh
for file in file_1.txt file_2.txt file_3.txt
do
awk '{ print "0" }' $file > tmp.tmp
mv tmp.tmp $file
done
And the cron... (2 Replies)
Hello,
I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me
1) How could I check my script when it is running from cron like... (3 Replies)
Hi all,
I have a piece of code which cork perfect. It copy the no of lines from some files (*.log) into finalLog file.
It read the lines after the line have text "ntot".
Here it is :
#!/bin/bash ... (10 Replies)
Trying to figure out why this works:
printpwd.pl
#!/usr/bin/perl
use CGI::Carp qw( fatalsToBrowser );
print "Content-type: text/html\n\n";
$A = system("pwd");
$A = `pwd`;
print "$A\n";
^^actually that works/breaks if that makes any sense.. i get the working directory twice but when... (5 Replies)
Hello all,
I have a file - 12.txt
cat 12.txt
===============================================
Number of executions = 2 Total execution time (sec.ms) = 0.009883
Number of executions = 8 Total execution time (sec.ms) = 0.001270
Number of... (23 Replies)