[Solved] Do not want to print sftp commands in log

Hi,

While running my ksh file, I require the logs to be written to another file. For this I use the below code:

write_log()
{
  echo `date +"%d %h, %Y %H:%M:%S"` " : " $* >> ${LOG_FILE}
}

But inside my ksh file, am connecting to sftp server and executing some commands.
So while i see the log, these commands are also getting printed. I do not want these sftp commands to get printed in the log. What should be done for that.
The log now looks like :

[06 Jun, 2013 05:39:02  :  Value of LOG_FILE : 1306060539.log
06 Jun, 2013 05:39:02  :  Job Starts
06 Jun, 2013 05:39:02  :  example.ksh
Connected to sftptest.com.
sftp> cd /test
sftp> lcd /test/files
sftp> mget *.cnm
File "/test/*.cnm" not found.
sftp> rm *.cnm
Removing /test/*.cnm
Couldn't delete file: Permission denied
sftp> quit
0
06 Jun, 2013 05:39:03  :   Download Success
06 Jun, 2013 05:39:03  :  Count of cnm files received today: 0 files
06 Jun, 2013 05:39:03  :  The files are:
06 Jun, 2013 05:39:03  : 
SFTP Process  Completed.
06 Jun, 2013 05:39:03  :  Sending mail]

Here i dont require the below commands to be printed in log.

Connected to sftptest.com.
sftp> cd /test
sftp> lcd /test/files
sftp> mget *.cnm
File "/test/*.cnm" not found.
sftp> rm *.cnm
Removing /test/*.cnm
Couldn't delete file: Permission denied
sftp> quit

Am not using any explicit commands for printing this, still it gets printed.

Hello,

Could you please give me a idea which kind of operations are being performed by your script after making a sftp connection?

R. Singh

Am using the below code:

sftp $USER@$HOST<<EOF 2>&1 cd $DIR
lcd $DIR/files
mget *$FILEEXT1 rm *$FILEEXT1 quit EOF

Hello,

Could you please add | grep -v "sftp" into your function which is creating logs.
Here is one example for same.

eg-->

cat test | grep -v "sftp"

It will search for all sftp things and it will show only text/lines that don't have sftp init.
Please make a try to it and let me know if that helps you.

R. Singh

Hi Ravinder,

I tried it out, but it delete only the rows having sftp word, but i need to delete all sftp loggings.

Here in my log the line stating "File "/test/*.cnm" not found." ,should also get deleted.

thanks

Hello,

Please let me know which kind of logs you are expecting in Output file. Is it Output of all the commands you are execuitng.

A example can help me a bit.

R. Singh

HI,

I am explicitly logging the data which I require in the file using below method :

write_log() {   echo `date +"%d %h, %Y %H:%M:%S"` " : " $* >> ${LOG_FILE} }

So i require only those written using write_log() method. Nothing else.

This is because I need to send an email using the contents of the log file, so the log has to be user defined. But here sftp commands are getting logged, which is not required.

You are obviously turning on some sort of logging other than write_log() when you invoke sftp. You have not provided us with enough information about how you are invoking sftp to determine how you do that particular logging.

HI,

Yes you were correct. I was calling my ksh file through a wrapper class which was actually logging sftp commands.
So now I have decided to log these commands into another file using the below code. So that the log file which I require for mailing will have only specified logs.

sftp $USER@$HOST<<EOF >sftp_log_file.log 2>&1 
cd $DIR lcd $DIR/files mget *$FILEEXT1 
rm *$FILEEXT1 
quit 
EOF

Thanks RavinderSingh13 and fpmurphy for the help. :slight_smile: