Log file is not getting created & unable to grep error from it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Log file is not getting created & unable to grep error from it
Prev   Next
# 1  
Old 07-03-2010
Log file is not getting created & unable to grep error from it

Hi All,

Below is my code,what I am trying to do is redirecting output of ftp to a log file & then greping the errors but here I am unable to grep "Permission denied" error only & also the corresponding log file is also not getting created.

Code:
#!/bin/sh

. cfg

USER='abc'
PASSWD='abc123'

MPGS_FILE_DIR_ON_LOCAL_MACHINE=$MNP_HOME

PORTIN_FILE_PREFIX='MNP_PORT_IN'
PORTOUT_FILE_PREFIX='MNP_PORT_OUT'
ACKPATTERN='.ack'
PORTIN_ACKDIR='/mpgapp/kenan/port-in/order_ack/ready'
PORTOUT_ACKDIR='/mpgapp/kenan/port-out/order_ack/ready'

COMPLETIONPATTERN='.comp'
PORTIN_COMPLETIONDIR='/mpgapp/kenan/port-in/order_comp/ready'
PORTOUT_COMPLETIONDIR='/mpgapp/kenan/port-out/order_comp/ready'

REJECTPATTERN='.rej'
ERRORPATTERN='.err'
PORTIN_ERRORDIR='/mpgapp/kenan/port-in/order_err/ready'
PORTOUT_ERRORDIR='/mpgapp/kenan/port-out/order_err/ready'

FTPLOG='/SYSTEM/custom/data/MNP/mpgsdev/log/ftp.log'
LOG='/SYSTEM/custom/data/MNP/mpgsdev/log/error.log'

INTERVAL=100

sleep 10 # wait until parent process has created log file and written pid to it
echo to exit script: kill \<pid\>

cd $MPGS_FILE_DIR_ON_LOCAL_MACHINE

# check for port-in and port-out acknowledgement, completed, error and rejected files
while true
do
date

# check for acknowledgement files for port-in
echo Checking for port-in acknowledgement files
for file in `ls $PORTIN_FILE_PREFIX*$ACKPATTERN 2>/dev/null`
do
ping $PRIMARY -n 3
if [[ $? != 0 ]]; then
    date '+%Y-%m-%d %H:%M:%S Connection Unavailable' >> $LOG
ping $SECONDARY -n 3
if [[ $? != 0 ]]; then
    date '+%Y-%m-%d %H:%M:%S Connection Unavailable - SUPPORT PERSONNEL TO CHECK' >> $LOG
else
    date '+%Y-%m-%d %H:%M:%S Connection Available' >> $LOG
    echo Transferring file $file
ftp -n $SECONDARY 2>&1 1> $FTPLOG <<END
quote USER $USER
quote PASS $PASSWD
cd $PORTIN_ACKDIR
put $file
END
EXITFTP=$?
if test $EXITFTP -ne 0; then echo "ERROR FTP" >> $LOG; exit 3; fi
if (grep "No such file or directory." $FTPLOG); then echo "ERROR FTP NO SUCH FILE" >> $LOG; fi 
if (grep "Login incorrect." $FTPLOG); then echo "ERROR FTP LOGIN" >> $LOG; fi
if (grep "Permission denied" $FTPLOG); then echo "ERROR FILE OR DIR PERMISSION ISSUE" >> $LOG; fi
fi
else
    date '+%Y-%m-%d %H:%M:%S Connection Available' >> $LOG
    echo Transferring file $file
ftp -n $PRIMARY 2>&1 1> $FTPLOG <<END
quote USER $USER
quote PASS $PASSWD
cd $PORTIN_ACKDIR
put $file
END
EXITFTP=$?
if test $EXITFTP -ne 0; then echo "ERROR FTP" >> $LOG; exit 3; fi
if (grep "No such file or directory." $FTPLOG); then echo "ERROR FTP NO SUCH FILE" >> $LOG; fi 
if (grep "Login incorrect." $FTPLOG); then echo "ERROR FTP LOGIN" >> $LOG; fi
if (grep "Permission denied" $FTPLOG); then echo "ERROR FILE OR DIR PERMISSION ISSUE" >> $LOG; fi
fi
done

# check for acknowledgement files for port-out
echo Checking for port-out acknowledgement files
for file in `ls $PORTOUT_FILE_PREFIX*$ACKPATTERN 2>/dev/null`
do
ping $PRIMARY -n 3
if [[ $? != 0 ]]; then
    date '+%Y-%m-%d %H:%M:%S Connection Unavailable' >> $LOG
ping $SECONDARY -n 3
if [[ $? != 0 ]]; then
    date '+%Y-%m-%d %H:%M:%S Connection Unavailable - SUPPORT PERSONNEL TO CHECK' >> $LOG
else
    date '+%Y-%m-%d %H:%M:%S Connection Available' >> $LOG
    echo Transferring file $file
ftp -n $SECONDARY 2>&1 1> $FTPLOG <<END
quote USER $USER
quote PASS $PASSWD
cd $PORTOUT_ACKDIR
put $file
END
EXITFTP=$?
if test $EXITFTP -ne 0; then echo " ERROR FTP" >> $LOG; exit 3; fi
if (grep "No such file or directory." $FTPLOG); then echo "ERROR FTP NO SUCH FILE" >> $LOG; fi 
if (grep "Login incorrect." $FTPLOG); then echo "ERROR FTP LOGIN" >> $LOG; fi
if (grep "Permission denied" $FTPLOG); then echo "ERROR FILE OR DIR PERMISSION ISSUE" >> $LOG; fi
fi
else
    date '+%Y-%m-%d %H:%M:%S Connection Available' >> $LOG
    echo Transferring file $file
ftp -n $PRIMARY 2>&1 1> $FTPLOG <<END
quote USER $USER
quote PASS $PASSWD
cd $PORTOUT_ACKDIR
put $file
END
EXITFTP=$?
if test $EXITFTP -ne 0; then echo "ERROR FTP" >> $LOG; exit 3; fi
if (grep "No such file or directory." $FTPLOG); then echo "ERROR FTP NO SUCH FILE" >> $LOG; fi 
if (grep "Login incorrect." $FTPLOG); then echo "ERROR FTP LOGIN" >> $LOG; fi
if (grep "Permission denied" $FTPLOG); then echo "ERROR FILE OR DIR PERMISSION ISSUE" >> $LOG; fi
fi
done

# check for completion files for port-in
echo Checking for port-in completion files
for file in `ls $PORTIN_FILE_PREFIX*$COMPLETIONPATTERN 2>/dev/null`
do
ping $PRIMARY -n 3
if [[ $? != 0 ]]; then
    date '+%Y-%m-%d %H:%M:%S Connection Unavailable' >> $LOG
ping $SECONDARY -n 3
if [[ $? != 0 ]]; then
    date '+%Y-%m-%d %H:%M:%S Connection Unavailable - SUPPORT PERSONNEL TO CHECK' >> $LOG
else
    date '+%Y-%m-%d %H:%M:%S Connection Available' >> $LOG
    echo Transferring file $file
ftp -n $SECONDARY 2>&1 1> $FTPLOG <<END
quote USER $USER
quote PASS $PASSWD
cd $PORTIN_COMPLETIONDIR
put $file
END
EXITFTP=$?
if test $EXITFTP -ne 0; then echo "ERROR FTP" >> $LOG; exit 3; fi
if (grep "No such file or directory." $FTPLOG); then echo "ERROR FTP NO SUCH FILE" >> $LOG; fi 
if (grep "Login incorrect." $FTPLOG); then echo "ERROR FTP LOGIN" >> $LOG; fi
if (grep "Permission denied" $FTPLOG); then echo "ERROR FILE OR DIR PERMISSION ISSUE" >> $LOG; fi
fi
else
    date '+%Y-%m-%d %H:%M:%S Connection Available' >> $LOG
    echo Transferring file $file
ftp -n $PRIMARY 2>&1 1> $FTPLOG <<END
quote USER $USER
quote PASS $PASSWD
cd $PORTIN_COMPLETIONDIR
put $file
END
EXITFTP=$?
if test $EXITFTP -ne 0; then echo "ERROR FTP" >> $LOG; exit 3; fi
if (grep "No such file or directory." $FTPLOG); then echo "ERROR FTP NO SUCH FILE" >> $LOG; fi 
if (grep "Login incorrect." $FTPLOG); then echo "ERROR FTP LOGIN" >> $LOG; fi
if (grep "Permission denied" $FTPLOG); then echo "ERROR FILE OR DIR PERMISSION ISSUE" >> $LOG; fi
fi
done

# check for completion files for port-out
echo Checking for port-out completion files
for file in `ls $PORTOUT_FILE_PREFIX*$COMPLETIONPATTERN 2>/dev/null`
do
ping $PRIMARY -n 3
if [[ $? != 0 ]]; then
    date '+%Y-%m-%d %H:%M:%S Connection Unavailable' >> $LOG
ping $SECONDARY -n 3
if [[ $? != 0 ]]; then
    date '+%Y-%m-%d %H:%M:%S Connection Unavailable - SUPPORT PERSONNEL TO CHECK' >> $LOG
else
    date '+%Y-%m-%d %H:%M:%S Connection Available' >> $LOG
    echo Transferring file $file
ftp -n $SECONDARY 2>&1 1> $FTPLOG <<END
quote USER $USER
quote PASS $PASSWD
cd $PORTOUT_COMPLETIONDIR
put $file
END
EXITFTP=$?
if test $EXITFTP -ne 0; then echo "ERROR FTP" >> $LOG; exit 3; fi
if (grep "No such file or directory." $FTPLOG); then echo "ERROR FTP NO SUCH FILE" >> $LOG; fi 
if (grep "Login incorrect." $FTPLOG); then echo "ERROR FTP LOGIN" >> $LOG; fi
if (grep "Permission denied" $FTPLOG); then echo "ERROR FILE OR DIR PERMISSION ISSUE" >> $LOG; fi
fi
else
    date '+%Y-%m-%d %H:%M:%S Connection Available' >> $LOG
    echo Transferring file $file
ftp -n $PRIMARY 2>&1 1> $FTPLOG <<END
quote USER $USER
quote PASS $PASSWD
cd $PORTOUT_COMPLETIONDIR
put $file
END
EXITFTP=$?
if test $EXITFTP -ne 0; then echo "ERROR FTP" >> $LOG; exit 3; fi
if (grep "No such file or directory." $FTPLOG); then echo "ERROR FTP NO SUCH FILE" >> $LOG; fi 
if (grep "Login incorrect." $FTPLOG); then echo "ERROR FTP LOGIN" >> $LOG; fi
if (grep "Permission denied" $FTPLOG); then echo "ERROR FILE OR DIR PERMISSION ISSUE" >> $LOG; fi
fi
done

# check for error and reject files for port-in
echo Checking for port-in error and reject files
for file in `ls $PORTIN_FILE_PREFIX*$ERRORPATTERN $PORTIN_FILE_PREFIX*$REJECTPATTERN 2>/dev/null`
do
ping $PRIMARY -n 3
if [[ $? != 0 ]]; then
    date '+%Y-%m-%d %H:%M:%S Connection Unavailable' >> $LOG
ping $SECONDARY -n 3
if [[ $? != 0 ]]; then
    date '+%Y-%m-%d %H:%M:%S Connection Unavailable - SUPPORT PERSONNEL TO CHECK' >> $LOG
else
    date '+%Y-%m-%d %H:%M:%S Connection Available' >> $LOG
    echo Transferring file $file
ftp -n $SECONDARY 2>&1 1> $FTPLOG <<END
quote USER $USER
quote PASS $PASSWD
cd $PORTIN_ERRORDIR
put $file
END
EXITFTP=$?
if test $EXITFTP -ne 0; then echo "ERROR FTP" >> $LOG; exit 3; fi
if (grep "No such file or directory." $FTPLOG); then echo "ERROR FTP NO SUCH FILE" >> $LOG; fi 
if (grep "Login incorrect." $FTPLOG); then echo "ERROR FTP LOGIN" >> $LOG; fi
if (grepb "Permission denied" $FTPLOG); then echo "ERROR FILE OR DIR PERMISSION ISSUE" >> $LOG; fi
fi
else
    date '+%Y-%m-%d %H:%M:%S Connection Available' >> $LOG
    echo Transferring file $file
ftp -n $PRIMARY 2>&1 1> $FTPLOG <<END
quote USER $USER
quote PASS $PASSWD
cd $PORTIN_ERRORDIR
put $file
END
EXITFTP=$?
if test $EXITFTP -ne 0; then echo "ERROR FTP" >> $LOG; exit 3; fi
if (grep "No such file or directory." $FTPLOG); then echo "ERROR FTP NO SUCH FILE" >> $LOG; fi 
if (grep "Login incorrect." $FTPLOG); then echo "ERROR FTP LOGIN" >> $LOG; fi
if (grep "Permission denied" $FTPLOG); then echo "ERROR FILE OR DIR PERMISSION ISSUE" >> $LOG; fi
fi
done

# check for error and reject files for port-out
echo Checking for port-out error and reject files
for file in `ls $PORTOUT_FILE_PREFIX*$ERRORPATTERN $PORTOUT_FILE_PREFIX*$REJECTPATTERN 2>/dev/null`
do
ping $PRIMARY -n 3
if [[ $? != 0 ]]; then
    date '+%Y-%m-%d %H:%M:%S Connection Unavailable' >> $LOG
ping $SECONDARY -n 3
if [[ $? != 0 ]]; then
    date '+%Y-%m-%d %H:%M:%S Connection Unavailable - SUPPORT PERSONNEL TO CHECK' >> $LOG
else
    date '+%Y-%m-%d %H:%M:%S Connection Available' >> $LOG
    echo Transferring file $file
ftp -n $SECONDARY 2>&1 1> $FTPLOG <<END
quote USER $USER
quote PASS $PASSWD
cd $PORTOUT_ERRORDIR
put $file
END
EXITFTP=$?
if test $EXITFTP -ne 0; then echo "ERROR FTP" >> $LOG; exit 3; fi
if (grep "No such file or directory." $FTPLOG); then echo "ERROR FTP NO SUCH FILE" >> $LOG; fi 
if (grep "Login incorrect." $FTPLOG); then echo "ERROR FTP LOGIN" >> $LOG; fi
if (grep "Permission denied" $FTPLOG); then echo "ERROR FILE OR DIR PERMISSION ISSUE" >> $LOG; fi
fi
else
    date '+%Y-%m-%d %H:%M:%S Connection Available' >> $LOG
    echo Transferring file $file
ftp -n $PRIMARY 2>&1 1> $FTPLOG <<END
quote USER $USER
quote PASS $PASSWD
cd $PORTOUT_ERRORDIR
put $file
END
EXITFTP=$?
if test $EXITFTP -ne 0; then echo "ERROR FTP" >> $LOG; exit 3; fi
if (grep "No such file or directory." $FTPLOG); then echo "ERROR FTP NO SUCH FILE" >> $LOG; fi 
if (grep "Login incorrect." $FTPLOG); then echo "ERROR FTP LOGIN" >> $LOG; fi
if (grep "Permission denied" $FTPLOG); then echo "ERROR FILE OR DIR PERMISSION ISSUE" >> $LOG; fi
fi
done

sleep $INTERVAL # sleeps for n interval

done

exit 0

Please point out where I am going wrong.

Thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to grep using wildcard in a file.

I wish to check if my file has a line that does not start with '#' and has 1. Listen and 2. 443 echo "Listen 443" > test.out grep 'Listen *443' test.out | grep -v '#' Listen 443 The above worked fine but when the entry changes to the below the grep fails... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. UNIX for Beginners Questions & Answers

Print Error in Console and both Error & Output in Log file - UNIX

I am writing a shell script with 2 run time arguments. During the execution if i got any error, then it needs to redirected to a error file and in console. Also both error and output to be redirected to a log file. But i am facing the below error. #! /bin/sh errExit () { errMsg=`cat... (1 Reply)
Discussion started by: sarathy_a35
1 Replies

3. Shell Programming and Scripting

Need Script to ZIP/SAVE & then DELETE Log file & send a mail conformation for any error

ENVIROMENT Linux: RHEL 6.4 Log Path: /usr/iplanet/servers/https-company/logs Log Format: user.log.03-15-2015 I have log4j log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I need a script that will run daily that... (1 Reply)
Discussion started by: admin_job_admin
1 Replies

4. Solaris

Unable to mount ext4 filesystem (created from Ubuntu) in Solaris 11

Hello everyone, I am trying to mount an ext4 filesystem which I created from Ubuntu. But mount command fails saying: prakhar@Solaris:~$ sudo mount /dev/dsk/c10t0d0p1 /mnt Password: mount: /dev/dsk/c10t0d0p1 is not this fstype And I also tried this: prakhar@Solaris:~$ fstyp... (6 Replies)
Discussion started by: Prakhar Mishra
6 Replies

5. UNIX for Dummies Questions & Answers

Unable to copy file using SCP (Input/output & Permission denied error)

Hi, I am facing issue while using scp. Source & target machines are Linux & HP-UX respectively. On target machine, if I fire the following command, I get error: Now if I try scp on another file, which is on the same source machine, it works fine. All directories and subdirectories... (2 Replies)
Discussion started by: Technext
2 Replies

6. Shell Programming and Scripting

Parsing Log File Based on Date & Error

I'm still up trying to figure this out and it is driving me nuts. I have a log file which has a basic format of this... 2010-10-10 22:25:42 Init block 'UA Deployment Date': Dynamic refresh of repository scope variables has failed. The ODBC function has returned an error. The database... (4 Replies)
Discussion started by: k1ko
4 Replies

7. Shell Programming and Scripting

Count number of Nodes created and write it to a Log file

Dear Experts, I have to count the number of AddressRecords formed in bbc.xml file using unix script file. For example: for below pasted file, I need to write an output to a log file as "No. of Address Records Created=4". Snippet of bbc.xml:- <?xml version="1.0" encoding="UTF-8" ?> -... (1 Reply)
Discussion started by: phani333
1 Replies

8. Shell Programming and Scripting

autosys job error file not created

Hi All Something really weird happened, I have an autosys job: insert_job: CAT_LDN_BaseCorrs job_type: c command: $$(LDNFIRC)\CAT_LDN_BaseCorrs.bat -modeldate $$MODEL_DATE -cutdate $$CUT_DATE permission: gx, mx, wx description: "Rerun=0;625;#CAT_Autosys" std_out_file:... (0 Replies)
Discussion started by: evilsmile2004
0 Replies

9. Shell Programming and Scripting

I want to get the file which created the error when the find command was run

I want to get the file which created the error when the find command was run ? I am wrote a script to mail a list of files whose file size is ge than 0 and returns 0 but wen it finds a folder with only empty files it exits as 1. i need to modify it so that the return for this is also 0 (but it... (1 Reply)
Discussion started by: guhas
1 Replies

10. UNIX for Dummies Questions & Answers

want to cat the latest log file created

everytime a new logfile get created at certain interval of time and i want a simple shell script program which cat the lastest log file when manually excuted (1 Reply)
Discussion started by: vkandati
1 Replies
Login or Register to Ask a Question